mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
54 lines
3.0 KiB
JavaScript
54 lines
3.0 KiB
JavaScript
'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');
|
|
},
|
|
};
|