Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch takedown ids back to ints on pds distribution #1694

Merged
merged 3 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Kysely, sql } from 'kysely'
import { Dialect } from '..'

export async function up(db: Kysely<unknown>, dialect: Dialect): Promise<void> {
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<unknown>,
dialect: Dialect,
): Promise<void> {
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)
}
}
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
Loading