-
Notifications
You must be signed in to change notification settings - Fork 599
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
Pds v2 migrate script #1800
Closed
Closed
Pds v2 migrate script #1800
Changes from 18 commits
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
32ddcf2
first pass
dholms a0437c3
tweak
dholms f414a4e
script edits
dholms d662a6e
reorg
dholms 98b1c17
some more tidy
dholms 9edc55f
read dids as maps
dholms 66e334d
entrypoint for migrate script
devinivy 0f8248b
Merge branch 'pds-v2-migrate-script' of github.com:bluesky-social/atp…
devinivy 3e16cee
build branch
dholms b614a78
export script & change filenames
dholms 21937f2
fix ambiguous column
dholms ec8ef4e
tidy script
dholms c491782
revamp migrate script
dholms e93e2f1
move db to data folder
dholms fcf8151
delete old script
dholms 537e2c3
more logs
dholms c9532e0
missing executes
dholms 5477f20
tweak log parsing
dholms e036de4
script tweaks
dholms 008be35
actually run script
dholms 093f86f
tweak logging
dholms 69d863f
tweak
dholms 8aa20ef
im dumb dumb
dholms f2201eb
patch script
dholms ee47798
patch
dholms de4f8d3
failed blobs script
dholms 03ec698
run script
dholms de61594
tweak
dholms 4a85750
better err handling
dholms f13b2b9
log import output
dholms 709ec8f
small tweaks
dholms 76c9699
tweak
dholms 9c604c8
add concurrency
dholms 1d1aa73
error tracking in script
dholms 6226fe0
allow large bodies
dholms 2525cfd
add admin auth headers
dholms 604f2b7
mark not-failed once done
dholms 1081ace
repair blobs that have been taken down
dholms bb51f9b
send admin headers
dholms f1dde36
rm colon
dholms 4a99d2d
less logs
dholms a4e4ae6
check failures script
dholms d01d887
chunk load dids
dholms 80110be
smaller chunks
dholms 315138a
im dumb dumb
dholms 3a018d8
increase concurrency
dholms a7cbea3
split out utils
dholms 596d9c5
repair blobs on main script
dholms b6c48de
concurrent blob repair
dholms 40d1660
tidy
dholms 867c997
concurrency 1
dholms 1a99165
not concurrent
dholms 0bc2542
tweak script
dholms dc6b7f6
log only after failure to repair blob
dholms aa7a337
graceful shutdown
dholms c806ebb
repair prefs script
dholms 47dfe36
cleanup
dholms fd4f44d
log err
dholms 93dd22e
fix repair blob
dholms ad7a3b0
automate repair prefs
dholms fd4c745
increase concurrency
dholms 375d44d
add a retry on migration
dholms 5480515
refactor + better load-dids
dholms 704a9c3
round robin dids
dholms f0c6f05
script per pds
dholms b109825
lower concurrency
dholms a7cbd0a
wal mode
dholms 41e7e10
get rev from ipld_block
dholms 86ca769
repair takedowns script
dholms 9bf2fa9
tweak load dids
dholms f94accf
tweak
dholms 09e46d9
concurrent repair blobs
dholms f842835
final await
dholms d9680bc
revert load dids
dholms 24d2191
require pds id
dholms eb92915
script tweaks
dholms 5976564
save borked
dholms 525303f
keep alive http client
dholms e35f684
allow did:web transter
dholms 3446b7e
repair imports script
dholms b95fb0e
tweaks
dholms 7c50f02
load failed blobs script
dholms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { Kysely, MigrationProvider, Migrator, SqliteDialect } from 'kysely' | ||
import SqliteDB from 'better-sqlite3' | ||
|
||
export const getDb = async (loc: string): Promise<MigrateDb> => { | ||
const db = new Kysely<Schema>({ | ||
dialect: new SqliteDialect({ | ||
database: new SqliteDB(loc), | ||
}), | ||
}) | ||
const migrator = new Migrator({ db, provider: dbMigrationProvider }) | ||
const { error } = await migrator.migrateToLatest() | ||
if (error) throw error | ||
return db | ||
} | ||
|
||
const dbMigrationProvider: MigrationProvider = { | ||
async getMigrations() { | ||
return { | ||
'1': { | ||
async up(db: Kysely<unknown>) { | ||
await db.schema | ||
.createTable('status') | ||
.addColumn('did', 'varchar', (col) => col.primaryKey()) | ||
.addColumn('pdsId', 'integer') | ||
.addColumn('signingKey', 'varchar') | ||
.addColumn('phase', 'integer') | ||
.addColumn('importedRev', 'varchar') | ||
.addColumn('failed', 'integer') | ||
.execute() | ||
await db.schema | ||
.createTable('failed_pref') | ||
.addColumn('did', 'varchar', (col) => col.primaryKey()) | ||
.execute() | ||
await db.schema | ||
.createTable('failed_blob') | ||
.addColumn('did', 'varchar', (col) => col.notNull()) | ||
.addColumn('cid', 'varchar', (col) => col.notNull()) | ||
.addPrimaryKeyConstraint('failed_blob_pkey', ['did', 'cid']) | ||
.execute() | ||
await db.schema | ||
.createTable('failed_takedown') | ||
.addColumn('did', 'varchar', (col) => col.notNull()) | ||
.addColumn('recordUri', 'varchar') | ||
.addColumn('recordCid', 'varchar') | ||
.addColumn('blobCid', 'varchar') | ||
.execute() | ||
}, | ||
async down() {}, | ||
}, | ||
} | ||
}, | ||
} | ||
|
||
export type MigrateDb = Kysely<Schema> | ||
|
||
type Schema = { | ||
status: Status | ||
failed_pref: FailedPreference | ||
failed_blob: FailedBlob | ||
failed_takedown: FailedTakedown | ||
} | ||
|
||
export enum TransferPhase { | ||
notStarted = 0, | ||
reservedKey = 1, | ||
initImport = 2, | ||
transferred = 4, | ||
preferences = 5, | ||
takedowns = 6, | ||
completed = 7, | ||
} | ||
|
||
export type Status = { | ||
did: string | ||
pdsId: number | null | ||
signingKey: string | null | ||
phase: TransferPhase | ||
importedRev: string | null | ||
failed: 0 | 1 | ||
} | ||
|
||
export type FailedPreference = { | ||
did: string | ||
} | ||
|
||
export type FailedBlob = { | ||
did: string | ||
cid: string | ||
} | ||
|
||
export type FailedTakedown = { | ||
did: string | ||
blobCid?: string | ||
recordUri?: string | ||
recordCid?: string | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might make
phase
(andfailed
) a not-null to match the types below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup yup