36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
/**
|
|
* Migration: Add Multi-Tenant Support
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
module.exports = {
|
|
async up(queryInterface, Sequelize) {
|
|
const tableDescription = await queryInterface.describeTable('tenants');
|
|
|
|
// Add essential multi-tenant columns
|
|
if (!tableDescription.subscription_type) {
|
|
await queryInterface.addColumn('tenants', 'subscription_type', {
|
|
type: Sequelize.ENUM('free', 'basic', 'premium', 'enterprise'),
|
|
defaultValue: 'basic'
|
|
});
|
|
}
|
|
|
|
if (!tableDescription.auth_provider) {
|
|
await queryInterface.addColumn('tenants', 'auth_provider', {
|
|
type: Sequelize.ENUM('local', 'saml', 'oauth', 'ldap', 'custom_sso'),
|
|
defaultValue: 'local'
|
|
});
|
|
}
|
|
|
|
console.log(' Multi-tenant columns added');
|
|
},
|
|
|
|
async down(queryInterface, Sequelize) {
|
|
await queryInterface.removeColumn('tenants', 'auth_provider');
|
|
await queryInterface.removeColumn('tenants', 'subscription_type');
|
|
await queryInterface.sequelize.query('DROP TYPE IF EXISTS "enum_tenants_auth_provider"');
|
|
await queryInterface.sequelize.query('DROP TYPE IF EXISTS "enum_tenants_subscription_type"');
|
|
}
|
|
};
|