@verdant-web/server 3.0.4 → 3.1.0
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/LICENSE +650 -21
- package/dist/esm/ServerLibrary.test.js +10 -0
- package/dist/esm/ServerLibrary.test.js.map +1 -1
- package/dist/esm/storage/index.d.ts +1 -0
- package/dist/esm/storage/index.js +1 -0
- package/dist/esm/storage/index.js.map +1 -1
- package/dist/esm/storage/sql/database.d.ts +9 -0
- package/dist/esm/storage/sql/database.js +24 -0
- package/dist/esm/storage/sql/database.js.map +1 -0
- package/dist/esm/storage/sql/sqlStorage.d.ts +2 -1
- package/dist/esm/storage/sql/sqlStorage.js +5 -13
- package/dist/esm/storage/sql/sqlStorage.js.map +1 -1
- package/dist/esm/storage/sql/tables.d.ts +2 -0
- package/dist/esm/storage/sqlShard/Databases.d.ts +21 -0
- package/dist/esm/storage/sqlShard/Databases.js +64 -0
- package/dist/esm/storage/sqlShard/Databases.js.map +1 -0
- package/dist/esm/storage/sqlShard/SqlBaselines.d.ts +23 -0
- package/dist/esm/storage/sqlShard/SqlBaselines.js +98 -0
- package/dist/esm/storage/sqlShard/SqlBaselines.js.map +1 -0
- package/dist/esm/storage/sqlShard/SqlFileMetadata.d.ts +18 -0
- package/dist/esm/storage/sqlShard/SqlFileMetadata.js +70 -0
- package/dist/esm/storage/sqlShard/SqlFileMetadata.js.map +1 -0
- package/dist/esm/storage/sqlShard/SqlOperations.d.ts +18 -0
- package/dist/esm/storage/sqlShard/SqlOperations.js +104 -0
- package/dist/esm/storage/sqlShard/SqlOperations.js.map +1 -0
- package/dist/esm/storage/sqlShard/SqlReplicas.d.ts +32 -0
- package/dist/esm/storage/sqlShard/SqlReplicas.js +164 -0
- package/dist/esm/storage/sqlShard/SqlReplicas.js.map +1 -0
- package/dist/esm/storage/sqlShard/_testData/unifiedData.d.ts +30 -0
- package/dist/esm/storage/sqlShard/_testData/unifiedData.js +42 -0
- package/dist/esm/storage/sqlShard/_testData/unifiedData.js.map +1 -0
- package/dist/esm/storage/sqlShard/database.d.ts +6 -0
- package/dist/esm/storage/sqlShard/database.js +28 -0
- package/dist/esm/storage/sqlShard/database.js.map +1 -0
- package/dist/esm/storage/sqlShard/migrations/v1.d.ts +3 -0
- package/dist/esm/storage/sqlShard/migrations/v1.js +48 -0
- package/dist/esm/storage/sqlShard/migrations/v1.js.map +1 -0
- package/dist/esm/storage/sqlShard/migrations.d.ts +5 -0
- package/dist/esm/storage/sqlShard/migrations.js +3 -0
- package/dist/esm/storage/sqlShard/migrations.js.map +1 -0
- package/dist/esm/storage/sqlShard/sqlShardStorage.d.ts +7 -0
- package/dist/esm/storage/sqlShard/sqlShardStorage.js +55 -0
- package/dist/esm/storage/sqlShard/sqlShardStorage.js.map +1 -0
- package/dist/esm/storage/sqlShard/tables.d.ts +38 -0
- package/dist/esm/storage/sqlShard/tables.js +2 -0
- package/dist/esm/storage/sqlShard/tables.js.map +1 -0
- package/dist/esm/storage/sqlShard/transfer.d.ts +6 -0
- package/dist/esm/storage/sqlShard/transfer.js +76 -0
- package/dist/esm/storage/sqlShard/transfer.js.map +1 -0
- package/dist/esm/storage/sqlShard/transfer.test.d.ts +1 -0
- package/dist/esm/storage/sqlShard/transfer.test.js +94 -0
- package/dist/esm/storage/sqlShard/transfer.test.js.map +1 -0
- package/package.json +3 -2
- package/src/ServerLibrary.test.ts +10 -0
- package/src/storage/index.ts +1 -0
- package/src/storage/sql/database.ts +32 -0
- package/src/storage/sql/sqlStorage.ts +6 -8
- package/src/storage/sql/tables.ts +4 -0
- package/src/storage/sqlShard/Databases.ts +80 -0
- package/src/storage/sqlShard/SqlBaselines.ts +140 -0
- package/src/storage/sqlShard/SqlFileMetadata.ts +98 -0
- package/src/storage/sqlShard/SqlOperations.ts +146 -0
- package/src/storage/sqlShard/SqlReplicas.ts +237 -0
- package/src/storage/sqlShard/_testData/unifiedData.ts +52 -0
- package/src/storage/sqlShard/database.ts +37 -0
- package/src/storage/sqlShard/migrations/v1.ts +53 -0
- package/src/storage/sqlShard/migrations.ts +3 -0
- package/src/storage/sqlShard/sqlShardStorage.ts +81 -0
- package/src/storage/sqlShard/tables.ts +45 -0
- package/src/storage/sqlShard/transfer.test.ts +130 -0
- package/src/storage/sqlShard/transfer.ts +107 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Kysely } from 'kysely';
|
|
2
|
+
import { openDatabase as openUnifiedDatabase } from '../sql/database.js';
|
|
3
|
+
import { Database as UnifiedDatabase } from '../sql/tables.js';
|
|
4
|
+
import { Database } from './tables.js';
|
|
5
|
+
import { openDatabase } from './database.js';
|
|
6
|
+
|
|
7
|
+
export async function transferToShards({
|
|
8
|
+
file,
|
|
9
|
+
directory,
|
|
10
|
+
}: {
|
|
11
|
+
file: string;
|
|
12
|
+
directory: string;
|
|
13
|
+
}) {
|
|
14
|
+
console.info(
|
|
15
|
+
`Transferring from unified database (${file}) to shards (${directory})...`,
|
|
16
|
+
);
|
|
17
|
+
const { db: unifiedDb, ready } = openUnifiedDatabase(file);
|
|
18
|
+
await ready;
|
|
19
|
+
const libraries = await unifiedDb
|
|
20
|
+
.selectFrom('ReplicaInfo')
|
|
21
|
+
.select('ReplicaInfo.libraryId')
|
|
22
|
+
.distinct()
|
|
23
|
+
.execute();
|
|
24
|
+
|
|
25
|
+
const dbs = await Promise.all(
|
|
26
|
+
libraries.map(async ({ libraryId }) => {
|
|
27
|
+
const db = await openDatabase(directory, libraryId);
|
|
28
|
+
await copyLibrary(libraryId, unifiedDb, db);
|
|
29
|
+
return db;
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return libraries.reduce(
|
|
34
|
+
(acc, { libraryId }, i) => {
|
|
35
|
+
acc[libraryId] = dbs[i];
|
|
36
|
+
return acc;
|
|
37
|
+
},
|
|
38
|
+
{} as Record<string, Kysely<Database>>,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function copyLibrary(
|
|
43
|
+
libraryId: string,
|
|
44
|
+
source: Kysely<UnifiedDatabase>,
|
|
45
|
+
dest: Kysely<Database>,
|
|
46
|
+
) {
|
|
47
|
+
const operations = await source
|
|
48
|
+
.selectFrom('OperationHistory')
|
|
49
|
+
.where('libraryId', '=', libraryId)
|
|
50
|
+
.selectAll()
|
|
51
|
+
.execute();
|
|
52
|
+
const baselines = await source
|
|
53
|
+
.selectFrom('DocumentBaseline')
|
|
54
|
+
.where('libraryId', '=', libraryId)
|
|
55
|
+
.selectAll()
|
|
56
|
+
.execute();
|
|
57
|
+
const replicas = await source
|
|
58
|
+
.selectFrom('ReplicaInfo')
|
|
59
|
+
.where('libraryId', '=', libraryId)
|
|
60
|
+
.selectAll()
|
|
61
|
+
.execute();
|
|
62
|
+
const fileMetadata = await source
|
|
63
|
+
.selectFrom('FileMetadata')
|
|
64
|
+
.where('libraryId', '=', libraryId)
|
|
65
|
+
.selectAll()
|
|
66
|
+
.execute();
|
|
67
|
+
|
|
68
|
+
for (const operation of operations) {
|
|
69
|
+
// @ts-expect-error
|
|
70
|
+
delete operation.libraryId;
|
|
71
|
+
}
|
|
72
|
+
for (const baseline of baselines) {
|
|
73
|
+
// @ts-expect-error
|
|
74
|
+
delete baseline.libraryId;
|
|
75
|
+
}
|
|
76
|
+
for (const replica of replicas) {
|
|
77
|
+
// @ts-expect-error
|
|
78
|
+
delete replica.libraryId;
|
|
79
|
+
}
|
|
80
|
+
for (const metadata of fileMetadata) {
|
|
81
|
+
// @ts-expect-error
|
|
82
|
+
delete metadata.libraryId;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
await dest.transaction().execute(async (trx) => {
|
|
86
|
+
const actions: Promise<any>[] = [];
|
|
87
|
+
if (operations.length) {
|
|
88
|
+
actions.push(
|
|
89
|
+
trx.insertInto('OperationHistory').values(operations).execute(),
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
if (baselines.length) {
|
|
93
|
+
actions.push(
|
|
94
|
+
trx.insertInto('DocumentBaseline').values(baselines).execute(),
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
if (replicas.length) {
|
|
98
|
+
actions.push(trx.insertInto('ReplicaInfo').values(replicas).execute());
|
|
99
|
+
}
|
|
100
|
+
if (fileMetadata.length) {
|
|
101
|
+
actions.push(
|
|
102
|
+
trx.insertInto('FileMetadata').values(fileMetadata).execute(),
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
await Promise.all(actions);
|
|
106
|
+
});
|
|
107
|
+
}
|