mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
25 lines
978 B
JavaScript
25 lines
978 B
JavaScript
'use strict';
|
|
|
|
// Backstop for the stacked-tier model: application code now enforces "at most
|
|
// one active row per (user_id, tier)" (see controllers/client/tiers.controller.js
|
|
// createOrder/captureOrder and controllers/admin/tiers.controller.js grantTier),
|
|
// but a race or a future code path could still violate it. This partial unique
|
|
// index makes the DB reject that case outright instead of silently allowing two
|
|
// active rows for the same user+tier.
|
|
//
|
|
// NOT auto-run — this file only defines the migration. Do not execute it against
|
|
// the shared dev/prod database without explicit confirmation.
|
|
module.exports = {
|
|
async up(queryInterface) {
|
|
await queryInterface.addIndex('user_tiers', ['user_id', 'tier'], {
|
|
unique: true,
|
|
where: { status: 'active' },
|
|
name: 'user_tiers_one_active_per_user_tier',
|
|
});
|
|
},
|
|
|
|
async down(queryInterface) {
|
|
await queryInterface.removeIndex('user_tiers', 'user_tiers_one_active_per_user_tier');
|
|
},
|
|
};
|