diff --git a/api/db/migrations/20241218101624_add-unicity-constraint-on-profile-rewards-table.js b/api/db/migrations/20241218101624_add-unicity-constraint-on-profile-rewards-table.js new file mode 100644 index 00000000000..9f4c35a7f28 --- /dev/null +++ b/api/db/migrations/20241218101624_add-unicity-constraint-on-profile-rewards-table.js @@ -0,0 +1,16 @@ +const TABLE_NAME = 'profile-rewards'; +const UNIQUE_CONSTRAINT_COLUMNS = ['userId', 'rewardId']; + +const up = async function (knex) { + return knex.schema.alterTable(TABLE_NAME, (table) => { + table.unique(UNIQUE_CONSTRAINT_COLUMNS); + }); +}; + +const down = async function (knex) { + return knex.schema.alterTable(TABLE_NAME, (table) => { + table.dropUnique(UNIQUE_CONSTRAINT_COLUMNS); + }); +}; + +export { down, up };