diff options
Diffstat (limited to 'bskylink/src/db/migrations/003-safelink-cursor-constraint.ts')
-rw-r--r-- | bskylink/src/db/migrations/003-safelink-cursor-constraint.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/bskylink/src/db/migrations/003-safelink-cursor-constraint.ts b/bskylink/src/db/migrations/003-safelink-cursor-constraint.ts new file mode 100644 index 000000000..1607eabeb --- /dev/null +++ b/bskylink/src/db/migrations/003-safelink-cursor-constraint.ts @@ -0,0 +1,31 @@ +import {type Kysely} from 'kysely' + +export async function up( + db: Kysely<{safelink_rule: {}; safelink_cursor: {}}>, +): Promise<void> { + // Remove existing items from safelink_rule that were duplicated due to broken cursor + await db.deleteFrom(['safelink_rule']).execute() + + // Delete the old cursor + await db.deleteFrom(['safelink_cursor']).execute() + + await db.schema + .alterTable('safelink_cursor') + .addPrimaryKeyConstraint('pk_id', ['id']) + .execute() +} + +export async function down( + db: Kysely<{safelink_rule: {}; safelink_cursor: {}}>, +): Promise<void> { + // Remove any rules that were added + await db.deleteFrom(['safelink_rule']).execute() + + // Delete the cursor + await db.deleteFrom(['safelink_cursor']).execute() + + await db.schema + .alterTable('safelink_cursor') + .dropConstraint('pk_id') + .execute() +} |