Fix jwt-token
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
// Create tenants table first (referenced by other tables)
|
||||
try {
|
||||
await queryInterface.createTable('tenants', {
|
||||
id: {
|
||||
type: Sequelize.UUID,
|
||||
@@ -36,22 +37,94 @@ module.exports = {
|
||||
allowNull: true,
|
||||
comment: 'Subdomain for multi-tenant routing'
|
||||
},
|
||||
subscription_type: {
|
||||
type: Sequelize.ENUM('free', 'basic', 'premium', 'enterprise'),
|
||||
defaultValue: 'basic',
|
||||
allowNull: false,
|
||||
comment: 'Subscription tier of the tenant'
|
||||
},
|
||||
is_active: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: true,
|
||||
comment: 'Whether tenant is active'
|
||||
},
|
||||
auth_provider: {
|
||||
type: Sequelize.ENUM('local', 'saml', 'oauth', 'ldap', 'custom_sso'),
|
||||
defaultValue: 'local',
|
||||
comment: 'Primary authentication provider'
|
||||
},
|
||||
auth_config: {
|
||||
type: Sequelize.JSONB,
|
||||
allowNull: true,
|
||||
comment: 'Authentication provider configuration'
|
||||
},
|
||||
user_mapping: {
|
||||
type: Sequelize.JSONB,
|
||||
allowNull: true,
|
||||
comment: 'User attribute mapping from external provider'
|
||||
},
|
||||
role_mapping: {
|
||||
type: Sequelize.JSONB,
|
||||
allowNull: true,
|
||||
comment: 'Role mapping from external provider to internal roles'
|
||||
},
|
||||
branding: {
|
||||
type: Sequelize.JSONB,
|
||||
allowNull: true,
|
||||
comment: 'Tenant-specific branding'
|
||||
},
|
||||
features: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
max_devices: 10,
|
||||
max_users: 5,
|
||||
api_rate_limit: 1000,
|
||||
data_retention_days: 90,
|
||||
features: ['basic_detection', 'alerts', 'dashboard']
|
||||
},
|
||||
comment: 'Tenant feature limits and enabled features'
|
||||
},
|
||||
admin_email: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
comment: 'Primary admin email for this tenant'
|
||||
},
|
||||
admin_phone: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
comment: 'Primary admin phone for this tenant'
|
||||
},
|
||||
billing_email: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true
|
||||
},
|
||||
payment_method_id: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
comment: 'Payment provider customer ID'
|
||||
},
|
||||
metadata: {
|
||||
type: Sequelize.JSONB,
|
||||
allowNull: true,
|
||||
comment: 'Additional tenant metadata'
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.NOW,
|
||||
allowNull: false
|
||||
defaultValue: Sequelize.NOW
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.NOW,
|
||||
allowNull: false
|
||||
defaultValue: Sequelize.NOW
|
||||
}
|
||||
});
|
||||
console.log('✅ Created tenants table');
|
||||
} catch (error) {
|
||||
if (error.parent?.code === '42P07') { // Table already exists
|
||||
console.log('⚠️ Tenants table already exists, skipping...');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Create users table
|
||||
await queryInterface.createTable('users', {
|
||||
@@ -82,6 +155,16 @@ module.exports = {
|
||||
defaultValue: 'viewer',
|
||||
allowNull: false
|
||||
},
|
||||
external_provider: {
|
||||
type: Sequelize.ENUM('local', 'saml', 'oauth', 'ldap', 'custom_sso'),
|
||||
defaultValue: 'local',
|
||||
comment: 'Authentication provider used for this user'
|
||||
},
|
||||
external_id: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
comment: 'User ID from external authentication provider'
|
||||
},
|
||||
tenant_id: {
|
||||
type: Sequelize.UUID,
|
||||
allowNull: true,
|
||||
|
||||
Reference in New Issue
Block a user