exports.up = async function(knex) { await knex.raw(` DROP INDEX unique_actor_slugs; CREATE UNIQUE INDEX unique_actor_slugs ON actors (slug, entry_id) WHERE entity_id IS NULL; `); await knex.schema.alterTable('actors', (table) => { table.boolean('allow_global_match'); table.text('comment'); }); await knex('users_roles') .update('abilities', JSON.stringify([ { subject: 'scene', action: 'create' }, { subject: 'scene', action: 'update' }, { subject: 'scene', action: 'delete' }, { subject: 'actor', action: 'create' }, { subject: 'actor', action: 'update' }, { subject: 'actor', action: 'delete' }, { subject: 'actor', action: 'merge' }, { plainUrls: true }, ])) .where('role', 'admin'); }; exports.down = async function(knex) { const dupes = await knex('actors') .select('name', 'slug', knex.raw('count(*) as count')) .whereNull('entity_id') .groupBy('name', 'slug') .havingRaw('count(*) > 1') .orderBy('count', 'desc'); if (dupes.length > 0) { console.log('DUPES\n', dupes.map((actor) => `${actor.name} ${actor.slug} ${actor.count}`).join('\n')); } await knex.raw(` DROP INDEX unique_actor_slugs; CREATE UNIQUE INDEX unique_actor_slugs ON actors (slug) WHERE entity_id IS NULL; `); await knex.schema.alterTable('actors', (table) => { table.dropColumn('allow_global_match'); table.dropColumn('comment'); }); await knex('users_roles') .update('abilities', JSON.stringify([ { subject: 'scene', action: 'create' }, { subject: 'scene', action: 'update' }, { subject: 'scene', action: 'delete' }, { subject: 'actor', action: 'create' }, { subject: 'actor', action: 'update' }, { subject: 'actor', action: 'delete' }, { plainUrls: true }, ])) .where('role', 'admin'); };