시드 생성
This commit is contained in:
+25
-19
@@ -3,10 +3,15 @@ const { sequelize } = require('../config/database');
|
||||
|
||||
const Feature = sequelize.define('Feature', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
code: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
@@ -15,29 +20,11 @@ const Feature = sequelize.define('Feature', {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true
|
||||
},
|
||||
code: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true
|
||||
},
|
||||
purchaseType: {
|
||||
type: DataTypes.ENUM('subscription_only', 'separate_only', 'both'),
|
||||
allowNull: false,
|
||||
defaultValue: 'both'
|
||||
},
|
||||
price: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
defaultValue: 0
|
||||
},
|
||||
oneTimePurchasePrice: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true
|
||||
},
|
||||
monthlySubscriptionPrice: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.ENUM('active', 'inactive', 'suspended'),
|
||||
allowNull: false,
|
||||
@@ -56,4 +43,23 @@ const Feature = sequelize.define('Feature', {
|
||||
timestamps: true
|
||||
});
|
||||
|
||||
Feature.associate = (models) => {
|
||||
Feature.hasMany(models.ClubFeature, { foreignKey: 'featureId' });
|
||||
Feature.belongsToMany(models.Club, {
|
||||
through: models.ClubFeature,
|
||||
foreignKey: 'featureId',
|
||||
});
|
||||
Feature.hasMany(models.Menu, {
|
||||
foreignKey: 'featureCode',
|
||||
sourceKey: 'code',
|
||||
});
|
||||
// SubscriptionPlan 관계는 이미 있음
|
||||
|
||||
Feature.belongsToMany(models.SubscriptionPlan, {
|
||||
through: models.SubscriptionPlanFeature,
|
||||
foreignKey: 'featureId',
|
||||
otherKey: 'planId',
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Feature;
|
||||
|
||||
Reference in New Issue
Block a user