95 lines
2.0 KiB
JavaScript
95 lines
2.0 KiB
JavaScript
|
|
const { DataTypes } = require('sequelize');
|
||
|
|
const sequelize = require('../config/db');
|
||
|
|
|
||
|
|
const TenantSubscription = sequelize.define('TenantSubscription', {
|
||
|
|
id: {
|
||
|
|
type: DataTypes.INTEGER,
|
||
|
|
primaryKey: true,
|
||
|
|
autoIncrement: true,
|
||
|
|
comment: 'Subscription ID'
|
||
|
|
},
|
||
|
|
tenantId: {
|
||
|
|
type: DataTypes.INTEGER,
|
||
|
|
allowNull: false,
|
||
|
|
comment: 'Tenant ID'
|
||
|
|
},
|
||
|
|
planId: {
|
||
|
|
type: DataTypes.INTEGER,
|
||
|
|
allowNull: false,
|
||
|
|
comment: 'Plan ID'
|
||
|
|
},
|
||
|
|
orderId: {
|
||
|
|
type: DataTypes.INTEGER,
|
||
|
|
allowNull: true,
|
||
|
|
comment: 'Source order ID'
|
||
|
|
},
|
||
|
|
status: {
|
||
|
|
type: DataTypes.ENUM('active', 'expired', 'cancelled'),
|
||
|
|
allowNull: false,
|
||
|
|
defaultValue: 'active',
|
||
|
|
comment: 'Subscription status'
|
||
|
|
},
|
||
|
|
billingCycle: {
|
||
|
|
type: DataTypes.ENUM('monthly', 'yearly', 'custom'),
|
||
|
|
allowNull: false,
|
||
|
|
defaultValue: 'monthly',
|
||
|
|
comment: 'Billing cycle'
|
||
|
|
},
|
||
|
|
months: {
|
||
|
|
type: DataTypes.INTEGER,
|
||
|
|
allowNull: false,
|
||
|
|
defaultValue: 1,
|
||
|
|
comment: 'Purchased months'
|
||
|
|
},
|
||
|
|
startDate: {
|
||
|
|
type: DataTypes.DATE,
|
||
|
|
allowNull: false,
|
||
|
|
comment: 'Subscription start'
|
||
|
|
},
|
||
|
|
endDate: {
|
||
|
|
type: DataTypes.DATE,
|
||
|
|
allowNull: false,
|
||
|
|
comment: 'Subscription end'
|
||
|
|
},
|
||
|
|
amount: {
|
||
|
|
type: DataTypes.DECIMAL(10, 2),
|
||
|
|
allowNull: false,
|
||
|
|
defaultValue: 0,
|
||
|
|
comment: 'Paid amount'
|
||
|
|
},
|
||
|
|
createBy: {
|
||
|
|
type: DataTypes.INTEGER,
|
||
|
|
allowNull: true,
|
||
|
|
comment: 'Created by'
|
||
|
|
},
|
||
|
|
updateBy: {
|
||
|
|
type: DataTypes.INTEGER,
|
||
|
|
allowNull: true,
|
||
|
|
comment: 'Updated by'
|
||
|
|
},
|
||
|
|
isDeleted: {
|
||
|
|
type: DataTypes.INTEGER,
|
||
|
|
allowNull: false,
|
||
|
|
defaultValue: 0,
|
||
|
|
comment: 'Soft delete flag'
|
||
|
|
},
|
||
|
|
createTime: {
|
||
|
|
type: DataTypes.DATE,
|
||
|
|
allowNull: false,
|
||
|
|
defaultValue: DataTypes.NOW,
|
||
|
|
comment: 'Created time'
|
||
|
|
},
|
||
|
|
updateTime: {
|
||
|
|
type: DataTypes.DATE,
|
||
|
|
allowNull: false,
|
||
|
|
defaultValue: DataTypes.NOW,
|
||
|
|
comment: 'Updated time'
|
||
|
|
}
|
||
|
|
}, {
|
||
|
|
tableName: 'tenant_subscriptions',
|
||
|
|
timestamps: false,
|
||
|
|
comment: 'Tenant subscription ledger'
|
||
|
|
});
|
||
|
|
|
||
|
|
module.exports = TenantSubscription;
|