about summary refs log tree commit diff
path: root/bskylink/src/db/migrations/003-safelink-cursor-constraint.ts
diff options
context:
space:
mode:
authorhailey <hailey@blueskyweb.xyz>2025-09-03 08:55:09 -0700
committerGitHub <noreply@github.com>2025-09-03 08:55:09 -0700
commit6c8e9fd8c9944a5cd83147b845cb58abe5280316 (patch)
treec775dec48dcfe7fa4836ae03e3ed860c18e38c89 /bskylink/src/db/migrations/003-safelink-cursor-constraint.ts
parentfd7b1292b8ba1d7ef847ea7084dcf237252753cb (diff)
downloadvoidsky-6c8e9fd8c9944a5cd83147b845cb58abe5280316.tar.zst
add cursor constraint to safelink (#8966)
Diffstat (limited to 'bskylink/src/db/migrations/003-safelink-cursor-constraint.ts')
-rw-r--r--bskylink/src/db/migrations/003-safelink-cursor-constraint.ts31
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()
+}