updated db migration

This commit is contained in:
2026-07-20 12:28:46 +08:00
parent a2c9936f79
commit d665897ef5
129 changed files with 574 additions and 1878 deletions
@@ -0,0 +1,53 @@
'use strict';
// content_mode is STRING + explicit CHECK (CockroachDB can't create a new
// enum type via addColumn the way createTable can) — matches the live schema
// since 20260711000003.
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('advertisements', {
advertisement_id: { type: Sequelize.BIGINT, primaryKey: true, autoIncrement: true },
uuid: { type: Sequelize.UUID, defaultValue: Sequelize.UUIDV4, allowNull: false, unique: true },
type: { type: Sequelize.ENUM('hero', 'banner', 'popup', 'sidebar'), allowNull: false },
status: { type: Sequelize.ENUM('draft', 'active', 'scheduled', 'expired', 'archived'), allowNull: false, defaultValue: 'draft' },
badge_label: { type: Sequelize.STRING(100) },
headline: { type: Sequelize.STRING(255) },
description: { type: Sequelize.TEXT },
image_url: { type: Sequelize.STRING(512) },
image_asset_id: { type: Sequelize.BIGINT, allowNull: true, references: { model: 'assets', key: 'asset_id' }, onDelete: 'SET NULL' },
ctas: { type: Sequelize.JSONB, allowNull: false, defaultValue: [] },
start_date: { type: Sequelize.DATE },
end_date: { type: Sequelize.DATE },
order: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0 },
is_active: { type: Sequelize.BOOLEAN, allowNull: false, defaultValue: true },
size: { type: Sequelize.ENUM('sm', 'md', 'lg'), allowNull: true },
click_count: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0 },
placement: { type: Sequelize.STRING(100), allowNull: true },
content_mode: { type: Sequelize.STRING, allowNull: false, defaultValue: 'image' },
redirect_link: { type: Sequelize.STRING(512), allowNull: true },
landing_page: { type: Sequelize.JSONB, allowNull: true },
createdBy: { type: Sequelize.BIGINT, allowNull: true },
updatedBy: { type: Sequelize.BIGINT, allowNull: true },
deletedBy: { type: Sequelize.BIGINT, allowNull: true },
createdAt: { type: Sequelize.DATE, allowNull: false },
updatedAt: { type: Sequelize.DATE, allowNull: false },
deletedAt: { type: Sequelize.DATE, allowNull: true },
});
await queryInterface.sequelize.query(`
ALTER TABLE advertisements ADD CONSTRAINT check_content_mode
CHECK (content_mode IN ('image', 'content'))
`);
await queryInterface.addIndex('advertisements', ['uuid']);
await queryInterface.addIndex('advertisements', ['type']);
await queryInterface.addIndex('advertisements', ['status']);
await queryInterface.addIndex('advertisements', ['is_active']);
await queryInterface.addIndex('advertisements', ['deletedAt']);
await queryInterface.addIndex('advertisements', ['placement']);
},
async down(queryInterface) {
await queryInterface.dropTable('advertisements');
},
};