revised: payment strategy

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-07-31 02:27:05 +08:00
parent 2e5fd10b38
commit aad298bc54
4 changed files with 208 additions and 72 deletions
@@ -0,0 +1,24 @@
'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');
},
};