@openpeepshq/core 0.1.33 → 0.1.35
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/finders.js +5 -6
- package/dist/accessTokens/mutations.js +1 -1
- package/dist/accessTokens/tokens.js +8 -11
- package/dist/accounts/helpers.js +6 -2
- package/dist/accounts/mutations.js +36 -33
- package/dist/analytics/cache.js +3 -3
- package/dist/analytics/clicks.js +14 -22
- package/dist/analytics/compile.js +17 -12
- package/dist/analytics/dateRange.js +3 -5
- package/dist/analytics/jobs.js +3 -4
- package/dist/analytics/pdfReport.js +45 -61
- package/dist/analytics/privacy.js +1 -1
- package/dist/analytics/read.js +164 -140
- package/dist/analytics/report.d.ts +22 -1
- package/dist/analytics/report.js +2 -3
- package/dist/analytics/settings.js +3 -4
- package/dist/backups/index.js +82 -25
- package/dist/backups/metadata.d.ts +2 -3
- package/dist/backups/metadata.js +6 -2
- package/dist/config/db.js +2 -4
- package/dist/config/defaults/capabilities.js +13 -2
- package/dist/config/defaults/community.js +8 -3
- package/dist/config/defaults/core.d.ts +1 -1
- package/dist/config/defaults/core.js +16 -8
- package/dist/config/index.d.ts +22 -0
- package/dist/config/index.js +15 -11
- package/dist/db/explorer/query.js +9 -8
- package/dist/db/explorer/sql.js +8 -8
- package/dist/db/helpers.d.ts +1 -0
- package/dist/db/helpers.js +25 -7
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +1 -0
- package/dist/db/init.js +2 -3
- package/dist/db/migration/importCollections.d.ts +14 -9
- package/dist/db/migration/importCollections.js +121 -174
- package/dist/db/migration/shared.d.ts +2 -33
- package/dist/db/migration/shared.js +17 -87
- package/dist/db/pg/client.js +4 -7
- package/dist/db/pg/collections.d.ts +2 -2
- package/dist/db/pg/collections.js +2 -2
- package/dist/db/pg/filters/index.js +1 -1
- package/dist/db/pg/filters/posts.d.ts +12 -0
- package/dist/db/pg/filters/posts.js +30 -4
- package/dist/db/pg/filters/profiles.d.ts +1 -0
- package/dist/db/pg/filters/profiles.js +2 -1
- package/dist/db/pg/helpers.js +2 -14
- package/dist/db/pg/map/filters.js +40 -10
- package/dist/db/pg/map/helpers.js +5 -1
- package/dist/db/pg/map/index.js +46 -51
- package/dist/db/pg/map/mutations.js +65 -25
- package/dist/db/pg/map/registry.d.ts +5 -0
- package/dist/db/pg/map/registry.js +133 -56
- package/dist/db/pg/map/relations.js +76 -68
- package/dist/db/pg/map/search.js +15 -37
- package/dist/db/pg/mappers.js +13 -7
- package/dist/db/pg/migrate.d.ts +1 -2
- package/dist/db/pg/migrate.js +8 -9
- package/dist/db/pg/queries/activity.js +5 -5
- package/dist/db/pg/queries/derived.js +8 -12
- package/dist/db/pg/queries/sorts.d.ts +1 -0
- package/dist/db/pg/queries/sorts.js +4 -0
- package/dist/db/pg/schema/documents.d.ts +279 -41
- package/dist/db/pg/schema/documents.js +136 -22
- package/dist/db/pg/schema/edges.d.ts +116 -7
- package/dist/db/pg/schema/edges.js +9 -2
- package/dist/db/pg/schema/index.d.ts +362 -15
- package/dist/db/pg/schema/index.js +5 -1
- package/dist/db/pg/sql/0010_user_group_membership_roles.sql +16 -0
- package/dist/db/pg/sql/0011_drop_data_migrations.sql +1 -0
- package/dist/db/pg/sql/0012_posts_last_activity_at.sql +5 -0
- package/dist/db/pg/sql/0013_add_blocks_edge.sql +12 -0
- package/dist/db/pg/sql/0014_federation_datamodel.sql +59 -0
- package/dist/db/pg/sql/0015_profile_hashtags.sql +12 -0
- package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
- package/dist/db/pg/sql/meta/{0009_snapshot.json → 0015_snapshot.json} +291 -36
- package/dist/db/pg/sql/meta/_journal.json +49 -0
- package/dist/db/replaceOrigin.js +1 -1
- package/dist/email/queueStats.js +8 -11
- package/dist/email/render.js +14 -3
- package/dist/email/send.js +19 -17
- package/dist/email/smtpTest.js +10 -6
- package/dist/errors/index.js +1 -1
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.js +1 -0
- package/dist/events/once.js +2 -4
- package/dist/federation/activities.d.ts +17 -0
- package/dist/federation/activities.js +25 -0
- package/dist/federation/identity.d.ts +16 -0
- package/dist/federation/identity.js +52 -0
- package/dist/federation/index.d.ts +4 -0
- package/dist/federation/index.js +3 -0
- package/dist/federation/profiles.d.ts +3 -0
- package/dist/federation/profiles.js +14 -0
- package/dist/groups/finders.d.ts +2 -1
- package/dist/groups/helpers.d.ts +18 -0
- package/dist/groups/helpers.js +1 -2
- package/dist/groups/mapping.d.ts +4 -2
- package/dist/groups/mutations.js +1 -1
- package/dist/hashtags/finders.d.ts +6 -3
- package/dist/hashtags/finders.js +2 -0
- package/dist/hashtags/helpers.d.ts +8 -0
- package/dist/hashtags/helpers.js +4 -0
- package/dist/hashtags/index.d.ts +2 -0
- package/dist/hashtags/index.js +2 -0
- package/dist/hashtags/mutations.d.ts +3 -0
- package/dist/hashtags/mutations.js +13 -1
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.js +3 -1
- package/dist/i18n/pluginLocales.d.ts +6 -0
- package/dist/i18n/pluginLocales.js +15 -0
- package/dist/inviteLinks/mutations.js +2 -3
- package/dist/jams/export.d.ts +19 -0
- package/dist/jams/export.js +58 -0
- package/dist/jams/finders.js +4 -1
- package/dist/jams/health.d.ts +10 -0
- package/dist/jams/health.js +50 -0
- package/dist/jams/helpers.d.ts +2 -2
- package/dist/jams/helpers.js +6 -2
- package/dist/jams/index.d.ts +2 -0
- package/dist/jams/index.js +25 -18
- package/dist/jams/jobs.js +2 -3
- package/dist/jams/livekit.d.ts +49 -4
- package/dist/jams/livekit.js +62 -45
- package/dist/jams/mapping.d.ts +3 -3
- package/dist/jams/mutations.d.ts +1 -1
- package/dist/jams/recording.d.ts +10 -0
- package/dist/jams/recording.js +33 -1
- package/dist/jams/token.d.ts +13 -1
- package/dist/jams/token.js +25 -18
- package/dist/jams/waitingRoom.js +1 -1
- package/dist/jobs/index.d.ts +1 -0
- package/dist/jobs/index.js +9 -3
- package/dist/jobs/jobDetail.js +6 -12
- package/dist/jobs/jobLog.js +2 -3
- package/dist/lib/streams.js +4 -39
- package/dist/lib/zodDeepPartial.d.ts +1 -1
- package/dist/lib/zodDeepPartial.js +1 -1
- package/dist/log/index.js +13 -29
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.js +73 -12
- package/dist/media/jobs.js +1 -2
- package/dist/media/openpeeps/index.js +11 -46
- package/dist/media/processing.js +25 -11
- package/dist/media/streaming.js +5 -5
- package/dist/media/streamingCleanupJobs.js +1 -2
- package/dist/media/streamingJobs.js +3 -4
- package/dist/media/streamingPrewarm.js +7 -11
- package/dist/mediaAttachments/index.js +6 -2
- package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
- package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
- package/dist/notifications/defaultNotifications/follow/index.js +15 -18
- package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
- package/dist/notifications/defaultNotifications/index.js +4 -0
- package/dist/notifications/defaultNotifications/jamModerator/index.js +3 -5
- package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
- package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
- package/dist/notifications/defaultNotifications/mention/index.js +20 -24
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +11 -6
- package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
- package/dist/notifications/defaultNotifications/pollEnded/index.d.ts +19 -0
- package/dist/notifications/defaultNotifications/pollEnded/index.js +39 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.d.ts +3 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.js +17 -0
- package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
- package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
- package/dist/notifications/defaultNotifications/reply/index.js +21 -22
- package/dist/notifications/defaultNotifications/repost/index.js +16 -20
- package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
- package/dist/notifications/defaultNotifications/rsvp/index.js +31 -18
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +82 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
- package/dist/notifications/fcmCredential.js +1 -1
- package/dist/notifications/finders.js +1 -1
- package/dist/notifications/helpers.js +13 -10
- package/dist/notifications/jobs.js +10 -5
- package/dist/notifications/mutations.js +8 -1
- package/dist/notifications/push.js +11 -16
- package/dist/performance/index.js +3 -3
- package/dist/plugins/helpers.js +3 -6
- package/dist/plugins/index.js +39 -4
- package/dist/plugins/install.d.ts +28 -9
- package/dist/plugins/install.js +302 -56
- package/dist/plugins/pluginAuth.d.ts +1 -1
- package/dist/plugins/pluginAuth.js +13 -10
- package/dist/plugins/state.js +2 -3
- package/dist/posts/activity.d.ts +9 -0
- package/dist/posts/activity.js +34 -0
- package/dist/posts/contextClosure.d.ts +1 -9
- package/dist/posts/contextClosure.js +14 -44
- package/dist/posts/conversationQueries.d.ts +7 -0
- package/dist/posts/conversationQueries.js +76 -4
- package/dist/posts/eventAgenda.d.ts +1 -0
- package/dist/posts/eventAgenda.js +17 -8
- package/dist/posts/eventOccurrenceJobs.js +7 -2
- package/dist/posts/eventOccurrences.d.ts +6 -0
- package/dist/posts/eventOccurrences.js +22 -1
- package/dist/posts/finders.d.ts +56 -9
- package/dist/posts/finders.js +84 -23
- package/dist/posts/helpers/filters.js +13 -9
- package/dist/posts/helpers/index.d.ts +179 -14
- package/dist/posts/helpers/index.js +70 -34
- package/dist/posts/index.d.ts +5 -2
- package/dist/posts/index.js +5 -2
- package/dist/posts/mapping.d.ts +765 -30
- package/dist/posts/mapping.js +74 -31
- package/dist/posts/mutations.d.ts +516 -3
- package/dist/posts/mutations.js +179 -41
- package/dist/posts/pollEnd.d.ts +3 -0
- package/dist/posts/pollEnd.js +4 -0
- package/dist/posts/pollEndJobs.d.ts +8 -0
- package/dist/posts/pollEndJobs.js +49 -0
- package/dist/posts/replyClosure.d.ts +10 -0
- package/dist/posts/replyClosure.js +43 -0
- package/dist/posts/rsvpConfirmationEmail.js +23 -15
- package/dist/posts/threadPreview.d.ts +8 -0
- package/dist/posts/threadPreview.js +44 -0
- package/dist/posts/unseenCounts.js +4 -1
- package/dist/processingStats/queries.js +6 -7
- package/dist/profileSettings/cache.js +21 -5
- package/dist/profileSettings/mapping.d.ts +2 -0
- package/dist/profiles/activityQueries.d.ts +5 -0
- package/dist/profiles/activityQueries.js +85 -0
- package/dist/profiles/activitySummary.d.ts +3 -0
- package/dist/profiles/activitySummary.js +82 -0
- package/dist/profiles/blocks.d.ts +12 -0
- package/dist/profiles/blocks.js +73 -0
- package/dist/profiles/cache.d.ts +1 -0
- package/dist/profiles/cache.js +30 -10
- package/dist/profiles/export.js +30 -39
- package/dist/profiles/finders.d.ts +2 -1
- package/dist/profiles/finders.js +15 -8
- package/dist/profiles/helpers.d.ts +2 -0
- package/dist/profiles/index.d.ts +2 -0
- package/dist/profiles/index.js +2 -0
- package/dist/profiles/mapping.d.ts +10 -5
- package/dist/profiles/mapping.js +13 -1
- package/dist/profiles/mutations.d.ts +8 -4
- package/dist/profiles/mutations.js +31 -4
- package/dist/redis/connection.d.ts +2 -0
- package/dist/redis/connection.js +25 -6
- package/dist/reports/helpers.js +7 -3
- package/dist/roles/index.d.ts +1 -1
- package/dist/roles/index.js +1 -1
- package/dist/roles/mapping.d.ts +1 -0
- package/dist/roles/mutations.js +85 -3
- package/dist/search/finders.js +15 -3
- package/dist/search/helpers.js +1 -1
- package/dist/search/mapping.d.ts +1 -1
- package/dist/search/mapping.js +6 -2
- package/dist/sentry/index.js +9 -11
- package/dist/seo/index.d.ts +50 -0
- package/dist/seo/index.js +145 -0
- package/dist/seo/route.d.ts +18 -0
- package/dist/seo/route.js +19 -0
- package/dist/server/index.d.ts +19 -0
- package/dist/server/index.js +31 -14
- package/dist/server/stablePublicServerInfo.d.ts +17 -0
- package/dist/server/stablePublicServerInfo.js +37 -0
- package/dist/server/status.d.ts +25 -0
- package/dist/server/status.js +97 -0
- package/dist/session/index.js +2 -2
- package/dist/stats/finders.d.ts +1 -17681
- package/dist/stats/finders.js +22 -9
- package/dist/stats/helpers.js +4 -1
- package/dist/stats/mapping.d.ts +39 -2
- package/dist/stats/mapping.js +8 -4
- package/dist/stripe/cache.js +5 -6
- package/dist/stripe/connection.js +3 -4
- package/dist/stripe/helpers.js +15 -20
- package/package.json +5 -7
- package/dist/db/migration/detect.d.ts +0 -3
- package/dist/db/migration/detect.js +0 -33
- package/dist/db/migration/importPostgres.d.ts +0 -3
- package/dist/db/migration/importPostgres.js +0 -18
- package/dist/db/migration/transform.d.ts +0 -20
- package/dist/db/migration/transform.js +0 -232
- package/dist/db/migration/validate.d.ts +0 -18
- package/dist/db/migration/validate.js +0 -69
- package/dist/db/pg/sql/meta/0000_snapshot.json +0 -3380
- package/dist/db/pg/sql/meta/0004_snapshot.json +0 -4114
- package/dist/db/pg/sql/meta/0005_snapshot.json +0 -4179
- package/dist/db/pg/sql/meta/0006_snapshot.json +0 -4200
- package/dist/db/pg/sql/meta/0007_snapshot.json +0 -4179
- package/dist/mastodon/index.d.ts +0 -4
- package/dist/mastodon/index.js +0 -51
- package/dist/mastodon/types.d.ts +0 -7579
- package/dist/mastodon/types.js +0 -523
- package/dist/mastodon/typescript.d.ts +0 -1578
- package/dist/mastodon/typescript.js +0 -1
- package/dist/migration/index.d.ts +0 -4
- package/dist/migration/index.js +0 -4
- package/dist/roles/defaults.d.ts +0 -2
- package/dist/roles/defaults.js +0 -95
package/dist/db/helpers.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { parseFeedCursor } from '@openpeepshq/common';
|
|
2
|
+
import { and, eq } from 'drizzle-orm';
|
|
1
3
|
import { deleteEdge as deletePgEdge, insertEdge } from './pg/helpers.js';
|
|
2
4
|
import { asTable, edgeRegistry } from './pg/map/registry.js';
|
|
3
5
|
import { nowIso } from './pg/mappers.js';
|
|
4
|
-
import {
|
|
5
|
-
import { documentKeyAfter, documentKeyBefore } from './pg/filters/index.js';
|
|
6
|
+
import { documentKeyAfter, documentKeyBefore, postFilters } from './pg/filters/index.js';
|
|
6
7
|
import { sorts } from './pg/queries/index.js';
|
|
7
8
|
const getPgEdge = async (db, edgeCollectionName, fromId, toId) => {
|
|
8
9
|
const edgeConfig = edgeRegistry[edgeCollectionName];
|
|
@@ -18,7 +19,12 @@ const getPgEdge = async (db, edgeCollectionName, fromId, toId) => {
|
|
|
18
19
|
const row = rows[0];
|
|
19
20
|
if (!row)
|
|
20
21
|
return undefined;
|
|
21
|
-
return
|
|
22
|
+
return {
|
|
23
|
+
...row.body,
|
|
24
|
+
id: row.id,
|
|
25
|
+
_from: `${edgeConfig.fromCollection}/${row.fromId}`,
|
|
26
|
+
_to: `${edgeConfig.toCollection}/${row.toId}`,
|
|
27
|
+
};
|
|
22
28
|
};
|
|
23
29
|
export const connector = (fromCollectionInfo, toCollectionInfo, edgeCollectionInfo) => async (db, from, to, data = {}) => {
|
|
24
30
|
const edgeConfig = edgeRegistry[edgeCollectionInfo.name];
|
|
@@ -26,7 +32,12 @@ export const connector = (fromCollectionInfo, toCollectionInfo, edgeCollectionIn
|
|
|
26
32
|
throw new Error(`Unknown edge collection: ${edgeCollectionInfo.name}`);
|
|
27
33
|
}
|
|
28
34
|
const id = await insertEdge(db, edgeConfig.table, from.id, to.id, data);
|
|
29
|
-
return
|
|
35
|
+
return {
|
|
36
|
+
...data,
|
|
37
|
+
id,
|
|
38
|
+
_from: `${fromCollectionInfo.name}/${from.id}`,
|
|
39
|
+
_to: `${toCollectionInfo.name}/${to.id}`,
|
|
40
|
+
};
|
|
30
41
|
};
|
|
31
42
|
export const disconnector = (_fromCollectionInfo, _toCollectionInfo, edgeCollectionInfo) => async (db, from, to) => {
|
|
32
43
|
const edgeConfig = edgeRegistry[edgeCollectionInfo.name];
|
|
@@ -44,7 +55,7 @@ export const connectionUpdater = (_fromCollectionInfo, _toCollectionInfo, edgeCo
|
|
|
44
55
|
await db
|
|
45
56
|
.update(edgeConfig.table)
|
|
46
57
|
.set({
|
|
47
|
-
body: data
|
|
58
|
+
body: data ?? {},
|
|
48
59
|
updatedAt: nowIso(),
|
|
49
60
|
})
|
|
50
61
|
.where(and(eq(table.fromId, from.id), eq(table.toId, to.id)));
|
|
@@ -56,11 +67,18 @@ export const filterBefore = (mapping, id) => id
|
|
|
56
67
|
export const filterAfter = (mapping, id) => id
|
|
57
68
|
? mapping.filter(documentKeyAfter(mapping.data().collection, id))
|
|
58
69
|
: mapping;
|
|
59
|
-
export const addQuerySort = (mapping, sort) => (
|
|
70
|
+
export const addQuerySort = (mapping, sort) => (sort?.length ? mapping.sort(sort) : mapping);
|
|
60
71
|
export const sortNewestFirst = (mapping) => mapping.sort(sorts.idDesc);
|
|
61
72
|
export const sortOldestFirst = (mapping) => mapping.sort(sorts.idAsc);
|
|
62
73
|
export const addStartLimit = (mapping, start, limit = 100) => filterBefore(sortNewestFirst(mapping.limit(limit)), start);
|
|
63
|
-
export const addStart = (mapping, start) => filterBefore(sortNewestFirst(mapping), start);
|
|
74
|
+
export const addStart = (mapping, start) => filterBefore(sortNewestFirst(mapping), parseFeedCursor(start)?.id);
|
|
75
|
+
export const addActivityStart = (mapping, start) => {
|
|
76
|
+
const sorted = mapping.sort(sorts.lastActivityDesc);
|
|
77
|
+
const cursor = parseFeedCursor(start);
|
|
78
|
+
if (!cursor)
|
|
79
|
+
return sorted;
|
|
80
|
+
return sorted.filter(postFilters.afterActivity(cursor));
|
|
81
|
+
};
|
|
64
82
|
const buildLimit = (limit, offset) => limit && offset ? [offset, limit] : limit;
|
|
65
83
|
/**
|
|
66
84
|
* Ceiling on base rows read for one page, as a multiple of the page size. A
|
package/dist/db/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export * from './explorer';
|
|
|
5
5
|
export { map } from './pg/map';
|
|
6
6
|
export { collectionInfos } from './pg/collections';
|
|
7
7
|
export type { CollectionInfoKey } from './pg/collections';
|
|
8
|
-
export type
|
|
8
|
+
export { closePostgres, type PgDb } from './pg/client';
|
|
9
9
|
export type { PgFilter, SqlFilter } from './pg/map/queryTypes';
|
|
10
10
|
export { combine, createdAtBetween, documentKeyAfter, documentKeyBefore, edgeFilters, eventTimeFilters, groupFilters, isSqlFilter, notificationFilters, pgSql, postFilters, profileFilters, } from './pg/filters';
|
|
11
11
|
export { computedFields, sorts } from './pg/queries';
|
package/dist/db/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { empty } from './examples.js';
|
|
|
3
3
|
export * from './explorer/index.js';
|
|
4
4
|
export { map } from './pg/map/index.js';
|
|
5
5
|
export { collectionInfos } from './pg/collections.js';
|
|
6
|
+
export { closePostgres } from './pg/client.js';
|
|
6
7
|
export { combine, createdAtBetween, documentKeyAfter, documentKeyBefore, edgeFilters, eventTimeFilters, groupFilters, isSqlFilter, notificationFilters, pgSql, postFilters, profileFilters, } from './pg/filters/index.js';
|
|
7
8
|
export { computedFields, sorts } from './pg/queries/index.js';
|
|
8
9
|
let dbPromise;
|
package/dist/db/init.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { logger } from '../log/index.js';
|
|
2
2
|
import { initPostgres } from './pg/client.js';
|
|
3
|
+
import { backfillLocalFederationIdentities } from '../federation/identity.js';
|
|
3
4
|
const log = logger('openpeeps:db');
|
|
4
5
|
export const initDb = async () => {
|
|
5
6
|
log.info('Initializing Postgres');
|
|
6
|
-
if (process.env.AUTO_MIGRATE_FROM_ARANGO === 'true') {
|
|
7
|
-
log.warn('AUTO_MIGRATE_FROM_ARANGO is ignored at runtime. Use @openpeepshq/arango-migrate (archive/arango-migrate) for Arango cutover.');
|
|
8
|
-
}
|
|
9
7
|
const db = await initPostgres();
|
|
8
|
+
await backfillLocalFederationIdentities();
|
|
10
9
|
return { db };
|
|
11
10
|
};
|
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
/** Arango exports can contain duplicate _key lines; keep the last row per id. */
|
|
1
|
+
/** Keep the last row per id when a JSONL file repeats keys. */
|
|
3
2
|
export declare const dedupeRowsById: <T extends Record<string, unknown>>(rows: T[]) => T[];
|
|
4
3
|
export declare const collectionJsonlPath: (collectionsDir: string, collection: string) => string;
|
|
5
4
|
export declare const truncateAllTables: () => Promise<void>;
|
|
6
5
|
export declare const isUuid: (value: unknown) => value is string;
|
|
7
|
-
/** Collapse empty / duplicate hashtag names onto one row (unique on name). */
|
|
8
|
-
export declare const prepareHashtagRows: (rows: Record<string, unknown>[], context: ImportContext) => Record<string, unknown>[];
|
|
9
|
-
export declare const importArangoCollection: (collection: string, collectionsDir: string, context?: ImportContext) => Promise<number>;
|
|
10
6
|
export declare const importPostgresRowCollection: (collection: string, collectionsDir: string) => Promise<number>;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
/** Legacy reactions rows become append-only reaction entries. */
|
|
8
|
+
export declare const wrapReactionEntryBody: (body: Record<string, unknown> | null | undefined) => {
|
|
9
|
+
type: "reaction";
|
|
10
|
+
data: {
|
|
11
|
+
reaction: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/** Older dumps may still have reactions.jsonl; store them as entries. */
|
|
15
|
+
export declare const importLegacyReactionsAsEntries: (collectionsDir: string) => Promise<number>;
|
|
16
|
+
export type PlaceholderColumn = {
|
|
17
|
+
table: string;
|
|
18
|
+
column: string;
|
|
19
|
+
};
|
|
15
20
|
export declare const importAllPostgresCollections: (collectionsDir: string, schemaVersionFromBackup?: string) => Promise<{
|
|
16
21
|
imported: Record<string, number>;
|
|
17
22
|
total: number;
|
|
@@ -2,23 +2,33 @@ import { randomUUID } from 'node:crypto';
|
|
|
2
2
|
import { appendFile, access } from 'node:fs/promises';
|
|
3
3
|
import { constants } from 'node:fs';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
-
import { getTableName, sql } from 'drizzle-orm';
|
|
5
|
+
import { getTableColumns, getTableName, sql } from 'drizzle-orm';
|
|
6
6
|
import { logger } from '../../log/index.js';
|
|
7
7
|
import { pgDb } from '../pg/client.js';
|
|
8
8
|
import { resetAndMigrateToSchemaVersion, resolveRestoreSchemaVersion, runMigrations, } from '../pg/migrate.js';
|
|
9
|
-
import { documentRegistry, edgeRegistry, getTableForCollection, } from '../pg/map/registry.js';
|
|
10
|
-
import { arangoDocToDocumentRow, arangoDocToEdgeRow, buildPostCreatorIdByPostId, isEdgeCollection, normalizeImportId, } from './transform.js';
|
|
9
|
+
import { documentRegistry, edgeRegistry, getTableForCollection, isEdgeCollection, } from '../pg/map/registry.js';
|
|
11
10
|
import { BATCH_SIZE, DOCUMENT_IMPORT_ORDER, EDGE_IMPORT_ORDER, readJsonl, } from './shared.js';
|
|
12
11
|
const log = logger('core:db:import');
|
|
13
|
-
const
|
|
14
|
-
|
|
12
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
13
|
+
const normalizeImportId = (value) => {
|
|
14
|
+
if (typeof value !== 'string') {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
const trimmed = value.trim();
|
|
18
|
+
if (!trimmed) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return UUID_RE.test(trimmed) ? trimmed.toLowerCase() : trimmed;
|
|
22
|
+
};
|
|
23
|
+
const rowDedupeKey = (row) => normalizeImportId(row.id ?? row.key);
|
|
24
|
+
/** Keep the last row per id when a JSONL file repeats keys. */
|
|
15
25
|
export const dedupeRowsById = (rows) => {
|
|
16
26
|
const byKey = new Map();
|
|
17
27
|
const withoutKey = [];
|
|
18
28
|
for (const row of rows) {
|
|
19
29
|
const key = rowDedupeKey(row);
|
|
20
30
|
if (key) {
|
|
21
|
-
byKey.set(key, typeof row.id === 'string' ?
|
|
31
|
+
byKey.set(key, typeof row.id === 'string' ? { ...row, id: key } : row);
|
|
22
32
|
}
|
|
23
33
|
else {
|
|
24
34
|
withoutKey.push(row);
|
|
@@ -29,7 +39,6 @@ export const dedupeRowsById = (rows) => {
|
|
|
29
39
|
export const collectionJsonlPath = (collectionsDir, collection) => join(collectionsDir, `${collection}.jsonl`);
|
|
30
40
|
const isKnownCollection = (collection) => collection in documentRegistry || collection in edgeRegistry;
|
|
31
41
|
export const truncateAllTables = async () => {
|
|
32
|
-
var _a;
|
|
33
42
|
const db = pgDb();
|
|
34
43
|
const tableNames = [
|
|
35
44
|
...EDGE_IMPORT_ORDER.map((collection) => getTableName(edgeRegistry[collection].table)),
|
|
@@ -40,7 +49,7 @@ export const truncateAllTables = async () => {
|
|
|
40
49
|
const existing = [];
|
|
41
50
|
for (const name of tableNames) {
|
|
42
51
|
const result = await db.execute(sql.raw(`SELECT to_regclass('public.${name}')::text AS regclass`));
|
|
43
|
-
if (
|
|
52
|
+
if (result.rows[0]?.regclass != null) {
|
|
44
53
|
existing.push(name);
|
|
45
54
|
}
|
|
46
55
|
}
|
|
@@ -49,98 +58,20 @@ export const truncateAllTables = async () => {
|
|
|
49
58
|
}
|
|
50
59
|
await db.execute(sql.raw(`TRUNCATE TABLE ${existing.map((name) => `"${name}"`).join(', ')} RESTART IDENTITY CASCADE`));
|
|
51
60
|
};
|
|
52
|
-
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
53
61
|
export const isUuid = (value) => typeof value === 'string' && UUID_RE.test(value);
|
|
54
|
-
/**
|
|
55
|
-
* Edge `id` columns are uuid. Legacy Arango edge `_key`s are sometimes numeric
|
|
56
|
-
* (or otherwise non-UUID); replace those so the insert does not fail. Document
|
|
57
|
-
* collections are left alone (`data_migrations.id` is text, not uuid).
|
|
58
|
-
*/
|
|
59
62
|
const ensureEdgeUuidId = (collection, row) => {
|
|
60
|
-
var _a;
|
|
61
63
|
if (!isEdgeCollection(collection)) {
|
|
62
64
|
return row;
|
|
63
65
|
}
|
|
64
66
|
if (isUuid(row.id)) {
|
|
65
|
-
const normalized =
|
|
66
|
-
return normalized === row.id ? row :
|
|
67
|
+
const normalized = normalizeImportId(row.id) ?? String(row.id);
|
|
68
|
+
return normalized === row.id ? row : { ...row, id: normalized };
|
|
67
69
|
}
|
|
68
|
-
const next =
|
|
70
|
+
const next = { ...row, id: randomUUID() };
|
|
69
71
|
log.warn('Replaced non-UUID %s edge id %s with %s', collection, String(row.id), next.id);
|
|
70
72
|
return next;
|
|
71
73
|
};
|
|
72
|
-
const
|
|
73
|
-
if (collection === 'posts' && !row.creatorId) {
|
|
74
|
-
log.warn('Skipping post %s: missing creatorId', row.id);
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
if (collection === 'jamEvents' && !row.postId) {
|
|
78
|
-
log.warn('Skipping jam event %s: missing postId', row.id);
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
if (collection === 'profileSettings' && !row.profileId) {
|
|
82
|
-
log.warn('Skipping profile settings %s: missing profileId', row.id);
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
return true;
|
|
86
|
-
};
|
|
87
|
-
/** Collapse empty / duplicate hashtag names onto one row (unique on name). */
|
|
88
|
-
export const prepareHashtagRows = (rows, context) => {
|
|
89
|
-
var _a;
|
|
90
|
-
const remap = (_a = context.hashtagIdRemap) !== null && _a !== void 0 ? _a : new Map();
|
|
91
|
-
context.hashtagIdRemap = remap;
|
|
92
|
-
const byName = new Map();
|
|
93
|
-
const prepared = [];
|
|
94
|
-
for (const row of rows) {
|
|
95
|
-
const id = typeof row.id === 'string' ? row.id : undefined;
|
|
96
|
-
const name = typeof row.name === 'string' ? row.name.trim().toLowerCase() : '';
|
|
97
|
-
if (!name) {
|
|
98
|
-
if (id)
|
|
99
|
-
remap.set(id, '');
|
|
100
|
-
log.warn('Skipping hashtag %s: empty name', id !== null && id !== void 0 ? id : '(no id)');
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
row.name = name;
|
|
104
|
-
const existing = byName.get(name);
|
|
105
|
-
if (existing) {
|
|
106
|
-
const keptId = typeof existing.id === 'string' ? existing.id : '';
|
|
107
|
-
if (id)
|
|
108
|
-
remap.set(id, keptId);
|
|
109
|
-
log.warn('Skipping duplicate hashtag name "%s" (id %s → %s)', name, id, keptId || '(unknown)');
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
byName.set(name, row);
|
|
113
|
-
prepared.push(row);
|
|
114
|
-
}
|
|
115
|
-
return prepared;
|
|
116
|
-
};
|
|
117
|
-
const applyHashtagEdgeRemap = (collection, rows, context) => {
|
|
118
|
-
var _a;
|
|
119
|
-
if (collection !== 'postHashtags' || !((_a = context.hashtagIdRemap) === null || _a === void 0 ? void 0 : _a.size)) {
|
|
120
|
-
return rows;
|
|
121
|
-
}
|
|
122
|
-
const remap = context.hashtagIdRemap;
|
|
123
|
-
const out = [];
|
|
124
|
-
let dropped = 0;
|
|
125
|
-
for (const row of rows) {
|
|
126
|
-
const toId = typeof row.toId === 'string' ? row.toId : undefined;
|
|
127
|
-
if (!toId || !remap.has(toId)) {
|
|
128
|
-
out.push(row);
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
const mapped = remap.get(toId);
|
|
132
|
-
if (!mapped) {
|
|
133
|
-
dropped += 1;
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
out.push(Object.assign(Object.assign({}, row), { toId: mapped }));
|
|
137
|
-
}
|
|
138
|
-
if (dropped > 0) {
|
|
139
|
-
log.warn('Dropped %d postHashtags edge(s) pointing at skipped hashtags', dropped);
|
|
140
|
-
}
|
|
141
|
-
return out;
|
|
142
|
-
};
|
|
143
|
-
export const importArangoCollection = async (collection, collectionsDir, context = {}) => {
|
|
74
|
+
export const importPostgresRowCollection = async (collection, collectionsDir) => {
|
|
144
75
|
if (!isKnownCollection(collection)) {
|
|
145
76
|
return 0;
|
|
146
77
|
}
|
|
@@ -148,123 +79,136 @@ export const importArangoCollection = async (collection, collectionsDir, context
|
|
|
148
79
|
try {
|
|
149
80
|
await access(filePath, constants.F_OK);
|
|
150
81
|
}
|
|
151
|
-
catch
|
|
82
|
+
catch {
|
|
152
83
|
return 0;
|
|
153
84
|
}
|
|
154
|
-
const
|
|
155
|
-
if (
|
|
85
|
+
const mapped = await readJsonl(filePath);
|
|
86
|
+
if (mapped.length === 0) {
|
|
156
87
|
return 0;
|
|
157
88
|
}
|
|
89
|
+
const withValidIds = mapped.map((row) => ensureEdgeUuidId(collection, row));
|
|
90
|
+
const rows = dedupeRowsById(withValidIds);
|
|
91
|
+
if (rows.length < mapped.length) {
|
|
92
|
+
log.warn('Dropped %d duplicate row(s) while importing %s', mapped.length - rows.length, collection);
|
|
93
|
+
}
|
|
158
94
|
const table = getTableForCollection(collection);
|
|
159
95
|
const db = pgDb();
|
|
160
|
-
let mapped = docs.map((doc) => isEdgeCollection(collection)
|
|
161
|
-
? arangoDocToEdgeRow(collection, doc)
|
|
162
|
-
: arangoDocToDocumentRow(collection, doc, context));
|
|
163
|
-
if (collection === 'hashtags') {
|
|
164
|
-
mapped = prepareHashtagRows(mapped, context);
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
mapped = mapped.filter((row) => documentRowIsImportable(collection, row));
|
|
168
|
-
}
|
|
169
|
-
mapped = applyHashtagEdgeRemap(collection, mapped, context);
|
|
170
|
-
mapped = mapped.map((row) => ensureEdgeUuidId(collection, row));
|
|
171
|
-
const beforeDedupe = mapped.length;
|
|
172
|
-
const rows = dedupeRowsById(mapped);
|
|
173
|
-
if (rows.length < beforeDedupe) {
|
|
174
|
-
log.warn('Dropped %d duplicate row(s) while importing %s (e.g. remapped config keys or duplicate _key)', beforeDedupe - rows.length, collection);
|
|
175
|
-
}
|
|
176
|
-
if (rows.length === 0) {
|
|
177
|
-
return 0;
|
|
178
|
-
}
|
|
179
96
|
let imported = 0;
|
|
180
97
|
for (let offset = 0; offset < rows.length; offset += BATCH_SIZE) {
|
|
181
98
|
const batch = rows.slice(offset, offset + BATCH_SIZE);
|
|
182
|
-
|
|
183
|
-
await db.insert(table).values(batch);
|
|
184
|
-
}
|
|
185
|
-
catch (err) {
|
|
186
|
-
const cause = err && typeof err === 'object' && 'cause' in err
|
|
187
|
-
? err.cause
|
|
188
|
-
: undefined;
|
|
189
|
-
const detail = cause instanceof Error
|
|
190
|
-
? cause.message
|
|
191
|
-
: err instanceof Error
|
|
192
|
-
? err.message
|
|
193
|
-
: String(err);
|
|
194
|
-
throw new Error(`Failed importing ${collection} batch at offset ${offset} (${batch.length} rows): ${detail}`);
|
|
195
|
-
}
|
|
99
|
+
await db.insert(table).values(batch);
|
|
196
100
|
imported += batch.length;
|
|
197
101
|
}
|
|
198
|
-
log.info('Imported %d rows into %s from
|
|
102
|
+
log.info('Imported %d rows into %s from Postgres JSONL', imported, collection);
|
|
199
103
|
return imported;
|
|
200
104
|
};
|
|
201
|
-
|
|
202
|
-
|
|
105
|
+
/** Legacy reactions rows become append-only reaction entries. */
|
|
106
|
+
export const wrapReactionEntryBody = (body) => {
|
|
107
|
+
if (body?.type === 'reaction') {
|
|
108
|
+
const reaction = typeof body.data?.reaction ===
|
|
109
|
+
'string'
|
|
110
|
+
? body.data.reaction
|
|
111
|
+
: typeof body.reaction === 'string'
|
|
112
|
+
? body.reaction
|
|
113
|
+
: '👍';
|
|
114
|
+
return { type: 'reaction', data: { reaction } };
|
|
115
|
+
}
|
|
116
|
+
const reaction = typeof body?.reaction === 'string' ? body.reaction : '👍';
|
|
117
|
+
return { type: 'reaction', data: { reaction } };
|
|
118
|
+
};
|
|
119
|
+
const insertEntryRows = async (rows) => {
|
|
120
|
+
if (rows.length === 0)
|
|
203
121
|
return 0;
|
|
122
|
+
const table = getTableForCollection('entries');
|
|
123
|
+
const db = pgDb();
|
|
124
|
+
let imported = 0;
|
|
125
|
+
for (let offset = 0; offset < rows.length; offset += BATCH_SIZE) {
|
|
126
|
+
const batch = rows.slice(offset, offset + BATCH_SIZE);
|
|
127
|
+
await db.insert(table).values(batch);
|
|
128
|
+
imported += batch.length;
|
|
204
129
|
}
|
|
205
|
-
|
|
130
|
+
return imported;
|
|
131
|
+
};
|
|
132
|
+
/** Older dumps may still have reactions.jsonl; store them as entries. */
|
|
133
|
+
export const importLegacyReactionsAsEntries = async (collectionsDir) => {
|
|
134
|
+
const filePath = collectionJsonlPath(collectionsDir, 'reactions');
|
|
206
135
|
try {
|
|
207
136
|
await access(filePath, constants.F_OK);
|
|
208
137
|
}
|
|
209
|
-
catch
|
|
138
|
+
catch {
|
|
210
139
|
return 0;
|
|
211
140
|
}
|
|
212
|
-
const
|
|
213
|
-
if (
|
|
141
|
+
const docs = await readJsonl(filePath);
|
|
142
|
+
if (docs.length === 0) {
|
|
214
143
|
return 0;
|
|
215
144
|
}
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
let imported = 0;
|
|
224
|
-
for (let offset = 0; offset < rows.length; offset += BATCH_SIZE) {
|
|
225
|
-
const batch = rows.slice(offset, offset + BATCH_SIZE);
|
|
226
|
-
await db.insert(table).values(batch);
|
|
227
|
-
imported += batch.length;
|
|
228
|
-
}
|
|
229
|
-
log.info('Imported %d rows into %s from Postgres JSONL', imported, collection);
|
|
145
|
+
const mapped = docs.map((doc) => ensureEdgeUuidId('entries', {
|
|
146
|
+
...doc,
|
|
147
|
+
body: wrapReactionEntryBody(doc.body ?? doc),
|
|
148
|
+
}));
|
|
149
|
+
const rows = dedupeRowsById(mapped);
|
|
150
|
+
const imported = await insertEntryRows(rows);
|
|
151
|
+
log.info('Imported %d legacy reactions as entries', imported);
|
|
230
152
|
return imported;
|
|
231
153
|
};
|
|
232
154
|
const sumImported = (imported) => Object.values(imported).reduce((sum, count) => sum + count, 0);
|
|
233
|
-
const
|
|
234
|
-
const
|
|
235
|
-
|
|
155
|
+
const liveColumnNames = async (table) => {
|
|
156
|
+
const result = await pgDb().execute(sql `SELECT column_name FROM information_schema.columns
|
|
157
|
+
WHERE table_schema = 'public' AND table_name = ${table}`);
|
|
158
|
+
return new Set(result.rows.map((row) => row.column_name));
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* A restore loads rows at an older schema version, but Drizzle names every
|
|
162
|
+
* column of the current table objects in its INSERT, so a column a later
|
|
163
|
+
* migration adds (e.g. `search_vector` in 0001) breaks the load. Add those as
|
|
164
|
+
* nullable placeholders and drop them again before migrating forward, so the
|
|
165
|
+
* migration still creates them itself and runs its backfill.
|
|
166
|
+
*/
|
|
167
|
+
const addPlaceholderColumns = async () => {
|
|
168
|
+
const db = pgDb();
|
|
169
|
+
const added = [];
|
|
170
|
+
for (const collection of [...DOCUMENT_IMPORT_ORDER, ...EDGE_IMPORT_ORDER]) {
|
|
171
|
+
const table = getTableForCollection(collection);
|
|
172
|
+
const tableName = getTableName(table);
|
|
173
|
+
const live = await liveColumnNames(tableName);
|
|
174
|
+
if (live.size === 0) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
for (const column of Object.values(getTableColumns(table))) {
|
|
178
|
+
if (live.has(column.name)) {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
await db.execute(sql.raw(`ALTER TABLE "${tableName}" ADD COLUMN "${column.name}" ${column.getSQLType()}`));
|
|
182
|
+
added.push({ table: tableName, column: column.name });
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (added.length > 0) {
|
|
186
|
+
log.info('Added %d placeholder column(s) for the restore: %s', added.length, added.map(({ table, column }) => `${table}.${column}`).join(', '));
|
|
187
|
+
}
|
|
188
|
+
return added;
|
|
189
|
+
};
|
|
190
|
+
const dropPlaceholderColumns = async (columns) => {
|
|
191
|
+
for (const { table, column } of columns) {
|
|
192
|
+
await pgDb().execute(sql.raw(`ALTER TABLE "${table}" DROP COLUMN IF EXISTS "${column}"`));
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const backfillFederationIdentities = async () => {
|
|
196
|
+
const { backfillLocalFederationIdentities } = await import('../../federation/identity.js');
|
|
197
|
+
await backfillLocalFederationIdentities();
|
|
198
|
+
};
|
|
199
|
+
const prepareSchemaForRestore = async (schemaVersionFromBackup) => {
|
|
200
|
+
const schemaVersion = resolveRestoreSchemaVersion(schemaVersionFromBackup);
|
|
201
|
+
log.info('Preparing postgres restore at schema %s', schemaVersion);
|
|
236
202
|
await resetAndMigrateToSchemaVersion(schemaVersion);
|
|
237
203
|
// 0006 added a unique (from_id, to_id) on post_seen; that was wrong for
|
|
238
204
|
// impressions. Drop it before import so pre-0007 backups with duplicate
|
|
239
205
|
// view rows can restore. 0007 (and later) drop it permanently.
|
|
240
206
|
await pgDb().execute(sql.raw('DROP INDEX IF EXISTS "post_seen_from_to_unique"'));
|
|
241
207
|
await truncateAllTables();
|
|
242
|
-
|
|
243
|
-
export const importAllArangoCollections = async (collectionsDir) => {
|
|
244
|
-
await prepareSchemaForRestore('arango');
|
|
245
|
-
const imported = {};
|
|
246
|
-
const context = {
|
|
247
|
-
postCreatorIdByPostId: await buildPostCreatorIdByPostId(collectionsDir),
|
|
248
|
-
hashtagIdRemap: new Map(),
|
|
249
|
-
};
|
|
250
|
-
// Skip dataMigrations — Arango-era migration ledger is unused on Postgres.
|
|
251
|
-
for (const collection of DOCUMENT_IMPORT_ORDER) {
|
|
252
|
-
if (collection === 'dataMigrations') {
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
imported[collection] = await importArangoCollection(collection, collectionsDir, context);
|
|
256
|
-
}
|
|
257
|
-
for (const collection of EDGE_IMPORT_ORDER) {
|
|
258
|
-
imported[collection] = await importArangoCollection(collection, collectionsDir, context);
|
|
259
|
-
}
|
|
260
|
-
log.info('Arango rows loaded; migrating schema forward to latest');
|
|
261
|
-
await runMigrations();
|
|
262
|
-
const total = sumImported(imported);
|
|
263
|
-
log.info('Arango JSONL import complete: %d rows across %d collections', total, Object.keys(imported).filter((key) => imported[key] > 0).length);
|
|
264
|
-
return { imported, total };
|
|
208
|
+
return addPlaceholderColumns();
|
|
265
209
|
};
|
|
266
210
|
export const importAllPostgresCollections = async (collectionsDir, schemaVersionFromBackup) => {
|
|
267
|
-
await prepareSchemaForRestore(
|
|
211
|
+
const placeholders = await prepareSchemaForRestore(schemaVersionFromBackup);
|
|
268
212
|
const imported = {};
|
|
269
213
|
for (const collection of DOCUMENT_IMPORT_ORDER) {
|
|
270
214
|
imported[collection] = await importPostgresRowCollection(collection, collectionsDir);
|
|
@@ -272,8 +216,11 @@ export const importAllPostgresCollections = async (collectionsDir, schemaVersion
|
|
|
272
216
|
for (const collection of EDGE_IMPORT_ORDER) {
|
|
273
217
|
imported[collection] = await importPostgresRowCollection(collection, collectionsDir);
|
|
274
218
|
}
|
|
219
|
+
imported.reactions = await importLegacyReactionsAsEntries(collectionsDir);
|
|
275
220
|
log.info('Postgres rows loaded; ensuring schema is at latest');
|
|
221
|
+
await dropPlaceholderColumns(placeholders);
|
|
276
222
|
await runMigrations();
|
|
223
|
+
await backfillFederationIdentities();
|
|
277
224
|
const total = sumImported(imported);
|
|
278
225
|
log.info('Postgres JSONL import complete: %d rows across %d collections', total, Object.keys(imported).filter((key) => imported[key] > 0).length);
|
|
279
226
|
return { imported, total };
|
|
@@ -1,35 +1,4 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const collectionsDir: (exportDir: string) => string;
|
|
4
|
-
export declare const manifestPath: (exportDir: string) => string;
|
|
5
|
-
/** Counts actually inserted into Postgres (after skips / remaps / dedupe). */
|
|
6
|
-
export declare const importStatsPath: (exportDir: string) => string;
|
|
7
|
-
export type ImportStats = {
|
|
8
|
-
importedAt: string;
|
|
9
|
-
collections: CollectionCounts;
|
|
10
|
-
};
|
|
11
|
-
export declare const collectionFilePath: (exportDir: string, collection: string) => string;
|
|
12
|
-
export declare const DOCUMENT_IMPORT_ORDER: readonly ["configs", "i18n", "dataMigrations", "accounts", "roles", "profiles", "groups", "hashtags", "posts", "notifications", "reports", "accessTokens", "pushSubscriptions", "inviteLinks", "jamEvents", "mediaAttachments", "processingStats", "profileSettings"];
|
|
13
|
-
export declare const EDGE_IMPORT_ORDER: readonly ["controls", "follows", "requestsFollow", "mentions", "audience", "postHashtags", "entries", "reactions", "replyTo", "repost", "bookmarks", "postSeen", "hasSeen", "hasRead", "userGroups", "postGroups", "hasRole", "profileAccessTokens", "accountToPushSubscription", "createdReport", "isReportedProfile", "isReportedObject", "inviteLinkCreators", "inviteLinkRedeemers", "jamRecordings"];
|
|
14
|
-
export type CollectionCounts = Record<string, number>;
|
|
15
|
-
export type MigrationManifest = {
|
|
16
|
-
exportedAt: string;
|
|
17
|
-
dbUrl: string;
|
|
18
|
-
dbName?: string;
|
|
19
|
-
collections: CollectionCounts;
|
|
20
|
-
checksums: {
|
|
21
|
-
accountEmails: string;
|
|
22
|
-
postIds: string;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
export declare const sha256: (value: string) => string;
|
|
26
|
-
export declare const sortedChecksum: (values: string[]) => string;
|
|
1
|
+
export declare const DOCUMENT_IMPORT_ORDER: readonly ["configs", "i18n", "accounts", "roles", "profiles", "groups", "hashtags", "posts", "notifications", "reports", "accessTokens", "pushSubscriptions", "inviteLinks", "jamEvents", "mediaAttachments", "processingStats", "profileSettings"];
|
|
2
|
+
export declare const EDGE_IMPORT_ORDER: readonly ["controls", "follows", "blocks", "requestsFollow", "mentions", "audience", "postHashtags", "entries", "replyTo", "repost", "bookmarks", "postSeen", "hasSeen", "hasRead", "userGroups", "postGroups", "hasRole", "profileAccessTokens", "accountToPushSubscription", "createdReport", "isReportedProfile", "isReportedObject", "inviteLinkCreators", "inviteLinkRedeemers", "jamRecordings", "profileHashtags"];
|
|
27
3
|
export declare const readJsonl: (filePath: string) => Promise<Record<string, unknown>[]>;
|
|
28
|
-
export declare const readManifest: (exportDir: string) => Promise<MigrationManifest>;
|
|
29
|
-
export declare const writeManifest: (exportDir: string, manifest: MigrationManifest) => Promise<void>;
|
|
30
|
-
export declare const writeImportStats: (exportDir: string, collections: CollectionCounts) => Promise<void>;
|
|
31
|
-
export declare const readImportStats: (exportDir: string) => Promise<ImportStats | null>;
|
|
32
|
-
/** Prefer post-import counts when present (skips / remaps / dedupe). */
|
|
33
|
-
export declare const expectedCollectionCount: (collection: string, manifestCounts: CollectionCounts, importedCounts: CollectionCounts | null) => number;
|
|
34
|
-
export declare const assertExportDir: (exportDir: string) => Promise<void>;
|
|
35
4
|
export declare const BATCH_SIZE = 500;
|