@atproto/pds 0.4.117 → 0.4.118
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/account-manager/account-manager.d.ts +5 -2
- package/dist/account-manager/account-manager.d.ts.map +1 -1
- package/dist/account-manager/account-manager.js.map +1 -1
- package/dist/actor-store/blob/transactor.d.ts +2 -1
- package/dist/actor-store/blob/transactor.d.ts.map +1 -1
- package/dist/actor-store/blob/transactor.js +19 -5
- package/dist/actor-store/blob/transactor.js.map +1 -1
- package/dist/api/com/atproto/repo/uploadBlob.d.ts.map +1 -1
- package/dist/api/com/atproto/repo/uploadBlob.js +1 -0
- package/dist/api/com/atproto/repo/uploadBlob.js.map +1 -1
- package/dist/config/env.d.ts +1 -0
- package/dist/config/env.d.ts.map +1 -1
- package/dist/config/env.js +1 -0
- package/dist/config/env.js.map +1 -1
- package/dist/config/secrets.d.ts +1 -0
- package/dist/config/secrets.d.ts.map +1 -1
- package/dist/config/secrets.js +1 -0
- package/dist/config/secrets.js.map +1 -1
- package/dist/context.d.ts +3 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +19 -0
- package/dist/context.js.map +1 -1
- package/dist/lexicon/index.d.ts +10 -0
- package/dist/lexicon/index.d.ts.map +1 -1
- package/dist/lexicon/index.js +20 -0
- package/dist/lexicon/index.js.map +1 -1
- package/dist/lexicon/lexicons.d.ts +516 -0
- package/dist/lexicon/lexicons.d.ts.map +1 -1
- package/dist/lexicon/lexicons.js +277 -0
- package/dist/lexicon/lexicons.js.map +1 -1
- package/dist/lexicon/types/app/bsky/unspecced/defs.d.ts +27 -0
- package/dist/lexicon/types/app/bsky/unspecced/defs.d.ts.map +1 -1
- package/dist/lexicon/types/app/bsky/unspecced/defs.js +18 -0
- package/dist/lexicon/types/app/bsky/unspecced/defs.js.map +1 -1
- package/dist/lexicon/types/app/bsky/unspecced/getSuggestedStarterPacks.d.ts +36 -0
- package/dist/lexicon/types/app/bsky/unspecced/getSuggestedStarterPacks.d.ts.map +1 -0
- package/dist/lexicon/types/app/bsky/unspecced/getSuggestedStarterPacks.js +7 -0
- package/dist/lexicon/types/app/bsky/unspecced/getSuggestedStarterPacks.js.map +1 -0
- package/dist/lexicon/types/app/bsky/unspecced/getSuggestedStarterPacksSkeleton.d.ts +37 -0
- package/dist/lexicon/types/app/bsky/unspecced/getSuggestedStarterPacksSkeleton.d.ts.map +1 -0
- package/dist/lexicon/types/app/bsky/unspecced/getSuggestedStarterPacksSkeleton.js +7 -0
- package/dist/lexicon/types/app/bsky/unspecced/getSuggestedStarterPacksSkeleton.js.map +1 -0
- package/dist/lexicon/types/app/bsky/unspecced/getTrends.d.ts +36 -0
- package/dist/lexicon/types/app/bsky/unspecced/getTrends.d.ts.map +1 -0
- package/dist/lexicon/types/app/bsky/unspecced/getTrends.js +7 -0
- package/dist/lexicon/types/app/bsky/unspecced/getTrends.js.map +1 -0
- package/dist/lexicon/types/app/bsky/unspecced/getTrendsSkeleton.d.ts +38 -0
- package/dist/lexicon/types/app/bsky/unspecced/getTrendsSkeleton.d.ts.map +1 -0
- package/dist/lexicon/types/app/bsky/unspecced/getTrendsSkeleton.js +7 -0
- package/dist/lexicon/types/app/bsky/unspecced/getTrendsSkeleton.js.map +1 -0
- package/dist/lexicon/types/com/atproto/admin/updateAccountSigningKey.d.ts +31 -0
- package/dist/lexicon/types/com/atproto/admin/updateAccountSigningKey.d.ts.map +1 -0
- package/dist/lexicon/types/com/atproto/admin/updateAccountSigningKey.js +7 -0
- package/dist/lexicon/types/com/atproto/admin/updateAccountSigningKey.js.map +1 -0
- package/dist/repo/prepare.d.ts.map +1 -1
- package/dist/repo/prepare.js +1 -0
- package/dist/repo/prepare.js.map +1 -1
- package/dist/repo/types.d.ts +1 -0
- package/dist/repo/types.d.ts.map +1 -1
- package/dist/repo/types.js.map +1 -1
- package/dist/scripts/index.d.ts +8 -1
- package/dist/scripts/index.d.ts.map +1 -1
- package/dist/scripts/index.js +11 -0
- package/dist/scripts/index.js.map +1 -1
- package/dist/scripts/publish-identity.d.ts +8 -0
- package/dist/scripts/publish-identity.d.ts.map +1 -0
- package/dist/scripts/publish-identity.js +46 -0
- package/dist/scripts/publish-identity.js.map +1 -0
- package/dist/scripts/rebuild-repo.d.ts +10 -2
- package/dist/scripts/rebuild-repo.d.ts.map +1 -1
- package/dist/scripts/rebuild-repo.js +21 -12
- package/dist/scripts/rebuild-repo.js.map +1 -1
- package/dist/scripts/rotate-keys.d.ts +18 -0
- package/dist/scripts/rotate-keys.d.ts.map +1 -0
- package/dist/scripts/rotate-keys.js +115 -0
- package/dist/scripts/rotate-keys.js.map +1 -0
- package/dist/scripts/sequencer-recovery/index.d.ts +3 -0
- package/dist/scripts/sequencer-recovery/index.d.ts.map +1 -0
- package/dist/scripts/sequencer-recovery/index.js +17 -0
- package/dist/scripts/sequencer-recovery/index.js.map +1 -0
- package/dist/scripts/sequencer-recovery/recoverer.d.ts +27 -0
- package/dist/scripts/sequencer-recovery/recoverer.d.ts.map +1 -0
- package/dist/scripts/sequencer-recovery/recoverer.js +235 -0
- package/dist/scripts/sequencer-recovery/recoverer.js.map +1 -0
- package/dist/scripts/sequencer-recovery/recovery-db.d.ts +18 -0
- package/dist/scripts/sequencer-recovery/recovery-db.d.ts.map +1 -0
- package/dist/scripts/sequencer-recovery/recovery-db.js +45 -0
- package/dist/scripts/sequencer-recovery/recovery-db.js.map +1 -0
- package/dist/scripts/sequencer-recovery/repair-repos.d.ts +3 -0
- package/dist/scripts/sequencer-recovery/repair-repos.d.ts.map +1 -0
- package/dist/scripts/sequencer-recovery/repair-repos.js +45 -0
- package/dist/scripts/sequencer-recovery/repair-repos.js.map +1 -0
- package/dist/scripts/sequencer-recovery/user-queues.d.ts +12 -0
- package/dist/scripts/sequencer-recovery/user-queues.d.ts.map +1 -0
- package/dist/scripts/sequencer-recovery/user-queues.js +54 -0
- package/dist/scripts/sequencer-recovery/user-queues.js.map +1 -0
- package/dist/scripts/util.d.ts +2 -0
- package/dist/scripts/util.d.ts.map +1 -0
- package/dist/scripts/util.js +12 -0
- package/dist/scripts/util.js.map +1 -0
- package/dist/sequencer/sequencer.d.ts +2 -0
- package/dist/sequencer/sequencer.d.ts.map +1 -1
- package/dist/sequencer/sequencer.js +52 -42
- package/dist/sequencer/sequencer.js.map +1 -1
- package/package.json +10 -10
- package/src/account-manager/account-manager.ts +6 -2
- package/src/actor-store/blob/transactor.ts +25 -7
- package/src/api/com/atproto/repo/uploadBlob.ts +1 -0
- package/src/config/env.ts +2 -0
- package/src/config/secrets.ts +2 -0
- package/src/context.ts +23 -0
- package/src/lexicon/index.ts +62 -0
- package/src/lexicon/lexicons.ts +285 -0
- package/src/lexicon/types/app/bsky/unspecced/defs.ts +45 -0
- package/src/lexicon/types/app/bsky/unspecced/getSuggestedStarterPacks.ts +54 -0
- package/src/lexicon/types/app/bsky/unspecced/getSuggestedStarterPacksSkeleton.ts +55 -0
- package/src/lexicon/types/app/bsky/unspecced/getTrends.ts +54 -0
- package/src/lexicon/types/app/bsky/unspecced/getTrendsSkeleton.ts +56 -0
- package/src/lexicon/types/com/atproto/admin/updateAccountSigningKey.ts +48 -0
- package/src/repo/prepare.ts +1 -0
- package/src/repo/types.ts +1 -0
- package/src/scripts/README.md +40 -0
- package/src/scripts/index.ts +15 -0
- package/src/scripts/publish-identity.ts +54 -0
- package/src/scripts/rebuild-repo.ts +39 -12
- package/src/scripts/rotate-keys.ts +141 -0
- package/src/scripts/sequencer-recovery/index.ts +23 -0
- package/src/scripts/sequencer-recovery/recoverer.ts +289 -0
- package/src/scripts/sequencer-recovery/recovery-db.ts +64 -0
- package/src/scripts/sequencer-recovery/repair-repos.ts +48 -0
- package/src/scripts/sequencer-recovery/user-queues.ts +41 -0
- package/src/scripts/util.ts +7 -0
- package/src/sequencer/sequencer.ts +43 -40
- package/tests/recovery.test.ts +178 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.tests.tsbuildinfo +1 -1
@@ -3,22 +3,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.rebuildRepo = void 0;
|
6
|
+
exports.rebuildRepo = exports.rebuildRepoScript = void 0;
|
7
7
|
const promises_1 = __importDefault(require("node:readline/promises"));
|
8
8
|
const common_1 = require("@atproto/common");
|
9
9
|
const repo_1 = require("@atproto/repo");
|
10
|
-
const
|
10
|
+
const rebuildRepoScript = async (ctx, args) => {
|
11
11
|
const did = args[0];
|
12
12
|
if (!did || !did.startsWith('did:')) {
|
13
13
|
throw new Error('Expected DID as argument');
|
14
14
|
}
|
15
|
+
return (0, exports.rebuildRepo)(ctx, did, true);
|
16
|
+
};
|
17
|
+
exports.rebuildRepoScript = rebuildRepoScript;
|
18
|
+
const rebuildRepo = async (ctx, did, promptUser) => {
|
15
19
|
const memoryStore = new repo_1.MemoryBlockstore();
|
16
|
-
const rev = common_1.TID.nextStr();
|
17
20
|
const commit = await ctx.actorStore.transact(did, async (store) => {
|
18
|
-
const [records, existingCids] = await Promise.all([
|
21
|
+
const [rootDetails, records, existingCids] = await Promise.all([
|
22
|
+
store.repo.storage.getRootDetailed(),
|
19
23
|
store.record.listAll(),
|
20
24
|
store.record.listExistingBlocks(),
|
21
25
|
]);
|
26
|
+
// increment existing rev by 1 ms
|
27
|
+
const revTid = common_1.TID.fromStr(rootDetails.rev);
|
28
|
+
const rev = common_1.TID.fromTime(revTid.timestamp() + 1, revTid.clockid()).toString();
|
22
29
|
let mst = await repo_1.MST.create(memoryStore);
|
23
30
|
for (const record of records) {
|
24
31
|
mst = await mst.add(record.path, record.cid);
|
@@ -43,13 +50,15 @@ const rebuildRepo = async (ctx, args) => {
|
|
43
50
|
data: await mst.getPointer(),
|
44
51
|
}, store.repo.signingKey);
|
45
52
|
const commitCid = await newBlocks.add(newCommit);
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
+
if (promptUser) {
|
54
|
+
console.log('Record count: ', records.length);
|
55
|
+
console.log('Existing blocks: ', existingCids.toList().length);
|
56
|
+
console.log('Deleting blocks:', toDelete.toList().length);
|
57
|
+
console.log('Adding blocks: ', newBlocks.size);
|
58
|
+
const shouldContinue = await promptContinue();
|
59
|
+
if (!shouldContinue) {
|
60
|
+
throw new Error('Aborted');
|
61
|
+
}
|
53
62
|
}
|
54
63
|
await store.repo.storage.deleteMany(toDelete.toList());
|
55
64
|
await store.repo.storage.putMany(newBlocks, rev);
|
@@ -67,7 +76,7 @@ const rebuildRepo = async (ctx, args) => {
|
|
67
76
|
prevData: null,
|
68
77
|
};
|
69
78
|
});
|
70
|
-
await ctx.accountManager.updateRepoRoot(did, commit.cid, rev);
|
79
|
+
await ctx.accountManager.updateRepoRoot(did, commit.cid, commit.rev);
|
71
80
|
const syncData = await ctx.actorStore.read(did, (store) => store.repo.getSyncEventData());
|
72
81
|
await ctx.sequencer.sequenceSyncEvt(did, syncData);
|
73
82
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rebuild-repo.js","sourceRoot":"","sources":["../../src/scripts/rebuild-repo.ts"],"names":[],"mappings":";;;;;;AAAA,sEAA6C;AAC7C,4CAAqC;AACrC,wCAMsB;
|
1
|
+
{"version":3,"file":"rebuild-repo.js","sourceRoot":"","sources":["../../src/scripts/rebuild-repo.ts"],"names":[],"mappings":";;;;;;AAAA,sEAA6C;AAC7C,4CAAqC;AACrC,wCAMsB;AAWf,MAAM,iBAAiB,GAAG,KAAK,EACpC,GAAmB,EACnB,IAAc,EACd,EAAE;IACF,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;IACnB,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CA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AAA;IACF,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAA;IAClD,OAAO,MAAM,KAAK,EAAE,CAAA;AACtB,CAAC,CAAA"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import * as plc from '@did-plc/lib';
|
2
|
+
import AtpAgent from '@atproto/api';
|
3
|
+
import { Keypair } from '@atproto/crypto';
|
4
|
+
import { IdResolver } from '@atproto/identity';
|
5
|
+
import { ActorStore } from '../actor-store/actor-store';
|
6
|
+
import { Sequencer } from '../sequencer';
|
7
|
+
export type RotateKeysContext = {
|
8
|
+
sequencer: Sequencer;
|
9
|
+
actorStore: ActorStore;
|
10
|
+
idResolver: IdResolver;
|
11
|
+
plcClient: plc.Client;
|
12
|
+
plcRotationKey: Keypair;
|
13
|
+
entrywayAdminAgent?: AtpAgent;
|
14
|
+
};
|
15
|
+
export declare const rotateKeys: (ctx: RotateKeysContext, args: string[]) => Promise<void>;
|
16
|
+
export declare const rotateKeysFromFile: (ctx: RotateKeysContext, args: string[]) => Promise<void>;
|
17
|
+
export declare const rotateKeysRecovery: (ctx: RotateKeysContext, args: string[]) => Promise<void>;
|
18
|
+
//# sourceMappingURL=rotate-keys.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"rotate-keys.d.ts","sourceRoot":"","sources":["../../src/scripts/rotate-keys.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AAEnC,OAAO,QAAQ,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAEvD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAIxC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,SAAS,CAAA;IACpB,UAAU,EAAE,UAAU,CAAA;IACtB,UAAU,EAAE,UAAU,CAAA;IACtB,SAAS,EAAE,GAAG,CAAC,MAAM,CAAA;IACrB,cAAc,EAAE,OAAO,CAAA;IACvB,kBAAkB,CAAC,EAAE,QAAQ,CAAA;CAC9B,CAAA;AAED,eAAO,MAAM,UAAU,QAAe,iBAAiB,QAAQ,MAAM,EAAE,kBAGtE,CAAA;AAED,eAAO,MAAM,kBAAkB,QACxB,iBAAiB,QAChB,MAAM,EAAE,kBAef,CAAA;AAED,eAAO,MAAM,kBAAkB,QACxB,iBAAiB,QAChB,MAAM,EAAE,kBAqBf,CAAA"}
|
@@ -0,0 +1,115 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.rotateKeysRecovery = exports.rotateKeysFromFile = exports.rotateKeys = void 0;
|
7
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
8
|
+
const p_queue_1 = __importDefault(require("p-queue"));
|
9
|
+
const recovery_db_1 = require("./sequencer-recovery/recovery-db");
|
10
|
+
const util_1 = require("./util");
|
11
|
+
const rotateKeys = async (ctx, args) => {
|
12
|
+
const dids = args;
|
13
|
+
await rotateKeysForRepos(ctx, dids, 10);
|
14
|
+
};
|
15
|
+
exports.rotateKeys = rotateKeys;
|
16
|
+
const rotateKeysFromFile = async (ctx, args) => {
|
17
|
+
const filepath = args[0];
|
18
|
+
if (!filepath) {
|
19
|
+
throw new Error('Expected filepath as argument');
|
20
|
+
}
|
21
|
+
const concurrency = args[1] ? (0, util_1.parseIntArg)(args[1]) : 25;
|
22
|
+
const file = await promises_1.default.readFile(filepath);
|
23
|
+
const dids = file
|
24
|
+
.toString()
|
25
|
+
.split('\n')
|
26
|
+
.map((did) => did.trim())
|
27
|
+
.filter((did) => did.startsWith('did:plc'));
|
28
|
+
await rotateKeysForRepos(ctx, dids, concurrency);
|
29
|
+
};
|
30
|
+
exports.rotateKeysFromFile = rotateKeysFromFile;
|
31
|
+
const rotateKeysRecovery = async (ctx, args) => {
|
32
|
+
const concurrency = args[1] ? (0, util_1.parseIntArg)(args[0]) : 10;
|
33
|
+
const recoveryDb = await (0, recovery_db_1.getRecoveryDbFromSequencerLoc)(ctx.sequencer.dbLocation);
|
34
|
+
const rows = await recoveryDb.db
|
35
|
+
.selectFrom('new_account')
|
36
|
+
.select('did')
|
37
|
+
.where('new_account.published', '=', 0)
|
38
|
+
.execute();
|
39
|
+
const dids = rows.map((r) => r.did);
|
40
|
+
await rotateKeysForRepos(ctx, dids, concurrency, async (did) => {
|
41
|
+
await recoveryDb.db
|
42
|
+
.updateTable('new_account')
|
43
|
+
.set({ published: 1 })
|
44
|
+
.where('did', '=', did)
|
45
|
+
.execute();
|
46
|
+
});
|
47
|
+
};
|
48
|
+
exports.rotateKeysRecovery = rotateKeysRecovery;
|
49
|
+
const rotateKeysForRepos = async (ctx, dids, concurrency, onSuccess) => {
|
50
|
+
const queue = new p_queue_1.default({ concurrency });
|
51
|
+
let completed = 0;
|
52
|
+
for (const did of dids) {
|
53
|
+
queue.add(async () => {
|
54
|
+
try {
|
55
|
+
await updatePlcSigningKey(ctx, did);
|
56
|
+
}
|
57
|
+
catch (err) {
|
58
|
+
console.error(`failed to update key for ${did}: ${err}`);
|
59
|
+
return;
|
60
|
+
}
|
61
|
+
let syncData;
|
62
|
+
try {
|
63
|
+
syncData = await ctx.actorStore.transact(did, async (actorTxn) => {
|
64
|
+
await actorTxn.repo.processWrites([]);
|
65
|
+
return actorTxn.repo.getSyncEventData();
|
66
|
+
});
|
67
|
+
}
|
68
|
+
catch (err) {
|
69
|
+
console.error(`failed to write new commit for ${did}: ${err}`);
|
70
|
+
return;
|
71
|
+
}
|
72
|
+
try {
|
73
|
+
await ctx.sequencer.sequenceIdentityEvt(did);
|
74
|
+
}
|
75
|
+
catch (err) {
|
76
|
+
console.error(`failed to sequence new identity evt for ${did}: ${err}`);
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
try {
|
80
|
+
await ctx.sequencer.sequenceSyncEvt(did, syncData);
|
81
|
+
}
|
82
|
+
catch (err) {
|
83
|
+
console.error(`failed to sequence for ${did}: ${err}`);
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
if (onSuccess) {
|
87
|
+
await onSuccess(did);
|
88
|
+
}
|
89
|
+
completed++;
|
90
|
+
if (completed % 10 === 0) {
|
91
|
+
console.log(`${completed}/${dids.length}`);
|
92
|
+
}
|
93
|
+
});
|
94
|
+
}
|
95
|
+
await queue.onIdle();
|
96
|
+
console.log('DONE');
|
97
|
+
};
|
98
|
+
const updatePlcSigningKey = async (ctx, did) => {
|
99
|
+
const updateTo = await ctx.actorStore.keypair(did);
|
100
|
+
const currSigningKey = await ctx.idResolver.did.resolveAtprotoKey(did, true);
|
101
|
+
if (updateTo.did() === currSigningKey) {
|
102
|
+
// already up to date
|
103
|
+
return;
|
104
|
+
}
|
105
|
+
if (ctx.entrywayAdminAgent) {
|
106
|
+
await ctx.entrywayAdminAgent.api.com.atproto.admin.updateAccountSigningKey({
|
107
|
+
did,
|
108
|
+
signingKey: updateTo.did(),
|
109
|
+
});
|
110
|
+
}
|
111
|
+
else {
|
112
|
+
await ctx.plcClient.updateAtprotoKey(did, ctx.plcRotationKey, updateTo.did());
|
113
|
+
}
|
114
|
+
};
|
115
|
+
//# sourceMappingURL=rotate-keys.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"rotate-keys.js","sourceRoot":"","sources":["../../src/scripts/rotate-keys.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAiC;AAEjC,sDAA4B;AAO5B,kEAAgF;AAChF,iCAAoC;AAW7B,MAAM,UAAU,GAAG,KAAK,EAAE,GAAsB,EAAE,IAAc,EAAE,EAAE;IACzE,MAAM,IAAI,GAAG,IAAI,CAAA;IACjB,MAAM,kBAAkB,CAAC,GAA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mB,GAAG,KAAK,EAAE,GAAsB,EAAE,GAAW,EAAE,EAAE;IACxE,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAClD,MAAM,cAAc,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAC5E,IAAI,QAAQ,CAAC,GAAG,EAAE,KAAK,cAAc,EAAE,CAAC;QACtC,qBAAqB;QACrB,OAAM;IACR,CAAC;IACD,IAAI,GAAG,CAAC,kBAAkB,EAAE,CAAC;QAC3B,MAAM,GAAG,CAAC,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC;YACzE,GAAG;YACH,UAAU,EAAE,QAAQ,CAAC,GAAG,EAAE;SAC3B,CAAC,CAAA;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,CAAC,SAAS,CAAC,gBAAgB,CAClC,GAAG,EACH,GAAG,CAAC,cAAc,EAClB,QAAQ,CAAC,GAAG,EAAE,CACf,CAAA;IACH,CAAC;AACH,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/scripts/sequencer-recovery/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAG7D,eAAO,MAAM,iBAAiB,QACvB,oBAAoB,QACnB,MAAM,EAAE,kBAgBf,CAAA"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.sequencerRecovery = void 0;
|
4
|
+
const util_1 = require("../util");
|
5
|
+
const recoverer_1 = require("./recoverer");
|
6
|
+
const recovery_db_1 = require("./recovery-db");
|
7
|
+
const sequencerRecovery = async (ctx, args) => {
|
8
|
+
const cursor = args[0] ? (0, util_1.parseIntArg)(args[0]) : 0;
|
9
|
+
const concurrency = args[1] ? (0, util_1.parseIntArg)(args[1]) : 10;
|
10
|
+
const recoveryDb = await (0, recovery_db_1.getRecoveryDbFromSequencerLoc)(ctx.sequencer.dbLocation);
|
11
|
+
const recover = new recoverer_1.Recoverer({ ...ctx, recoveryDb }, {
|
12
|
+
concurrency,
|
13
|
+
});
|
14
|
+
await recover.run(cursor);
|
15
|
+
};
|
16
|
+
exports.sequencerRecovery = sequencerRecovery;
|
17
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scripts/sequencer-recovery/index.ts"],"names":[],"mappings":";;;AAAA,kCAAqC;AACrC,2CAA6D;AAC7D,+CAA6D;AAEtD,MAAM,iBAAiB,GAAG,KAAK,EACpC,GAAyB,EACzB,IAAc,EACd,EAAE;IACF,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAA,kBAAW,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACjD,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAA,kBAAW,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAEvD,MAAM,UAAU,GAAG,MAAM,IAAA,2CAA6B,EACpD,GAAG,CAAC,SAAS,CAAC,UAAU,CACzB,CAAA;IAED,MAAM,OAAO,GAAG,IAAI,qBAAS,CAC3B,EAAE,GAAG,GAAG,EAAE,UAAU,EAAE,EACtB;QACE,WAAW;KACZ,CACF,CAAA;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AAC3B,CAAC,CAAA;AAlBY,QAAA,iBAAiB,qBAkB7B"}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { AccountManager } from '../../account-manager/account-manager';
|
2
|
+
import { ActorStore } from '../../actor-store/actor-store';
|
3
|
+
import { SeqEvt, Sequencer } from '../../sequencer';
|
4
|
+
import { RecoveryDb } from './recovery-db';
|
5
|
+
import { UserQueues } from './user-queues';
|
6
|
+
export type RecovererContextNoDb = {
|
7
|
+
sequencer: Sequencer;
|
8
|
+
accountManager: AccountManager;
|
9
|
+
actorStore: ActorStore;
|
10
|
+
};
|
11
|
+
export type RecovererContext = RecovererContextNoDb & {
|
12
|
+
recoveryDb: RecoveryDb;
|
13
|
+
};
|
14
|
+
export declare class Recoverer {
|
15
|
+
ctx: RecovererContext;
|
16
|
+
queues: UserQueues;
|
17
|
+
failed: Set<string>;
|
18
|
+
constructor(ctx: RecovererContext, opts: {
|
19
|
+
concurrency: number;
|
20
|
+
});
|
21
|
+
run(startCursor?: number): Promise<void>;
|
22
|
+
processAll(): Promise<void>;
|
23
|
+
destroy(): Promise<void>;
|
24
|
+
processEvent(evt: SeqEvt): void;
|
25
|
+
}
|
26
|
+
export declare const processSeqEvt: (ctx: RecovererContext, evt: SeqEvt) => Promise<void>;
|
27
|
+
//# sourceMappingURL=recoverer.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"recoverer.d.ts","sourceRoot":"","sources":["../../../src/scripts/sequencer-recovery/recoverer.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,cAAc,EAEf,MAAM,uCAAuC,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAS1D,OAAO,EAAyB,MAAM,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE1C,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,EAAE,SAAS,CAAA;IACpB,cAAc,EAAE,cAAc,CAAA;IAC9B,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,GAAG;IACpD,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAID,qBAAa,SAAS;IAKX,GAAG,EAAE,gBAAgB;IAJ9B,MAAM,EAAE,UAAU,CAAA;IAClB,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;gBAGV,GAAG,EAAE,gBAAgB,EAC5B,IAAI,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE;IAMzB,GAAG,CAAC,WAAW,SAAI;IAmCnB,UAAU;IAIV,OAAO;IAIb,YAAY,CAAC,GAAG,EAAE,MAAM;CAezB;AAED,eAAO,MAAM,aAAa,QAAe,gBAAgB,OAAO,MAAM,kBAQrE,CAAA"}
|
@@ -0,0 +1,235 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.processSeqEvt = exports.Recoverer = void 0;
|
4
|
+
const common_1 = require("@atproto/common");
|
5
|
+
const crypto_1 = require("@atproto/crypto");
|
6
|
+
const repo_1 = require("@atproto/repo");
|
7
|
+
const account_manager_1 = require("../../account-manager/account-manager");
|
8
|
+
const db_1 = require("../../db");
|
9
|
+
const repo_2 = require("../../repo");
|
10
|
+
const user_queues_1 = require("./user-queues");
|
11
|
+
const PAGE_SIZE = 5000;
|
12
|
+
class Recoverer {
|
13
|
+
constructor(ctx, opts) {
|
14
|
+
Object.defineProperty(this, "ctx", {
|
15
|
+
enumerable: true,
|
16
|
+
configurable: true,
|
17
|
+
writable: true,
|
18
|
+
value: ctx
|
19
|
+
});
|
20
|
+
Object.defineProperty(this, "queues", {
|
21
|
+
enumerable: true,
|
22
|
+
configurable: true,
|
23
|
+
writable: true,
|
24
|
+
value: void 0
|
25
|
+
});
|
26
|
+
Object.defineProperty(this, "failed", {
|
27
|
+
enumerable: true,
|
28
|
+
configurable: true,
|
29
|
+
writable: true,
|
30
|
+
value: void 0
|
31
|
+
});
|
32
|
+
this.queues = new user_queues_1.UserQueues(opts.concurrency);
|
33
|
+
this.failed = new Set();
|
34
|
+
}
|
35
|
+
async run(startCursor = 0) {
|
36
|
+
const failed = await this.ctx.recoveryDb.db
|
37
|
+
.selectFrom('failed')
|
38
|
+
.select('did')
|
39
|
+
.execute();
|
40
|
+
for (const row of failed) {
|
41
|
+
this.failed.add(row.did);
|
42
|
+
}
|
43
|
+
const totalRes = await this.ctx.sequencer.db.db
|
44
|
+
.selectFrom('repo_seq')
|
45
|
+
.select(db_1.countAll.as('count'))
|
46
|
+
.executeTakeFirstOrThrow();
|
47
|
+
const totalEvts = totalRes.count;
|
48
|
+
let completed = 0;
|
49
|
+
let cursor = startCursor;
|
50
|
+
while (cursor !== undefined) {
|
51
|
+
const page = await this.ctx.sequencer.requestSeqRange({
|
52
|
+
earliestSeq: cursor,
|
53
|
+
limit: PAGE_SIZE,
|
54
|
+
});
|
55
|
+
page.forEach((evt) => this.processEvent(evt));
|
56
|
+
cursor = page.at(-1)?.seq;
|
57
|
+
await this.queues.onEmpty();
|
58
|
+
completed += PAGE_SIZE;
|
59
|
+
const percentComplete = (completed / totalEvts) * 100;
|
60
|
+
console.log(`${percentComplete.toFixed(2)}% - ${cursor}`);
|
61
|
+
}
|
62
|
+
await this.queues.processAll();
|
63
|
+
}
|
64
|
+
async processAll() {
|
65
|
+
await this.queues.processAll();
|
66
|
+
}
|
67
|
+
async destroy() {
|
68
|
+
await this.queues.destroy();
|
69
|
+
}
|
70
|
+
processEvent(evt) {
|
71
|
+
const did = didFromEvt(evt);
|
72
|
+
if (!did) {
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
this.queues.addToUser(did, async () => {
|
76
|
+
if (this.failed.has(did)) {
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
await (0, exports.processSeqEvt)(this.ctx, evt).catch(async (err) => {
|
80
|
+
this.failed.add(did);
|
81
|
+
await trackFailure(this.ctx.recoveryDb, did, err);
|
82
|
+
});
|
83
|
+
});
|
84
|
+
}
|
85
|
+
}
|
86
|
+
exports.Recoverer = Recoverer;
|
87
|
+
const processSeqEvt = async (ctx, evt) => {
|
88
|
+
// only need to process commits & tombstones
|
89
|
+
if (evt.type === 'account') {
|
90
|
+
await processAccountEvt(ctx, evt.evt);
|
91
|
+
}
|
92
|
+
if (evt.type === 'commit') {
|
93
|
+
await processCommit(ctx, evt.evt).catch();
|
94
|
+
}
|
95
|
+
};
|
96
|
+
exports.processSeqEvt = processSeqEvt;
|
97
|
+
const processCommit = async (ctx, evt) => {
|
98
|
+
const did = evt.repo;
|
99
|
+
const { writes, blocks } = await parseCommitEvt(evt);
|
100
|
+
if (evt.since === null) {
|
101
|
+
const actorExists = await ctx.actorStore.exists(did);
|
102
|
+
if (!actorExists) {
|
103
|
+
await processRepoCreation(ctx, evt, writes, blocks);
|
104
|
+
return;
|
105
|
+
}
|
106
|
+
}
|
107
|
+
await ctx.actorStore.transact(did, async (actorTxn) => {
|
108
|
+
const root = await actorTxn.repo.storage.getRootDetailed();
|
109
|
+
if (root.rev >= evt.rev) {
|
110
|
+
return;
|
111
|
+
}
|
112
|
+
const commit = await actorTxn.repo.formatCommit(writes);
|
113
|
+
commit.newBlocks = blocks;
|
114
|
+
commit.cid = evt.commit;
|
115
|
+
commit.rev = evt.rev;
|
116
|
+
await Promise.all([
|
117
|
+
actorTxn.repo.storage.applyCommit(commit),
|
118
|
+
actorTxn.repo.indexWrites(writes, commit.rev),
|
119
|
+
trackBlobs(actorTxn, writes),
|
120
|
+
]);
|
121
|
+
});
|
122
|
+
};
|
123
|
+
const processRepoCreation = async (ctx, evt, writes, blocks) => {
|
124
|
+
const did = evt.repo;
|
125
|
+
const keypair = await crypto_1.Secp256k1Keypair.create({ exportable: true });
|
126
|
+
await ctx.actorStore.create(did, keypair);
|
127
|
+
const commit = {
|
128
|
+
cid: evt.commit,
|
129
|
+
rev: evt.rev,
|
130
|
+
since: evt.since,
|
131
|
+
prev: null,
|
132
|
+
newBlocks: blocks,
|
133
|
+
relevantBlocks: new repo_1.BlockMap(),
|
134
|
+
removedCids: new repo_1.CidSet(),
|
135
|
+
};
|
136
|
+
await ctx.actorStore.transact(did, (actorTxn) => Promise.all([
|
137
|
+
actorTxn.repo.storage.applyCommit(commit, true),
|
138
|
+
actorTxn.repo.indexWrites(writes, commit.rev),
|
139
|
+
actorTxn.repo.blob.processWriteBlobs(commit.rev, writes),
|
140
|
+
]));
|
141
|
+
await trackNewAccount(ctx.recoveryDb, did);
|
142
|
+
};
|
143
|
+
const processAccountEvt = async (ctx, evt) => {
|
144
|
+
// do not need to process deactivation/takedowns because we backup account DB as well
|
145
|
+
if (evt.status !== account_manager_1.AccountStatus.Deleted) {
|
146
|
+
return;
|
147
|
+
}
|
148
|
+
const { directory } = await ctx.actorStore.getLocation(evt.did);
|
149
|
+
await (0, common_1.rmIfExists)(directory, true);
|
150
|
+
await ctx.accountManager.deleteAccount(evt.did);
|
151
|
+
};
|
152
|
+
const trackBlobs = async (store, writes) => {
|
153
|
+
await store.repo.blob.deleteDereferencedBlobs(writes);
|
154
|
+
for (const write of writes) {
|
155
|
+
if (write.action === repo_1.WriteOpAction.Create ||
|
156
|
+
write.action === repo_1.WriteOpAction.Update) {
|
157
|
+
for (const blob of write.blobs) {
|
158
|
+
await store.repo.blob.insertBlobMetadata(blob);
|
159
|
+
await store.repo.blob.associateBlob(blob, write.uri);
|
160
|
+
}
|
161
|
+
}
|
162
|
+
}
|
163
|
+
};
|
164
|
+
const trackFailure = async (recoveryDb, did, err) => {
|
165
|
+
await recoveryDb.db
|
166
|
+
.insertInto('failed')
|
167
|
+
.values({
|
168
|
+
did,
|
169
|
+
error: err?.toString(),
|
170
|
+
fixed: 0,
|
171
|
+
})
|
172
|
+
.onConflict((oc) => oc.doNothing())
|
173
|
+
.execute();
|
174
|
+
};
|
175
|
+
const trackNewAccount = async (recoveryDb, did) => {
|
176
|
+
await recoveryDb.db
|
177
|
+
.insertInto('new_account')
|
178
|
+
.values({
|
179
|
+
did,
|
180
|
+
published: 0,
|
181
|
+
})
|
182
|
+
.onConflict((oc) => oc.doNothing())
|
183
|
+
.execute();
|
184
|
+
};
|
185
|
+
const parseCommitEvt = async (evt) => {
|
186
|
+
const did = evt.repo;
|
187
|
+
const evtCar = await (0, repo_1.readCar)(evt.blocks);
|
188
|
+
const writesUnfiltered = await Promise.all(evt.ops.map(async (op) => {
|
189
|
+
const { collection, rkey } = (0, repo_1.parseDataKey)(op.path);
|
190
|
+
if (op.action === 'delete') {
|
191
|
+
return (0, repo_2.prepareDelete)({ did, collection, rkey });
|
192
|
+
}
|
193
|
+
if (!op.cid)
|
194
|
+
return undefined;
|
195
|
+
const recordBytes = evtCar.blocks.get(op.cid);
|
196
|
+
if (!recordBytes)
|
197
|
+
return undefined;
|
198
|
+
const record = (0, repo_1.cborToLexRecord)(recordBytes);
|
199
|
+
if (op.action === 'create') {
|
200
|
+
return (0, repo_2.prepareCreate)({
|
201
|
+
did,
|
202
|
+
collection,
|
203
|
+
rkey,
|
204
|
+
record,
|
205
|
+
validate: false,
|
206
|
+
});
|
207
|
+
}
|
208
|
+
else {
|
209
|
+
return (0, repo_2.prepareUpdate)({
|
210
|
+
did,
|
211
|
+
collection,
|
212
|
+
rkey,
|
213
|
+
record,
|
214
|
+
validate: false,
|
215
|
+
});
|
216
|
+
}
|
217
|
+
}));
|
218
|
+
const writes = writesUnfiltered.filter((w) => w !== undefined);
|
219
|
+
return {
|
220
|
+
writes,
|
221
|
+
blocks: evtCar.blocks,
|
222
|
+
};
|
223
|
+
};
|
224
|
+
const didFromEvt = (evt) => {
|
225
|
+
if (evt.type === 'account') {
|
226
|
+
return evt.evt.did;
|
227
|
+
}
|
228
|
+
else if (evt.type === 'commit') {
|
229
|
+
return evt.evt.repo;
|
230
|
+
}
|
231
|
+
else {
|
232
|
+
return null;
|
233
|
+
}
|
234
|
+
};
|
235
|
+
//# sourceMappingURL=recoverer.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"recoverer.js","sourceRoot":"","sources":["../../../src/scripts/sequenc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GAAG,CAAC,GAAG,CAAC,GAAG,CAAA;IACpB,CAAC;SAAM,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,GAAG,CAAC,GAAG,CAAC,IAAI,CAAA;IACrB,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC,CAAA"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { Database } from '../../db';
|
2
|
+
export interface NewAccount {
|
3
|
+
did: string;
|
4
|
+
published: 0 | 1;
|
5
|
+
}
|
6
|
+
export interface Failed {
|
7
|
+
did: string;
|
8
|
+
error: string | null;
|
9
|
+
fixed: 0 | 1;
|
10
|
+
}
|
11
|
+
export type RecoveryDbSchema = {
|
12
|
+
new_account: NewAccount;
|
13
|
+
failed: Failed;
|
14
|
+
};
|
15
|
+
export type RecoveryDb = Database<RecoveryDbSchema>;
|
16
|
+
export declare const getRecoveryDbFromSequencerLoc: (sequencerLoc: string) => Promise<RecoveryDb>;
|
17
|
+
export declare const getAndMigrateRecoveryDb: (location: string, disableWalAutoCheckpoint?: boolean) => Promise<RecoveryDb>;
|
18
|
+
//# sourceMappingURL=recovery-db.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"recovery-db.d.ts","sourceRoot":"","sources":["../../../src/scripts/sequencer-recovery/recovery-db.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAY,MAAM,UAAU,CAAA;AAE7C,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,CAAC,GAAG,CAAC,CAAA;CACjB;AAED,MAAM,WAAW,MAAM;IACrB,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,KAAK,EAAE,CAAC,GAAG,CAAC,CAAA;CACb;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,UAAU,CAAA;IACvB,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAA;AAEnD,eAAO,MAAM,6BAA6B,iBAC1B,MAAM,KACnB,OAAO,CAAC,UAAU,CAGpB,CAAA;AAED,eAAO,MAAM,uBAAuB,aACxB,MAAM,yCAEf,OAAO,CAAC,UAAU,CAQpB,CAAA"}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.getAndMigrateRecoveryDb = exports.getRecoveryDbFromSequencerLoc = void 0;
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
8
|
+
const db_1 = require("../../db");
|
9
|
+
const getRecoveryDbFromSequencerLoc = (sequencerLoc) => {
|
10
|
+
const recoveryDbLoc = node_path_1.default.join(node_path_1.default.dirname(sequencerLoc), 'recovery.sqlite');
|
11
|
+
return (0, exports.getAndMigrateRecoveryDb)(recoveryDbLoc);
|
12
|
+
};
|
13
|
+
exports.getRecoveryDbFromSequencerLoc = getRecoveryDbFromSequencerLoc;
|
14
|
+
const getAndMigrateRecoveryDb = async (location, disableWalAutoCheckpoint = false) => {
|
15
|
+
const pragmas = disableWalAutoCheckpoint
|
16
|
+
? { wal_autocheckpoint: '0' }
|
17
|
+
: {};
|
18
|
+
const db = db_1.Database.sqlite(location, pragmas);
|
19
|
+
const migrator = new db_1.Migrator(db.db, migrations);
|
20
|
+
await migrator.migrateToLatestOrThrow();
|
21
|
+
return db;
|
22
|
+
};
|
23
|
+
exports.getAndMigrateRecoveryDb = getAndMigrateRecoveryDb;
|
24
|
+
const migrations = {
|
25
|
+
'001': {
|
26
|
+
up: async (db) => {
|
27
|
+
await db.schema
|
28
|
+
.createTable('new_account')
|
29
|
+
.addColumn('did', 'varchar', (col) => col.primaryKey())
|
30
|
+
.addColumn('published', 'int2', (col) => col.notNull())
|
31
|
+
.execute();
|
32
|
+
await db.schema
|
33
|
+
.createTable('failed')
|
34
|
+
.addColumn('did', 'varchar', (col) => col.primaryKey())
|
35
|
+
.addColumn('error', 'varchar')
|
36
|
+
.addColumn('fixed', 'int2', (col) => col.notNull())
|
37
|
+
.execute();
|
38
|
+
},
|
39
|
+
down: async (db) => {
|
40
|
+
await db.schema.dropTable('new_account').execute();
|
41
|
+
await db.schema.dropTable('failed').execute();
|
42
|
+
},
|
43
|
+
},
|
44
|
+
};
|
45
|
+
//# sourceMappingURL=recovery-db.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"recovery-db.js","sourceRoot":"","sources":["../../../src/scripts/sequencer-recovery/recovery-db.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,iCAA6C;AAoBtC,MAAM,6BAA6B,GAAG,CAC3C,YAAoB,EACC,EAAE;IACvB,MAAM,aAAa,GAAG,mBAAI,CAAC,IAAI,CAAC,mBAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,iBAAiB,CAAC,CAAA;IAC9E,OAAO,IAAA,+BAAuB,EAAC,aAAa,CAAC,CAAA;AAC/C,CAAC,CAAA;AALY,QAAA,6BAA6B,iCAKzC;AAEM,MAAM,uBAAuB,GAAG,KAAK,EAC1C,QAAgB,EAChB,wBAAwB,GAAG,KAAK,EACX,EAAE;IACvB,MAAM,OAAO,GAA2B,wBAAwB;QAC9D,CAAC,CAAC,EAAE,kBAAkB,EAAE,GAAG,EAAE;QAC7B,CAAC,CAAC,EAAE,CAAA;IACN,MAAM,EAAE,GAAG,aAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAC7C,MAAM,QAAQ,GAAG,IAAI,aAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,UAAU,CAAC,CAAA;IAChD,MAAM,QAAQ,CAAC,sBAAsB,EAAE,CAAA;IACvC,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