@openpeepshq/core 0.1.32 → 0.1.33
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/dist/accessTokens/helpers.d.ts +2 -2
- package/dist/accessTokens/tokens.js +14 -7
- package/dist/accounts/mutations.d.ts +2 -2
- package/dist/analytics/cache.js +12 -7
- package/dist/analytics/pdfReport.d.ts +1 -0
- package/dist/analytics/pdfReport.js +5 -4
- package/dist/analytics/privacy.d.ts +18 -0
- package/dist/analytics/privacy.js +10 -0
- package/dist/analytics/read.js +24 -11
- package/dist/analytics/report.d.ts +1 -1
- package/dist/analytics/report.js +9 -2
- package/dist/backups/index.js +6 -3
- package/dist/backups/metadata.d.ts +7 -0
- package/dist/config/defaults/community.js +0 -6
- package/dist/config/defaults/db.d.ts +0 -2
- package/dist/config/defaults/db.js +0 -2
- package/dist/config/index.d.ts +10 -9
- package/dist/db/helpers.d.ts +6 -28
- package/dist/db/helpers.js +19 -149
- package/dist/db/index.d.ts +2 -0
- package/dist/db/index.js +4 -0
- package/dist/db/init.js +3 -2
- package/dist/db/migration/detect.d.ts +0 -3
- package/dist/db/migration/detect.js +0 -54
- package/dist/db/migration/importCollections.d.ts +1 -1
- package/dist/db/migration/importCollections.js +22 -6
- package/dist/db/migration/shared.d.ts +0 -4
- package/dist/db/migration/shared.js +0 -7
- package/dist/db/migration/transform.d.ts +2 -0
- package/dist/db/migration/transform.js +23 -0
- package/dist/db/pg/client.js +4 -0
- package/dist/db/pg/filters/edges.d.ts +1 -1
- package/dist/db/pg/filters/edges.js +1 -1
- package/dist/db/pg/filters/posts.d.ts +1 -0
- package/dist/db/pg/filters/posts.js +11 -1
- package/dist/db/pg/map/filters.js +5 -0
- package/dist/db/pg/map/relations.d.ts +1 -1
- package/dist/db/pg/map/relations.js +89 -41
- package/dist/db/pg/migrate.d.ts +23 -0
- package/dist/db/pg/migrate.js +87 -1
- package/dist/db/pg/schema/documents.d.ts +143 -0
- package/dist/db/pg/schema/documents.js +22 -1
- package/dist/db/pg/schema/edges.d.ts +1 -0
- package/dist/db/pg/schema/edges.js +2 -1
- package/dist/db/pg/schema/index.d.ts +143 -0
- package/dist/db/pg/sql/0007_shallow_oracle.sql +3 -0
- package/dist/db/pg/sql/0008_group_owner_roles.sql +31 -0
- package/dist/db/pg/sql/0009_event_occurrences.sql +26 -0
- package/dist/db/pg/sql/meta/0007_snapshot.json +4179 -0
- package/dist/db/pg/sql/meta/0009_snapshot.json +4299 -0
- package/dist/db/pg/sql/meta/_journal.json +21 -0
- package/dist/db/replaceOrigin.js +6 -0
- package/dist/db/types.d.ts +0 -4
- package/dist/events/index.d.ts +2 -1
- package/dist/events/index.js +54 -33
- package/dist/groups/finders.d.ts +2 -2
- package/dist/groups/helpers.d.ts +6 -6
- package/dist/groups/mapping.d.ts +4 -4
- package/dist/groups/mapping.js +2 -2
- package/dist/groups/mutations.js +1 -1
- package/dist/inviteLinks/helpers.d.ts +4 -4
- package/dist/jams/cache.d.ts +1 -1
- package/dist/jams/cache.js +2 -1
- package/dist/jams/finders.d.ts +2 -1
- package/dist/jams/finders.js +18 -7
- package/dist/jams/helpers.d.ts +4 -0
- package/dist/jams/index.d.ts +4 -3
- package/dist/jams/index.js +20 -13
- package/dist/jams/livekit.d.ts +46 -8
- package/dist/jams/livekit.js +103 -21
- package/dist/jams/mapping.d.ts +14 -4
- package/dist/jams/mutations.d.ts +2 -0
- package/dist/jams/rtmp.d.ts +5 -0
- package/dist/jams/rtmp.js +8 -0
- package/dist/jams/token.d.ts +3 -3
- package/dist/jams/token.js +15 -12
- package/dist/jams/waitingRoom.d.ts +6 -6
- package/dist/jams/waitingRoom.js +24 -23
- package/dist/migration/index.d.ts +4 -0
- package/dist/migration/index.js +4 -0
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +3 -1
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +3 -1
- package/dist/notifications/helpers.js +6 -2
- package/dist/notifications/push.js +11 -4
- package/dist/plugins/helpers.d.ts +1 -0
- package/dist/plugins/helpers.js +1 -8
- package/dist/plugins/index.d.ts +5 -0
- package/dist/plugins/index.js +41 -4
- package/dist/plugins/install.d.ts +20 -0
- package/dist/plugins/install.js +223 -0
- package/dist/plugins/state.d.ts +4 -0
- package/dist/plugins/state.js +29 -0
- package/dist/posts/eventAgenda.d.ts +165 -0
- package/dist/posts/eventAgenda.js +120 -0
- package/dist/posts/eventOccurrenceJobs.d.ts +4 -0
- package/dist/posts/eventOccurrenceJobs.js +23 -0
- package/dist/posts/eventOccurrences.d.ts +4 -0
- package/dist/posts/eventOccurrences.js +40 -0
- package/dist/posts/finders.d.ts +32 -8
- package/dist/posts/finders.js +27 -45
- package/dist/posts/helpers/filters.js +1 -1
- package/dist/posts/helpers/index.d.ts +102 -16
- package/dist/posts/helpers/index.js +33 -20
- package/dist/posts/index.d.ts +3 -0
- package/dist/posts/index.js +3 -0
- package/dist/posts/mapping.d.ts +275 -0
- package/dist/posts/mapping.js +37 -3
- package/dist/posts/mutations.d.ts +1 -1
- package/dist/posts/mutations.js +29 -18
- package/dist/posts/rsvpConfirmationEmail.js +2 -1
- package/dist/posts/unseenCounts.d.ts +2 -0
- package/dist/posts/unseenCounts.js +25 -8
- package/dist/profiles/cache.d.ts +3 -1
- package/dist/profiles/cache.js +9 -1
- package/dist/profiles/helpers.d.ts +5 -5
- package/dist/profiles/index.d.ts +1 -1
- package/dist/profiles/index.js +1 -1
- package/dist/profiles/mapping.d.ts +5 -5
- package/dist/profiles/mutations.js +12 -14
- package/dist/pushSubscriptions/helpers.d.ts +2 -2
- package/dist/pushSubscriptions/mutations.js +13 -1
- package/dist/reports/helpers.d.ts +6 -6
- package/dist/roles/defaults.js +1 -0
- package/dist/server/index.d.ts +7 -7
- package/dist/server/index.js +15 -8
- package/dist/stats/finders.d.ts +1692 -142
- package/dist/stats/mapping.d.ts +21 -0
- package/package.json +4 -9
- package/dist/db/arango.d.ts +0 -2
- package/dist/db/arango.js +0 -110
- package/dist/db/migration/autoMigrate.d.ts +0 -2
- package/dist/db/migration/autoMigrate.js +0 -111
- package/dist/db/migration/cli.d.ts +0 -1
- package/dist/db/migration/cli.js +0 -56
- package/dist/db/migration/exportArango.d.ts +0 -4
- package/dist/db/migration/exportArango.js +0 -80
package/dist/stats/mapping.d.ts
CHANGED
|
@@ -141,6 +141,27 @@ export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mappi
|
|
|
141
141
|
} | undefined;
|
|
142
142
|
} | undefined;
|
|
143
143
|
url?: string | undefined;
|
|
144
|
+
recurrence?: {
|
|
145
|
+
freq: "DAILY" | "WEEKLY" | "MONTHLY";
|
|
146
|
+
interval?: number | undefined;
|
|
147
|
+
byDay?: ("MO" | "TU" | "WE" | "TH" | "FR" | "SA" | "SU")[] | undefined;
|
|
148
|
+
until?: string | undefined;
|
|
149
|
+
count?: number | undefined;
|
|
150
|
+
} | undefined;
|
|
151
|
+
exceptions?: {
|
|
152
|
+
recurrenceId: string;
|
|
153
|
+
cancelled?: boolean | undefined;
|
|
154
|
+
start?: string | undefined;
|
|
155
|
+
end?: string | undefined;
|
|
156
|
+
physicalLocation?: {
|
|
157
|
+
text: string;
|
|
158
|
+
coordinates?: {
|
|
159
|
+
lat: number;
|
|
160
|
+
lng: number;
|
|
161
|
+
alt?: number | undefined;
|
|
162
|
+
} | undefined;
|
|
163
|
+
} | undefined;
|
|
164
|
+
}[] | undefined;
|
|
144
165
|
} | {
|
|
145
166
|
type: "article";
|
|
146
167
|
content?: string | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.33",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"dependencies": {
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"uuidv7": "^1.0.2",
|
|
39
39
|
"web-push": "^3.6.7",
|
|
40
40
|
"zod": "^4.4.3",
|
|
41
|
-
"@openpeepshq/common": "0.1.44",
|
|
42
41
|
"@openpeepshq/geocoder": "^0.1.2",
|
|
43
42
|
"@openpeepshq/fetch-client": "^0.1.7",
|
|
43
|
+
"@openpeepshq/common": "0.1.45",
|
|
44
44
|
"@openpeepshq/i18n": "^0.1.9"
|
|
45
45
|
},
|
|
46
46
|
"main": "dist/index.js",
|
|
@@ -67,7 +67,6 @@
|
|
|
67
67
|
"@types/web-push": "^3.6.4",
|
|
68
68
|
"@typescript-eslint/eslint-plugin": "^8.19.1",
|
|
69
69
|
"@typescript-eslint/parser": "^8.19.1",
|
|
70
|
-
"arangojs": "10.0.0",
|
|
71
70
|
"concurrently": "^9.1.2",
|
|
72
71
|
"drizzle-kit": "^0.31.1",
|
|
73
72
|
"eslint": "^9.17.0",
|
|
@@ -77,8 +76,7 @@
|
|
|
77
76
|
"prettier": "^3.4.2",
|
|
78
77
|
"tsc-alias": "^1.8.10",
|
|
79
78
|
"typescript": "^5.7.2",
|
|
80
|
-
"vitest": "^2.1.8"
|
|
81
|
-
"@openpeepshq/arango-querybuilder": "^0.4.7"
|
|
79
|
+
"vitest": "^2.1.8"
|
|
82
80
|
},
|
|
83
81
|
"scripts": {
|
|
84
82
|
"lint": "prettier --check . && ESLINT_USE_FLAT_CONFIG=false eslint .",
|
|
@@ -91,9 +89,6 @@
|
|
|
91
89
|
"create-migration": "node create-migration.js",
|
|
92
90
|
"db:generate": "drizzle-kit generate",
|
|
93
91
|
"db:migrate": "drizzle-kit migrate",
|
|
94
|
-
"db:studio": "drizzle-kit studio"
|
|
95
|
-
"db:export-arango": "pnpm build && node dist/db/migration/cli.js export",
|
|
96
|
-
"db:import-pg": "pnpm build && node dist/db/migration/cli.js import",
|
|
97
|
-
"db:validate-migration": "pnpm build && node dist/db/migration/cli.js validate"
|
|
92
|
+
"db:studio": "drizzle-kit studio"
|
|
98
93
|
}
|
|
99
94
|
}
|
package/dist/db/arango.d.ts
DELETED
package/dist/db/arango.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { Database } from 'arangojs';
|
|
2
|
-
import { defaultConfig } from '../config/defaults/core.js';
|
|
3
|
-
import { ArangoError } from 'arangojs/errors';
|
|
4
|
-
import { logger } from '../log/index.js';
|
|
5
|
-
import { sleep } from '@openpeepshq/common/lib';
|
|
6
|
-
const log = logger('openpeeps:db');
|
|
7
|
-
const DB_AVAILABILITY_TIMEOUT = 10000;
|
|
8
|
-
let dbPromise;
|
|
9
|
-
const handleArangoError = (method, params) => (e) => {
|
|
10
|
-
var _a;
|
|
11
|
-
if (e instanceof ArangoError) {
|
|
12
|
-
if (method === 'query') {
|
|
13
|
-
log.error('===============================');
|
|
14
|
-
log.error('===============================');
|
|
15
|
-
// @ts-expect-error type guaranteed because of method name
|
|
16
|
-
if (params[0].query && typeof params[0].query === 'string') {
|
|
17
|
-
// @ts-expect-error type guaranteed because of method name
|
|
18
|
-
const queryText = params[0].query;
|
|
19
|
-
log.error(queryText
|
|
20
|
-
.split('\n')
|
|
21
|
-
.map((line, i) => `${i + 1}: ${line}`)
|
|
22
|
-
.join('\n'));
|
|
23
|
-
// @ts-expect-error type guaranteed because of method name
|
|
24
|
-
log.error(params[0].bindVars);
|
|
25
|
-
log.error('querylength', queryText.length);
|
|
26
|
-
}
|
|
27
|
-
log.error('===============================');
|
|
28
|
-
log.error(e.message);
|
|
29
|
-
log.error('===============================');
|
|
30
|
-
throw new Error(e.message);
|
|
31
|
-
}
|
|
32
|
-
throw {
|
|
33
|
-
request: {
|
|
34
|
-
method,
|
|
35
|
-
params,
|
|
36
|
-
},
|
|
37
|
-
response: (_a = e.response) === null || _a === void 0 ? void 0 : _a.body,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
throw e;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const waitForDatabase = async (config) => {
|
|
45
|
-
const start = Date.now();
|
|
46
|
-
// Ping the server via `_system`; the target database may not exist yet.
|
|
47
|
-
const database = new Database(Object.assign(Object.assign({}, config), { databaseName: '_system' }));
|
|
48
|
-
let tryCount = 1;
|
|
49
|
-
while (true) {
|
|
50
|
-
log.info(`Checking ArangoDB availability at ${config.url} (try ${tryCount})`);
|
|
51
|
-
const availability = await database.availability(true).catch(() => false);
|
|
52
|
-
if (availability) {
|
|
53
|
-
log.info(`ArangoDB is available at ${config.url}`);
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
if (Date.now() - start > DB_AVAILABILITY_TIMEOUT) {
|
|
57
|
-
log.error(`ArangoDB is not available at ${config.url} after ${DB_AVAILABILITY_TIMEOUT}ms`);
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
await sleep(1);
|
|
61
|
-
tryCount++;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
const initArangoDb = async () => {
|
|
65
|
-
const config = defaultConfig.db;
|
|
66
|
-
await waitForDatabase(config);
|
|
67
|
-
if (config.databaseName) {
|
|
68
|
-
log.info(`Using database "${config.databaseName}"`);
|
|
69
|
-
const systemDb = new Database(Object.assign(Object.assign({}, config), { databaseName: '_system' }));
|
|
70
|
-
if (!(await systemDb.database(config.databaseName).exists())) {
|
|
71
|
-
log.info(`Creating database "${config.databaseName}"`);
|
|
72
|
-
await systemDb.createDatabase(config.databaseName);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
log.info('Using default database');
|
|
77
|
-
}
|
|
78
|
-
return new Proxy(new Database(defaultConfig.db), {
|
|
79
|
-
get: (target, propertyName) => {
|
|
80
|
-
const property = target[propertyName];
|
|
81
|
-
if (typeof property === 'function') {
|
|
82
|
-
const decoratedFunction = (...args) => {
|
|
83
|
-
try {
|
|
84
|
-
// @ts-expect-error typing is guaranteed to be correct
|
|
85
|
-
const result = target[propertyName](...args);
|
|
86
|
-
if (result instanceof Promise) {
|
|
87
|
-
return result.catch(handleArangoError(propertyName, args));
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
catch (e) {
|
|
94
|
-
handleArangoError(propertyName, args)(e);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
return decoratedFunction.bind(target);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
return target[propertyName];
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
export const arangoDb = async () => {
|
|
106
|
-
if (!dbPromise) {
|
|
107
|
-
dbPromise = initArangoDb();
|
|
108
|
-
}
|
|
109
|
-
return dbPromise;
|
|
110
|
-
};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { mkdtemp, rm, writeFile, access, readFile } from 'node:fs/promises';
|
|
2
|
-
import { constants } from 'node:fs';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { logger } from '../../log/index.js';
|
|
6
|
-
import { SCHEMA_MIGRATE_LOCK, closePostgres, resetPostgresSchemas, withPostgresAdvisoryLock, } from '../pg/client.js';
|
|
7
|
-
import { arangoHasSourceData, isPostgresEmpty } from './detect.js';
|
|
8
|
-
import { exportArango } from './exportArango.js';
|
|
9
|
-
import { importPostgres } from './importPostgres.js';
|
|
10
|
-
import { validateMigration } from './validate.js';
|
|
11
|
-
const log = logger('core:migration:auto');
|
|
12
|
-
const autoMigrateEnabled = () => process.env.AUTO_MIGRATE_FROM_ARANGO !== 'false';
|
|
13
|
-
export const autoMigrateFailureMarkerPath = () => process.env.AUTO_MIGRATE_FAILURE_MARKER ||
|
|
14
|
-
// Ephemeral container path (not on apatlogs/apatfiles volumes) so a
|
|
15
|
-
// replaced/updated container retries migration automatically.
|
|
16
|
-
join(tmpdir(), 'openpeeps-auto-migrate-from-arango.failed');
|
|
17
|
-
const markerExists = async (path) => {
|
|
18
|
-
try {
|
|
19
|
-
await access(path, constants.F_OK);
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
catch (_a) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
/** Stay alive so Docker `restart: always` does not retry a failed migration. */
|
|
27
|
-
const idleForever = async (message) => {
|
|
28
|
-
log.error(message);
|
|
29
|
-
// A bare pending Promise does not keep Node's event loop alive — schedule a
|
|
30
|
-
// timer so the process does not exit(0) and get restarted by Docker.
|
|
31
|
-
await new Promise(() => {
|
|
32
|
-
setInterval(() => undefined, 60000);
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
const writeFailureMarker = async (detail) => {
|
|
36
|
-
const marker = autoMigrateFailureMarkerPath();
|
|
37
|
-
try {
|
|
38
|
-
await writeFile(marker, `Automatic Arango → Postgres migration failed at ${new Date().toISOString()}\n\n${detail}\n`, 'utf8');
|
|
39
|
-
log.error('Wrote auto-migration failure marker to %s (remove it to retry after fixing data)', marker);
|
|
40
|
-
}
|
|
41
|
-
catch (markerErr) {
|
|
42
|
-
log.error('Failed to write auto-migration failure marker to %s', marker, markerErr);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
export const maybeAutoMigrateFromArango = async () => {
|
|
46
|
-
if (!autoMigrateEnabled()) {
|
|
47
|
-
log.info('Automatic Arango → Postgres migration is disabled');
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const marker = autoMigrateFailureMarkerPath();
|
|
51
|
-
if (await markerExists(marker)) {
|
|
52
|
-
const previous = await readFile(marker, 'utf8').catch(() => '');
|
|
53
|
-
await idleForever(`Previous automatic Arango → Postgres migration failed. Marker: ${marker}\n${previous}`);
|
|
54
|
-
}
|
|
55
|
-
if (!(await isPostgresEmpty())) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
if (!(await arangoHasSourceData())) {
|
|
59
|
-
log.info('Postgres is empty and no Arango source data was found; skipping auto migration');
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
let failureDetail;
|
|
63
|
-
// Serialize against concurrent apat processes (compose scale, rolling
|
|
64
|
-
// restart). A peer that hits a migrate conflict used to DROP SCHEMA under
|
|
65
|
-
// an in-flight import — holding this lock for the whole import prevents that.
|
|
66
|
-
await withPostgresAdvisoryLock(SCHEMA_MIGRATE_LOCK.key1, SCHEMA_MIGRATE_LOCK.key2, async () => {
|
|
67
|
-
var _a;
|
|
68
|
-
if (!(await isPostgresEmpty())) {
|
|
69
|
-
log.info('Postgres is no longer empty after acquiring migrate lock; skipping auto migration');
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
const exportDir = await mkdtemp(join(tmpdir(), 'openpeeps-arango-export-'));
|
|
73
|
-
log.info('Postgres is empty and Arango has data; starting automatic migration (export dir: %s)', exportDir);
|
|
74
|
-
try {
|
|
75
|
-
await exportArango(exportDir);
|
|
76
|
-
await importPostgres(exportDir, { closeConnection: false });
|
|
77
|
-
const result = await validateMigration(exportDir, {
|
|
78
|
-
closeConnection: false,
|
|
79
|
-
});
|
|
80
|
-
if (!result.ok) {
|
|
81
|
-
throw new Error(`Automatic Arango → Postgres migration failed validation (${result.issues.length} issue(s))`);
|
|
82
|
-
}
|
|
83
|
-
log.info('Automatic Arango → Postgres migration completed successfully');
|
|
84
|
-
}
|
|
85
|
-
catch (err) {
|
|
86
|
-
failureDetail =
|
|
87
|
-
err instanceof Error
|
|
88
|
-
? `${err.message}\n${(_a = err.stack) !== null && _a !== void 0 ? _a : ''}`
|
|
89
|
-
: String(err);
|
|
90
|
-
log.error('Automatic Arango → Postgres migration failed:\n%s', failureDetail);
|
|
91
|
-
try {
|
|
92
|
-
// Keep the pool open until the advisory lock client is released.
|
|
93
|
-
await resetPostgresSchemas({ closePool: false });
|
|
94
|
-
log.warn('Wiped Postgres public + drizzle schemas after failed migration');
|
|
95
|
-
}
|
|
96
|
-
catch (wipeErr) {
|
|
97
|
-
log.error('Failed to wipe Postgres after auto-migration failure', wipeErr);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
finally {
|
|
101
|
-
await rm(exportDir, { recursive: true, force: true }).catch((err) => {
|
|
102
|
-
log.warn('Failed to remove temporary export directory %s', exportDir, err);
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
if (failureDetail) {
|
|
107
|
-
await closePostgres();
|
|
108
|
-
await writeFailureMarker(failureDetail);
|
|
109
|
-
await idleForever('Automatic Arango → Postgres migration failed; Postgres was wiped and this process will idle. Redeploy/replace the container (or remove the ephemeral failure marker) to retry.');
|
|
110
|
-
}
|
|
111
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const runCli: (argv?: string[]) => Promise<0 | 1>;
|
package/dist/db/migration/cli.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { logger } from '../../log/index.js';
|
|
2
|
-
import { exportArango } from './exportArango.js';
|
|
3
|
-
import { importPostgres } from './importPostgres.js';
|
|
4
|
-
import { exportDirFromEnv } from './shared.js';
|
|
5
|
-
import { validateMigration } from './validate.js';
|
|
6
|
-
const log = logger('core:migration:cli');
|
|
7
|
-
const usage = () => {
|
|
8
|
-
console.log(`Usage: node dist/db/migration/cli.js <command>
|
|
9
|
-
|
|
10
|
-
Commands:
|
|
11
|
-
export Export ArangoDB collections to JSONL (DB_URL, DB_NAME)
|
|
12
|
-
import Import export into Postgres (DATABASE_URL)
|
|
13
|
-
validate Compare Postgres to import-stats.json (or export manifest) + checksums
|
|
14
|
-
|
|
15
|
-
Environment:
|
|
16
|
-
MIGRATION_EXPORT_DIR Export directory (default: ./arango-export)
|
|
17
|
-
DB_URL Arango server URL (default: http://localhost:8529)
|
|
18
|
-
DB_NAME Arango database name
|
|
19
|
-
DATABASE_URL Postgres connection string
|
|
20
|
-
`);
|
|
21
|
-
};
|
|
22
|
-
export const runCli = async (argv = process.argv.slice(2)) => {
|
|
23
|
-
const [command] = argv;
|
|
24
|
-
const exportDir = exportDirFromEnv();
|
|
25
|
-
switch (command) {
|
|
26
|
-
case 'export': {
|
|
27
|
-
await exportArango(exportDir);
|
|
28
|
-
return 0;
|
|
29
|
-
}
|
|
30
|
-
case 'import': {
|
|
31
|
-
await importPostgres(exportDir);
|
|
32
|
-
return 0;
|
|
33
|
-
}
|
|
34
|
-
case 'validate': {
|
|
35
|
-
const result = await validateMigration(exportDir);
|
|
36
|
-
return result.ok ? 0 : 1;
|
|
37
|
-
}
|
|
38
|
-
default:
|
|
39
|
-
usage();
|
|
40
|
-
if (command) {
|
|
41
|
-
log.error('Unknown command: %s', command);
|
|
42
|
-
return 1;
|
|
43
|
-
}
|
|
44
|
-
return 1;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
runCli()
|
|
48
|
-
.then((code) => {
|
|
49
|
-
if (code !== 0) {
|
|
50
|
-
process.exitCode = code;
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
.catch((err) => {
|
|
54
|
-
log.error('Migration CLI failed', err);
|
|
55
|
-
process.exitCode = 1;
|
|
56
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
2
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
3
|
-
var m = o[Symbol.asyncIterator], i;
|
|
4
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
5
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
6
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
7
|
-
};
|
|
8
|
-
import { appendFile, mkdir, writeFile } from 'node:fs/promises';
|
|
9
|
-
import { join } from 'node:path';
|
|
10
|
-
import { aql, Database } from 'arangojs';
|
|
11
|
-
import { collectionInfos } from '../pg/collections.js';
|
|
12
|
-
import { logger } from '../../log/index.js';
|
|
13
|
-
import { arangoConfig, collectionFilePath, collectionsDir, exportDirFromEnv, sortedChecksum, writeManifest, } from './shared.js';
|
|
14
|
-
const log = logger('core:migration:export');
|
|
15
|
-
export const connectArango = () => new Database(arangoConfig());
|
|
16
|
-
export const exportArango = async (exportDir = exportDirFromEnv()) => {
|
|
17
|
-
var _a, e_1, _b, _c;
|
|
18
|
-
var _d;
|
|
19
|
-
const config = arangoConfig();
|
|
20
|
-
const db = connectArango();
|
|
21
|
-
log.info('Exporting ArangoDB from %s (database: %s)', config.url, (_d = config.databaseName) !== null && _d !== void 0 ? _d : 'default');
|
|
22
|
-
await mkdir(collectionsDir(exportDir), { recursive: true });
|
|
23
|
-
await writeFile(join(exportDir, 'collectionInfos.json'), JSON.stringify(collectionInfos, null, 2));
|
|
24
|
-
const collections = {};
|
|
25
|
-
const accountEmails = [];
|
|
26
|
-
const postIds = [];
|
|
27
|
-
for (const collectionInfo of Object.values(collectionInfos)) {
|
|
28
|
-
const collectionName = collectionInfo.name;
|
|
29
|
-
const filePath = collectionFilePath(exportDir, collectionName);
|
|
30
|
-
if (!(await db.collection(collectionName).exists())) {
|
|
31
|
-
log.info('Skipping missing collection %s', collectionName);
|
|
32
|
-
collections[collectionName] = 0;
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
log.info('Exporting collection %s', collectionName);
|
|
36
|
-
let count = 0;
|
|
37
|
-
const cursor = await db.query(aql `
|
|
38
|
-
FOR doc IN ${db.collection(collectionName)}
|
|
39
|
-
RETURN doc
|
|
40
|
-
`);
|
|
41
|
-
try {
|
|
42
|
-
for (var _e = true, cursor_1 = (e_1 = void 0, __asyncValues(cursor)), cursor_1_1; cursor_1_1 = await cursor_1.next(), _a = cursor_1_1.done, !_a; _e = true) {
|
|
43
|
-
_c = cursor_1_1.value;
|
|
44
|
-
_e = false;
|
|
45
|
-
const doc = _c;
|
|
46
|
-
const record = doc;
|
|
47
|
-
await appendFile(filePath, `${JSON.stringify(record)}\n`);
|
|
48
|
-
count++;
|
|
49
|
-
if (collectionName === 'accounts' && typeof record.email === 'string') {
|
|
50
|
-
accountEmails.push(record.email);
|
|
51
|
-
}
|
|
52
|
-
if (collectionName === 'posts' && typeof record._key === 'string') {
|
|
53
|
-
postIds.push(record._key);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
58
|
-
finally {
|
|
59
|
-
try {
|
|
60
|
-
if (!_e && !_a && (_b = cursor_1.return)) await _b.call(cursor_1);
|
|
61
|
-
}
|
|
62
|
-
finally { if (e_1) throw e_1.error; }
|
|
63
|
-
}
|
|
64
|
-
collections[collectionName] = count;
|
|
65
|
-
log.info('Exported %d documents from %s', count, collectionName);
|
|
66
|
-
}
|
|
67
|
-
const manifest = {
|
|
68
|
-
exportedAt: new Date().toISOString(),
|
|
69
|
-
dbUrl: config.url,
|
|
70
|
-
dbName: config.databaseName,
|
|
71
|
-
collections,
|
|
72
|
-
checksums: {
|
|
73
|
-
accountEmails: sortedChecksum(accountEmails),
|
|
74
|
-
postIds: sortedChecksum(postIds),
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
await writeManifest(exportDir, manifest);
|
|
78
|
-
log.info('Export complete: %s', exportDir);
|
|
79
|
-
return manifest;
|
|
80
|
-
};
|