Skip to content

Commit

Permalink
switch takedown ids back to ints, consistent with live pds
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Sep 29, 2023
1 parent d3e194f commit 9fe38b0
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Kysely, sql } from 'kysely'

export async function up(db: Kysely<unknown>): Promise<void> {
sql`alter table "repo_root" alter column "takedownId" type integer using "takedownId"::integer`.execute(
db,
)
sql`alter table "repo_blob" alter column "takedownId" type integer using "takedownId"::integer`.execute(
db,
)
sql`alter table "record" alter column "takedownId" type integer using "takedownId"::integer`.execute(
db,
)
}

export async function down(db: Kysely<unknown>): Promise<void> {
sql`alter table "repo_root" alter column "takedownId" type varchar`.execute(
db,
)
sql`alter table "repo_blob" alter column "takedownId" type varchar`.execute(
db,
)
sql`alter table "record" alter column "takedownId" type varchar`.execute(db)
}
1 change: 1 addition & 0 deletions packages/pds/src/db/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
3 changes: 1 addition & 2 deletions packages/pds/src/db/tables/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 1 addition & 2 deletions packages/pds/src/db/tables/repo-blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 1 addition & 2 deletions packages/pds/src/db/tables/repo-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion packages/pds/src/db/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions packages/pds/src/services/moderation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/pds/src/services/moderation/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ type RecordResult = {
cid: string
value: object
indexedAt: string
takedownId: string | null
takedownId: number | null
}

type SubjectResult = Pick<
Expand Down
2 changes: 1 addition & 1 deletion packages/pds/src/services/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion packages/pds/tests/account-deletion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ describe('account deletion', () => {

const getMailFrom = async (promise): Promise<Mail.Options> => {
const result = await Promise.all([once(mailCatcher, 'mail'), promise])
console.log(result)
return result[0][0]
}

Expand Down

0 comments on commit 9fe38b0

Please sign in to comment.