revise ads and alerts

This commit is contained in:
2026-08-03 22:48:06 +08:00
parent 32c72f0b39
commit 573cfb98af
16 changed files with 414 additions and 17 deletions
@@ -0,0 +1,58 @@
'use strict';
// badge_label was a single STRING(100). The Type step redesign lets admins
// attach up to 2 badges (outline chips) to a "Text with Image" ad, so the
// column becomes a JSONB string array (renamed badge_labels to match the
// plural shape, mirroring the existing `ctas` JSONB column). Any existing
// scalar value is wrapped into a single-element array; null/empty becomes [].
module.exports = {
async up(queryInterface) {
await queryInterface.sequelize.query(`
ALTER TABLE advertisements
ALTER COLUMN badge_label TYPE JSONB
USING (
CASE
WHEN badge_label IS NULL OR badge_label = '' THEN '[]'::jsonb
ELSE jsonb_build_array(badge_label)
END
)
`);
await queryInterface.sequelize.query(`
ALTER TABLE advertisements
ALTER COLUMN badge_label SET DEFAULT '[]'::jsonb
`);
await queryInterface.sequelize.query(`
ALTER TABLE advertisements
ALTER COLUMN badge_label SET NOT NULL
`);
await queryInterface.renameColumn('advertisements', 'badge_label', 'badge_labels');
},
async down(queryInterface) {
await queryInterface.renameColumn('advertisements', 'badge_labels', 'badge_label');
await queryInterface.sequelize.query(`
ALTER TABLE advertisements
ALTER COLUMN badge_label DROP NOT NULL
`);
await queryInterface.sequelize.query(`
ALTER TABLE advertisements
ALTER COLUMN badge_label TYPE STRING(100)
USING (
CASE
WHEN jsonb_array_length(badge_label) = 0 THEN NULL
ELSE badge_label->>0
END
)
`);
await queryInterface.sequelize.query(`
ALTER TABLE advertisements
ALTER COLUMN badge_label DROP DEFAULT
`);
},
};
@@ -0,0 +1,18 @@
'use strict';
// Alerts are title-only now — the composer no longer collects a body message
// (see AddNotificationBroadcast.jsx). Only this table's column goes; the
// per-recipient admin_notifications/user_notifications.message columns stay
// (shared by ~20 unrelated notification types via NOTIFICATION_REGISTRY).
module.exports = {
async up(queryInterface) {
await queryInterface.removeColumn('notification_broadcasts', 'message');
},
async down(queryInterface, Sequelize) {
await queryInterface.addColumn('notification_broadcasts', 'message', {
type: Sequelize.TEXT,
allowNull: true,
});
},
};
@@ -0,0 +1,17 @@
'use strict';
// Notifications-type alerts need a body again; Sticky-type alerts stay
// title-only. Nullable this time (sticky rows never populate it) — reverses
// 20270101000086, which dropped this same column as NOT NULL.
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.addColumn('notification_broadcasts', 'message', {
type: Sequelize.TEXT,
allowNull: true,
});
},
async down(queryInterface) {
await queryInterface.removeColumn('notification_broadcasts', 'message');
},
};