about summary refs log tree commit diff
path: root/bskylink/src/db/migrations/003-safelink-cursor-constraint.ts
blob: 1607eabeb33ec9ab68db176ff03cd0e18b2fc324 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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()
}