diff --git a/packages/pds/src/db/migrations/20230929T213219699Z-takedown-id-as-int.ts b/packages/pds/src/db/migrations/20230929T213219699Z-takedown-id-as-int.ts new file mode 100644 index 00000000000..8cacc599c60 --- /dev/null +++ b/packages/pds/src/db/migrations/20230929T213219699Z-takedown-id-as-int.ts @@ -0,0 +1,47 @@ +import { Kysely, sql } from 'kysely' +import { Dialect } from '..' + +export async function up(db: Kysely, dialect: Dialect): Promise { + if (dialect === 'pg') { + await sql` + alter table "repo_root" alter column "takedownId" type integer using "takedownId"::integer; + alter table "repo_blob" alter column "takedownId" type integer using "takedownId"::integer; + alter table "record" alter column "takedownId" type integer using "takedownId"::integer; + `.execute(db) + } else { + await sql`alter table "repo_root" drop column "takedownId"`.execute(db) + await sql`alter table "repo_root" add column "takedownId" integer`.execute( + db, + ) + await sql`alter table "repo_blob" drop column "takedownId"`.execute(db) + await sql`alter table "repo_blob" add column "takedownId" integer`.execute( + db, + ) + await sql`alter table "record" drop column "takedownId"`.execute(db) + await sql`alter table "record" add column "takedownId" integer`.execute(db) + } +} + +export async function down( + db: Kysely, + dialect: Dialect, +): Promise { + if (dialect === 'pg') { + await sql` + alter table "repo_root" alter column "takedownId" type varchar; + alter table "repo_blob" alter column "takedownId" type varchar; + alter table "record" alter column "takedownId" type varchar; + `.execute(db) + } else { + await sql`alter table "repo_root" drop column "takedownId"`.execute(db) + await sql`alter table "repo_root" add column "takedownId" varchar`.execute( + db, + ) + await sql`alter table "repo_blob" drop column "takedownId"`.execute(db) + await sql`alter table "repo_blob" add column "takedownId" varchar`.execute( + db, + ) + await sql`alter table "record" drop column "takedownId"`.execute(db) + await sql`alter table "record" add column "takedownId" varchar`.execute(db) + } +} diff --git a/packages/pds/src/db/migrations/index.ts b/packages/pds/src/db/migrations/index.ts index 2c7b34b9f47..9aead0d7012 100644 --- a/packages/pds/src/db/migrations/index.ts +++ b/packages/pds/src/db/migrations/index.ts @@ -5,3 +5,4 @@ export * as _20230613T164932261Z from './20230613T164932261Z-init' export * as _20230914T014727199Z from './20230914T014727199Z-repo-v3' export * as _20230926T195532354Z from './20230926T195532354Z-email-tokens' +export * as _20230929T213219699Z from './20230929T213219699Z-takedown-id-as-int' diff --git a/packages/pds/src/db/tables/record.ts b/packages/pds/src/db/tables/record.ts index fbde68b2219..03f1008ef0f 100644 --- a/packages/pds/src/db/tables/record.ts +++ b/packages/pds/src/db/tables/record.ts @@ -7,8 +7,7 @@ export interface Record { rkey: string repoRev: string | null indexedAt: string - // opaque identifier, though currently tends to reference a moderation_action - takedownId: string | null + takedownId: number | null } export const tableName = 'record' diff --git a/packages/pds/src/db/tables/repo-blob.ts b/packages/pds/src/db/tables/repo-blob.ts index 67aa072454f..a1fed0877e5 100644 --- a/packages/pds/src/db/tables/repo-blob.ts +++ b/packages/pds/src/db/tables/repo-blob.ts @@ -3,8 +3,7 @@ export interface RepoBlob { recordUri: string repoRev: string | null did: string - // opaque identifier, though currently tends to reference a moderation_action - takedownId: string | null + takedownId: number | null } export const tableName = 'repo_blob' diff --git a/packages/pds/src/db/tables/repo-root.ts b/packages/pds/src/db/tables/repo-root.ts index b68c6c37bea..6b6c921f380 100644 --- a/packages/pds/src/db/tables/repo-root.ts +++ b/packages/pds/src/db/tables/repo-root.ts @@ -4,8 +4,7 @@ export interface RepoRoot { root: string rev: string | null indexedAt: string - // opaque identifier, though currently tends to reference a moderation_action - takedownId: string | null + takedownId: number | null } export const tableName = 'repo_root' diff --git a/packages/pds/src/db/util.ts b/packages/pds/src/db/util.ts index 4fcd93a1d44..696ac7dee8b 100644 --- a/packages/pds/src/db/util.ts +++ b/packages/pds/src/db/util.ts @@ -23,7 +23,7 @@ export const notSoftDeletedClause = (alias: DbRef) => { return sql`${alias}."takedownId" is null` } -export const softDeleted = (repoOrRecord: { takedownId: string | null }) => { +export const softDeleted = (repoOrRecord: { takedownId: number | null }) => { return repoOrRecord.takedownId !== null } diff --git a/packages/pds/src/services/moderation/index.ts b/packages/pds/src/services/moderation/index.ts index 622fee2a11c..9e46332cf33 100644 --- a/packages/pds/src/services/moderation/index.ts +++ b/packages/pds/src/services/moderation/index.ts @@ -437,7 +437,7 @@ export class ModerationService { async takedownRepo(info: { takedownId: number; did: string }) { await this.db.db .updateTable('repo_root') - .set({ takedownId: String(info.takedownId) }) + .set({ takedownId: info.takedownId }) .where('did', '=', info.did) .where('takedownId', 'is', null) .executeTakeFirst() @@ -459,14 +459,14 @@ export class ModerationService { this.db.assertTransaction() await this.db.db .updateTable('record') - .set({ takedownId: String(info.takedownId) }) + .set({ takedownId: info.takedownId }) .where('uri', '=', info.uri.toString()) .where('takedownId', 'is', null) .executeTakeFirst() if (info.blobCids?.length) { await this.db.db .updateTable('repo_blob') - .set({ takedownId: String(info.takedownId) }) + .set({ takedownId: info.takedownId }) .where('recordUri', '=', info.uri.toString()) .where( 'cid', diff --git a/packages/pds/src/services/moderation/views.ts b/packages/pds/src/services/moderation/views.ts index b38b9fa987e..e8d89620d73 100644 --- a/packages/pds/src/services/moderation/views.ts +++ b/packages/pds/src/services/moderation/views.ts @@ -616,7 +616,7 @@ type RecordResult = { cid: string value: object indexedAt: string - takedownId: string | null + takedownId: number | null } type SubjectResult = Pick< diff --git a/packages/pds/src/services/record/index.ts b/packages/pds/src/services/record/index.ts index 5ddc9b79a09..1914d1b8c61 100644 --- a/packages/pds/src/services/record/index.ts +++ b/packages/pds/src/services/record/index.ts @@ -164,7 +164,7 @@ export class RecordService { cid: string value: object indexedAt: string - takedownId: string | null + takedownId: number | null } | null> { const { ref } = this.db.db.dynamic let builder = this.db.db diff --git a/packages/pds/tests/account-deletion.test.ts b/packages/pds/tests/account-deletion.test.ts index 54f1de60c70..12bdad8875a 100644 --- a/packages/pds/tests/account-deletion.test.ts +++ b/packages/pds/tests/account-deletion.test.ts @@ -62,7 +62,6 @@ describe('account deletion', () => { const getMailFrom = async (promise): Promise => { const result = await Promise.all([once(mailCatcher, 'mail'), promise]) - console.log(result) return result[0][0] }