Enforcing profile ID in actors_avatars.
This commit is contained in:
24
migrations/20260723120000_actors_avatars_profile_not_null.js
Normal file
24
migrations/20260723120000_actors_avatars_profile_not_null.js
Normal file
@@ -0,0 +1,24 @@
|
||||
exports.up = async function(knex) {
|
||||
const orphanedAvatars = await knex('actors_avatars')
|
||||
.whereNull('profile_id');
|
||||
|
||||
if (orphanedAvatars.length > 0) {
|
||||
console.log(`Deleting ${orphanedAvatars.length} actors_avatars rows with no profile_id`);
|
||||
}
|
||||
|
||||
await knex('actors_avatars')
|
||||
.whereNull('profile_id')
|
||||
.delete();
|
||||
|
||||
await knex.raw(`
|
||||
DROP INDEX IF EXISTS unique_main_avatars;
|
||||
ALTER TABLE actors_avatars ALTER COLUMN profile_id SET NOT NULL;
|
||||
`);
|
||||
};
|
||||
|
||||
exports.down = async function(knex) {
|
||||
await knex.raw(`
|
||||
ALTER TABLE actors_avatars ALTER COLUMN profile_id DROP NOT NULL;
|
||||
CREATE UNIQUE INDEX unique_main_avatars ON actors_avatars (actor_id) WHERE (profile_id IS NULL);
|
||||
`);
|
||||
};
|
||||
Reference in New Issue
Block a user