traxxx/migrations/20241103060644_socials.js

47 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2024-11-03 05:29:16 +00:00
exports.up = async (knex) => {
await knex.schema.alterTable('actors_social', (table) => {
table.dropUnique(['url', 'actor_id', 'profile_id']);
table.dropColumn('profile_id');
2024-11-04 01:37:45 +00:00
table.string('handle');
2024-11-03 05:29:16 +00:00
2024-11-04 01:37:45 +00:00
table.boolean('is_broken')
.notNullable()
.defaultTo(false);
2024-11-03 05:29:16 +00:00
2024-11-04 01:37:45 +00:00
table.datetime('pinged_at');
2024-11-03 05:29:16 +00:00
table.datetime('verified_at');
2024-11-04 01:37:45 +00:00
table.unique(['actor_id', 'platform', 'handle']);
table.unique(['actor_id', 'url']);
2024-11-03 05:29:16 +00:00
});
2024-11-04 01:37:45 +00:00
await knex.raw('ALTER TABLE actors_social ADD CONSTRAINT socials_url_or_handle CHECK (num_nulls(handle, url) = 1);');
await knex.raw('ALTER TABLE actors_social ADD CONSTRAINT socials_handle_and_platform CHECK (num_nulls(platform, handle) = 2 or num_nulls(platform, handle) = 0);');
await knex.schema.renameTable('actors_social', 'actors_socials');
2024-11-03 05:29:16 +00:00
};
exports.down = async (knex) => {
2024-11-04 01:37:45 +00:00
await knex.raw('ALTER TABLE actors_socials DROP CONSTRAINT socials_url_or_handle;');
await knex.raw('ALTER TABLE actors_socials DROP CONSTRAINT socials_handle_and_platform;');
await knex.schema.renameTable('actors_socials', 'actors_social');
2024-11-03 05:29:16 +00:00
await knex.schema.alterTable('actors_social', (table) => {
2024-11-04 01:37:45 +00:00
table.dropUnique(['actor_id', 'platform', 'handle']);
2024-11-03 05:29:16 +00:00
table.dropUnique(['actor_id', 'url']);
table.integer('profile_id')
.references('id')
.inTable('actors_profiles');
2024-11-04 01:37:45 +00:00
table.dropColumn('handle');
2024-11-03 05:29:16 +00:00
table.dropColumn('verified_at');
2024-11-04 01:37:45 +00:00
table.dropColumn('pinged_at');
table.dropColumn('is_broken');
2024-11-03 05:29:16 +00:00
table.unique(['url', 'actor_id', 'profile_id']);
});
};