"use strict"; module.exports.up = function(knex, Promise) { // Get rid of existing duplicate entries return knex.raw(` DELETE FROM srap_tags WHERE id IN ( SELECT id FROM ( SELECT id, row_number() OVER w as rnum FROM srap_tags WINDOW w AS ( PARTITION BY name, item_id ORDER BY id ) ) t WHERE t.rnum > 1); `).then(() => { return knex.schema .alterTable("srap_tags", (table) => { table.dropPrimary(); table.dropIndex("name"); table.dropColumn("id"); table.primary([ "name", "item_id" ]); }); }); }; module.exports.down = function(knex, Promise) { return knex.schema .alterTable("srap_tags", (table) => { table.dropPrimary(); table.bigIncrements("id").primary(); }); };