@stamhoofd/backend-statistics-syncer 2.153.0 → 2.161.1

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.
Files changed (83) hide show
  1. package/LICENSE.md +7 -7
  2. package/README.md +1 -1
  3. package/dist/index.js +5 -8
  4. package/dist/index.js.map +1 -0
  5. package/dist/migrations.js +19 -0
  6. package/dist/migrations.js.map +1 -0
  7. package/dist/src/boot.js +75 -0
  8. package/dist/src/boot.js.map +1 -0
  9. package/dist/src/crons.js +39 -0
  10. package/dist/src/crons.js.map +1 -0
  11. package/dist/src/database.js +88 -0
  12. package/dist/src/database.js.map +1 -0
  13. package/dist/src/migrate.js +38 -0
  14. package/dist/src/migrate.js.map +1 -0
  15. package/dist/src/migrations/1785958573-platform-statistics-schema.sql +382 -0
  16. package/dist/src/migrations/1786203367-postal-code-coordinates.sql +1203 -0
  17. package/dist/src/periods.js +86 -0
  18. package/dist/src/periods.js.map +1 -0
  19. package/dist/src/rows.js +209 -0
  20. package/dist/src/rows.js.map +1 -0
  21. package/dist/src/schema.js +28 -0
  22. package/dist/src/schema.js.map +1 -0
  23. package/dist/src/sources.js +10 -0
  24. package/dist/src/sources.js.map +1 -0
  25. package/dist/src/sync-state.js +36 -0
  26. package/dist/src/sync-state.js.map +1 -0
  27. package/dist/src/sync.js +608 -0
  28. package/dist/src/sync.js.map +1 -0
  29. package/dist/src/writer.js +63 -0
  30. package/dist/src/writer.js.map +1 -0
  31. package/dist-types/index.d.ts +2 -0
  32. package/dist-types/index.d.ts.map +1 -0
  33. package/dist-types/migrations.d.ts +2 -0
  34. package/dist-types/migrations.d.ts.map +1 -0
  35. package/dist-types/src/boot.d.ts +8 -0
  36. package/dist-types/src/boot.d.ts.map +1 -0
  37. package/dist-types/src/crons.d.ts +21 -0
  38. package/dist-types/src/crons.d.ts.map +1 -0
  39. package/dist-types/src/database.d.ts +28 -0
  40. package/dist-types/src/database.d.ts.map +1 -0
  41. package/dist-types/src/migrate.d.ts +2 -0
  42. package/dist-types/src/migrate.d.ts.map +1 -0
  43. package/dist-types/src/periods.d.ts +51 -0
  44. package/dist-types/src/periods.d.ts.map +1 -0
  45. package/dist-types/src/rows.d.ts +212 -0
  46. package/dist-types/src/rows.d.ts.map +1 -0
  47. package/dist-types/src/schema.d.ts +9 -0
  48. package/dist-types/src/schema.d.ts.map +1 -0
  49. package/dist-types/src/sources.d.ts +10 -0
  50. package/dist-types/src/sources.d.ts.map +1 -0
  51. package/dist-types/src/sync-state.d.ts +20 -0
  52. package/dist-types/src/sync-state.d.ts.map +1 -0
  53. package/dist-types/src/sync.d.ts +37 -0
  54. package/dist-types/src/sync.d.ts.map +1 -0
  55. package/dist-types/src/writer.d.ts +24 -0
  56. package/dist-types/src/writer.d.ts.map +1 -0
  57. package/index.ts +5 -8
  58. package/migrations.ts +16 -11
  59. package/package.json +37 -23
  60. package/src/boot.ts +7 -3
  61. package/src/crons.test.ts +33 -8
  62. package/src/crons.ts +7 -1
  63. package/src/database.test.ts +48 -11
  64. package/src/database.ts +30 -7
  65. package/src/migrate.ts +1 -1
  66. package/src/periods.ts +5 -2
  67. package/src/rows.test.ts +96 -16
  68. package/src/rows.ts +28 -6
  69. package/src/schema.test.ts +48 -19
  70. package/src/schema.ts +14 -4
  71. package/src/sync-state.test.ts +3 -1
  72. package/src/sync-state.ts +13 -4
  73. package/src/sync.test.ts +145 -32
  74. package/src/sync.ts +422 -91
  75. package/src/writer.ts +32 -10
  76. package/tsconfig.build.json +4 -11
  77. package/tsconfig.json +1 -1
  78. package/tsconfig.test.json +1 -3
  79. package/tsconfig.types.json +7 -0
  80. package/.gitignore +0 -221
  81. package/tests/vitest.global.setup.ts +0 -29
  82. package/tests/vitest.setup.ts +0 -24
  83. package/vitest.config.js +0 -18
@@ -0,0 +1,608 @@
1
+ import { Group, Member, MemberPlatformMembership, MemberResponsibilityRecord, Organization, Platform, Registration, RegistrationPeriod, } from '@stamhoofd/models';
2
+ import { SQL, SQLSelect, SQLWhereSign } from '@stamhoofd/node-sql';
3
+ import { getStatisticsConnection } from './database.js';
4
+ import { applyImportedCutoff, getImportedUntil, isFrozen, loadFrozenPeriodIds, loadSettledPeriodIds, releaseUnlockedPeriods, settleLockedPeriods, } from './periods.js';
5
+ import { flattenDefaultAgeGroup, flattenGroup, flattenMember, flattenMembership, flattenNamedConfig, flattenOrganization, flattenPlatform, flattenRegistration, flattenRegistrationPeriod, flattenResponsibilityRecord, } from './rows.js';
6
+ import { syncSource } from './sources.js';
7
+ import { nextWatermark, readSyncState, writeSyncState } from './sync-state.js';
8
+ import { deleteRows, iterateIds, upsertRows } from './writer.js';
9
+ /**
10
+ * How far before the watermark a run starts reading again. A row that was written while the previous
11
+ * run was reading may carry an `updatedAt` below the watermark that run ended on, so re-reading a
12
+ * window costs a few redundant upserts and closes that gap.
13
+ */
14
+ export const watermarkOverlap = 5 * 60 * 1000;
15
+ /** Source rows read per query. */
16
+ export const fetchBatchSize = 500;
17
+ /**
18
+ * Marks which pipeline wrote a row, so the reconciliation only ever checks its own against the main
19
+ * database and leaves imported rows alone.
20
+ */
21
+ export const sourceColumns = ['source'];
22
+ function withSource(rows) {
23
+ return rows.map((row) => ({ ...row, source: syncSource }));
24
+ }
25
+ function idsOf(rows) {
26
+ return rows.map((row) => row.id);
27
+ }
28
+ function groupByPeriod(organizations) {
29
+ const grouped = new Map();
30
+ for (const organization of organizations) {
31
+ const group = grouped.get(organization.periodId);
32
+ if (group) {
33
+ group.push(organization);
34
+ }
35
+ else {
36
+ grouped.set(organization.periodId, [organization]);
37
+ }
38
+ }
39
+ return grouped;
40
+ }
41
+ async function existingModelIds(model, ids) {
42
+ const rows = await model.select().where(SQL.column('id'), ids).fetch();
43
+ return new Set(idsOf(rows));
44
+ }
45
+ /**
46
+ * The periods each of these members or units holds a registration in.
47
+ *
48
+ * Both are recorded per year, and the source has no such row: a member is simply a member there and
49
+ * a unit simply a unit, and it is the registrations that place them in a year.
50
+ *
51
+ * Limited to the periods the statistics database already holds. A registration can point at a period
52
+ * that has not been synced yet, and a row for it would be refused by the foreign key, which would
53
+ * stall the whole table over one row.
54
+ */
55
+ async function periodIdsByRegistration(column, ids) {
56
+ const byId = new Map();
57
+ if (ids.length === 0) {
58
+ return byId;
59
+ }
60
+ const rows = await new SQLSelect((row) => ({
61
+ key: row[Registration.table][column],
62
+ periodId: row[Registration.table].periodId,
63
+ }), SQL.column(column), SQL.column('periodId'))
64
+ .from(Registration.table)
65
+ .where(SQL.column(column), ids)
66
+ .fetch();
67
+ const known = await existingPeriodIds(rows.map((row) => row.periodId).filter((id) => id !== null));
68
+ for (const row of rows) {
69
+ if (row.periodId !== null && known.has(row.periodId)) {
70
+ addTo(byId, row.key, row.periodId);
71
+ }
72
+ }
73
+ return byId;
74
+ }
75
+ function periodIdsByMember(memberIds) {
76
+ return periodIdsByRegistration('memberId', memberIds);
77
+ }
78
+ /**
79
+ * Which of these members are charged the platform's verlaagd lidgeld: those with financiële
80
+ * ondersteuning or an active UITPAS.
81
+ *
82
+ * That status is the input the price of a lidgeld is calculated from, and the only record of which
83
+ * tarief was charged -- the membership itself keeps the amount and not what it was made of. Read off
84
+ * the member here so a lidgeld row can carry it, which is the grain the reports split on.
85
+ *
86
+ * It answers what is true of the member now, like their gender and postal code, and lands in the
87
+ * years still open only: a settled year keeps the tarief it was counted with.
88
+ */
89
+ async function reducedPriceByMember(memberIds) {
90
+ const unique = [...new Set(memberIds)];
91
+ if (unique.length === 0) {
92
+ return new Set();
93
+ }
94
+ const members = (await Member.select().where(SQL.column('id'), unique).fetch());
95
+ return new Set(members
96
+ .filter((member) => member.details.shouldApplyReducedPrice)
97
+ .map((member) => member.id));
98
+ }
99
+ /**
100
+ * A unit also gets a row for the period it is in now, before anyone has registered in it: its netwerk
101
+ * is recorded against that period, and a netwerk link to a unit that has no row yet is a link to
102
+ * nothing.
103
+ */
104
+ async function periodIdsByOrganization(organizations) {
105
+ const byOrganization = await periodIdsByRegistration('organizationId', idsOf(organizations));
106
+ const known = await existingPeriodIds(organizations.map((organization) => organization.periodId));
107
+ for (const organization of organizations) {
108
+ if (known.has(organization.periodId)) {
109
+ addTo(byOrganization, organization.id, organization.periodId);
110
+ }
111
+ }
112
+ return byOrganization;
113
+ }
114
+ function addTo(map, key, value) {
115
+ const values = map.get(key);
116
+ if (values) {
117
+ values.add(value);
118
+ }
119
+ else {
120
+ map.set(key, new Set([value]));
121
+ }
122
+ }
123
+ async function existingPeriodIds(ids) {
124
+ const unique = [...new Set(ids)];
125
+ if (unique.length === 0) {
126
+ return new Set();
127
+ }
128
+ const connection = getStatisticsConnection();
129
+ const [rows] = await connection.select('SELECT `id` FROM `registration_periods` WHERE `id` IN (?)', [unique], { nestTables: false });
130
+ return new Set(rows.map((row) => row.id));
131
+ }
132
+ function incrementalQuery(model, since, afterId, limit) {
133
+ const query = model.select().where(SQL.column('id'), SQLWhereSign.Greater, afterId);
134
+ if (since) {
135
+ query.where(SQL.column('updatedAt'), SQLWhereSign.GreaterEqual, since);
136
+ }
137
+ return query.orderBy(SQL.column('id'), 'ASC').limit(limit);
138
+ }
139
+ /**
140
+ * The dimension ids the statistics database currently knows, across every period it holds them for.
141
+ * Rows referring to anything else are dropped or nulled before writing: platform configuration can
142
+ * lose an age group or a membership type while rows still point at it, and the reports would
143
+ * otherwise group by a name that is no longer there.
144
+ */
145
+ async function loadIdSet(table) {
146
+ const connection = getStatisticsConnection();
147
+ const [rows] = await connection.select(`SELECT DISTINCT \`id\` FROM ${connection.escapeId(table)}`, [], { nestTables: false });
148
+ return new Set(rows.map((row) => row.id));
149
+ }
150
+ /**
151
+ * The periods, which every other table here is keyed by and therefore has to be synced before any of
152
+ * them: which periods exist, and which of them are still open, decides what the rest of a run writes
153
+ * at all.
154
+ */
155
+ function periodsTable() {
156
+ return {
157
+ table: 'registration_periods',
158
+ columns: [
159
+ 'id',
160
+ 'startDate',
161
+ 'endDate',
162
+ 'locked',
163
+ 'organizationId',
164
+ 'previousPeriodId',
165
+ 'nextPeriodId',
166
+ 'customName',
167
+ 'name',
168
+ 'createdAt',
169
+ 'updatedAt',
170
+ ],
171
+ fetch: async (since, afterId, limit) => {
172
+ const periods = (await incrementalQuery(RegistrationPeriod, since, afterId, limit).fetch());
173
+ return {
174
+ rows: periods.map(flattenRegistrationPeriod),
175
+ updatedAt: periods.map((period) => period.updatedAt),
176
+ lastId: periods.at(-1)?.id ?? afterId,
177
+ };
178
+ },
179
+ existingIds: (ids) => existingModelIds(RegistrationPeriod, ids),
180
+ periodColumn: 'id',
181
+ // A period is what every historical figure hangs off, and everything else points at it with
182
+ // ON DELETE RESTRICT. Removing one would either be refused by the database or take a settled
183
+ // year's numbers with it, so a period that disappears from the administration stays here,
184
+ // like its members and organizations.
185
+ neverDelete: true,
186
+ };
187
+ }
188
+ function buildIncrementalTables(known, frozen, openPeriodIds) {
189
+ return [
190
+ {
191
+ table: 'organizations',
192
+ columns: [
193
+ 'id',
194
+ 'periodId',
195
+ 'name',
196
+ 'uri',
197
+ 'postalCode',
198
+ 'city',
199
+ 'active',
200
+ 'createdAt',
201
+ 'updatedAt',
202
+ ],
203
+ fetch: async (since, afterId, limit) => {
204
+ const organizations = (await incrementalQuery(Organization, since, afterId, limit).fetch());
205
+ await syncOrganizationTagsAndResponsibilities(organizations, frozen, openPeriodIds);
206
+ const periodIds = await periodIdsByOrganization(organizations);
207
+ const rows = organizations.flatMap((organization) => [...(periodIds.get(organization.id) ?? [])].map((periodId) => flattenOrganization(organization, periodId)));
208
+ return {
209
+ rows,
210
+ updatedAt: organizations.map((organization) => organization.updatedAt),
211
+ lastId: organizations.at(-1)?.id ?? afterId,
212
+ };
213
+ },
214
+ existingIds: (ids) => existingModelIds(Organization, ids),
215
+ periodColumn: 'periodId',
216
+ keyColumns: ['id', 'periodId'],
217
+ neverDelete: true,
218
+ },
219
+ {
220
+ table: 'groups',
221
+ columns: [
222
+ 'id',
223
+ 'type',
224
+ 'name',
225
+ 'organizationId',
226
+ 'periodId',
227
+ 'defaultAgeGroupId',
228
+ 'status',
229
+ 'deletedAt',
230
+ 'createdAt',
231
+ 'updatedAt',
232
+ ],
233
+ fetch: async (since, afterId, limit) => {
234
+ const groups = (await incrementalQuery(Group, since, afterId, limit).fetch());
235
+ const rows = groups.map((group) => {
236
+ const row = flattenGroup(group);
237
+ if (typeof row.defaultAgeGroupId === 'string' &&
238
+ !known.ageGroups.has(row.defaultAgeGroupId)) {
239
+ row.defaultAgeGroupId = null;
240
+ }
241
+ return row;
242
+ });
243
+ return {
244
+ rows,
245
+ updatedAt: groups.map((group) => group.updatedAt),
246
+ lastId: groups.at(-1)?.id ?? afterId,
247
+ };
248
+ },
249
+ existingIds: (ids) => existingModelIds(Group, ids),
250
+ periodColumn: 'periodId',
251
+ },
252
+ {
253
+ table: 'members',
254
+ columns: [
255
+ 'id',
256
+ 'periodId',
257
+ 'birthDate',
258
+ 'gender',
259
+ 'postalCode',
260
+ 'organizationId',
261
+ 'createdAt',
262
+ 'updatedAt',
263
+ 'lastRegisteredAt',
264
+ ],
265
+ fetch: async (since, afterId, limit) => {
266
+ const members = (await incrementalQuery(Member, since, afterId, limit).fetch());
267
+ const periodIds = await periodIdsByMember(members.map((member) => member.id));
268
+ const rows = members.flatMap((member) => [...(periodIds.get(member.id) ?? [])].map((periodId) => flattenMember(member, periodId)));
269
+ return {
270
+ rows,
271
+ updatedAt: members.map((member) => member.updatedAt),
272
+ lastId: members.at(-1)?.id ?? afterId,
273
+ };
274
+ },
275
+ existingIds: (ids) => existingModelIds(Member, ids),
276
+ periodColumn: 'periodId',
277
+ keyColumns: ['id', 'periodId'],
278
+ neverDelete: true,
279
+ },
280
+ {
281
+ table: 'registrations',
282
+ columns: [
283
+ 'id',
284
+ 'organizationId',
285
+ 'memberId',
286
+ 'groupId',
287
+ 'periodId',
288
+ 'registeredAt',
289
+ 'startDate',
290
+ 'endDate',
291
+ 'trialUntil',
292
+ 'deactivatedAt',
293
+ 'createdAt',
294
+ 'updatedAt',
295
+ ],
296
+ fetch: async (since, afterId, limit) => {
297
+ const registrations = (await incrementalQuery(Registration, since, afterId, limit).fetch());
298
+ return {
299
+ rows: registrations.map(flattenRegistration),
300
+ updatedAt: registrations.map((registration) => registration.updatedAt),
301
+ lastId: registrations.at(-1)?.id ?? afterId,
302
+ };
303
+ },
304
+ existingIds: (ids) => existingModelIds(Registration, ids),
305
+ periodColumn: 'periodId',
306
+ },
307
+ {
308
+ table: 'member_platform_memberships',
309
+ columns: [
310
+ 'id',
311
+ 'memberId',
312
+ 'membershipTypeId',
313
+ 'reducedPrice',
314
+ 'organizationId',
315
+ 'periodId',
316
+ 'startDate',
317
+ 'endDate',
318
+ 'expireDate',
319
+ 'trialUntil',
320
+ 'deletedAt',
321
+ 'createdAt',
322
+ 'updatedAt',
323
+ ],
324
+ fetch: async (since, afterId, limit) => {
325
+ const memberships = (await incrementalQuery(MemberPlatformMembership, since, afterId, limit).fetch());
326
+ const kept = memberships.filter((membership) => known.membershipTypes.has(membership.membershipTypeId));
327
+ const reduced = await reducedPriceByMember(kept.map((membership) => membership.memberId));
328
+ const rows = kept.map((membership) => flattenMembership(membership, reduced.has(membership.memberId)));
329
+ return {
330
+ rows,
331
+ updatedAt: kept.map((membership) => membership.updatedAt),
332
+ lastId: memberships.at(-1)?.id ?? afterId,
333
+ };
334
+ },
335
+ existingIds: (ids) => existingModelIds(MemberPlatformMembership, ids),
336
+ periodColumn: 'periodId',
337
+ },
338
+ ];
339
+ }
340
+ /**
341
+ * Copy the platform record and the configuration that lives in json on it into the dimension tables.
342
+ * Small enough to write on every run, and it has to happen before the tables pointing at it.
343
+ *
344
+ * The configuration holds one answer -- the name a tak, netwerk, lidgeldtype or functie carries
345
+ * today -- and no history at all, so that answer is written against every period still open. The
346
+ * frozen ones keep the answer they were counted with.
347
+ */
348
+ async function syncPlatformConfig(openPeriodIds) {
349
+ const platform = await Platform.getShared();
350
+ const config = platform.config;
351
+ const perPeriod = (items, flatten) => openPeriodIds.flatMap((periodId) => items.map((item) => flatten(item, periodId)));
352
+ // The platform record itself rather than its configuration, and therefore not per period: the
353
+ // reports read which organization it runs and what it calls its verlaagd lidgeld, and what they
354
+ // print of that organization comes from `organizations`, which is recorded per year like
355
+ // everything else.
356
+ await upsertRows('platform', ['id', 'name', 'membershipOrganizationId', 'reducedPriceName'], [flattenPlatform(platform)], ['id']);
357
+ await upsertRows('organization_tags', ['id', 'periodId', 'name'], perPeriod(config.tags, flattenNamedConfig), namedConfigKey);
358
+ await upsertRows('default_age_groups', ['id', 'periodId', 'name', 'minAge', 'maxAge'], perPeriod(config.defaultAgeGroups, (group, periodId) => flattenDefaultAgeGroup({ id: group.id, names: group.names, minAge: group.minAge, maxAge: group.maxAge }, periodId)), namedConfigKey);
359
+ await upsertRows('platform_membership_types', ['id', 'periodId', 'name'], perPeriod(config.membershipTypes, flattenNamedConfig), namedConfigKey);
360
+ await upsertRows('responsibilities', ['id', 'periodId', 'name'], perPeriod(config.responsibilities, flattenNamedConfig), namedConfigKey);
361
+ }
362
+ /** The periods the sync still writes into: everything the statistics database knows, minus the frozen ones. */
363
+ async function loadOpenPeriodIds(frozen) {
364
+ return [...(await loadIdSet('registration_periods'))].filter((id) => !frozen.has(id));
365
+ }
366
+ const namedConfigKey = ['id', 'periodId'];
367
+ /**
368
+ * The tags an organization carries and the responsibilities it defines itself. Both hang off the
369
+ * organization record, so they are written along with the batch of organizations they belong to
370
+ * rather than by scanning every organization again.
371
+ */
372
+ async function syncOrganizationTagsAndResponsibilities(organizations, frozen, openPeriodIds) {
373
+ if (organizations.length === 0) {
374
+ return;
375
+ }
376
+ const ownResponsibilities = organizations.flatMap((organization) => organization.privateMeta.responsibilities);
377
+ await upsertRows('responsibilities', ['id', 'periodId', 'name'], openPeriodIds.flatMap((periodId) => ownResponsibilities.map((responsibility) => flattenNamedConfig(responsibility, periodId))), namedConfigKey);
378
+ // The source only knows the tags an organization carries now, so they are recorded against the
379
+ // period it is in. A frozen period keeps the netwerk it was recorded with while it was live.
380
+ const knownPeriods = await loadIdSet('registration_periods');
381
+ const live = organizations.filter((organization) => knownPeriods.has(organization.periodId) && !isFrozen(frozen, organization.periodId));
382
+ if (live.length === 0) {
383
+ return;
384
+ }
385
+ const knownTags = await loadIdSet('organization_tags');
386
+ const connection = getStatisticsConnection();
387
+ // Replace the links of these organizations for the period they are in, leaving every other
388
+ // period exactly as it was recorded.
389
+ for (const [periodId, group] of groupByPeriod(live)) {
390
+ await connection.delete(`DELETE FROM ${connection.escapeId('_organizations_organization_tags')} WHERE \`organizationsId\` IN (?) AND \`periodId\` = ?`, [idsOf(group), periodId]);
391
+ }
392
+ const links = live.flatMap((organization) => organization.meta.tags
393
+ .filter((tagId) => knownTags.has(tagId))
394
+ .map((tagId) => ({
395
+ organizationsId: organization.id,
396
+ organizationTagsId: tagId,
397
+ periodId: organization.periodId,
398
+ })));
399
+ await upsertRows('_organizations_organization_tags', ['organizationsId', 'organizationTagsId', 'periodId', ...sourceColumns], withSource(links));
400
+ }
401
+ /**
402
+ * The years the sync still writes into, grouped by the unit holding them. Every unit keeps its own
403
+ * row per year; the platform's own years are the ones under no unit at all.
404
+ */
405
+ async function loadOpenPeriodsByOrganization(frozen) {
406
+ const connection = getStatisticsConnection();
407
+ const [rows] = await connection.select('SELECT `id`, `organizationId`, `startDate`, `endDate` FROM `registration_periods`', [], { nestTables: false });
408
+ const byOrganization = new Map();
409
+ for (const period of rows) {
410
+ if (frozen.has(period.id)) {
411
+ continue;
412
+ }
413
+ const periods = byOrganization.get(period.organizationId);
414
+ if (periods) {
415
+ periods.push(period);
416
+ }
417
+ else {
418
+ byOrganization.set(period.organizationId, [period]);
419
+ }
420
+ }
421
+ return byOrganization;
422
+ }
423
+ /**
424
+ * The years a record runs through: the ones of its own unit that its date range overlaps, or the
425
+ * platform's own when it belongs to no unit.
426
+ *
427
+ * A record with no end date runs until now rather than forever, so a functie someone still holds is
428
+ * not also recorded against the years that have not happened yet.
429
+ */
430
+ function periodIdsOfRecord(record, byOrganization, now) {
431
+ const periods = byOrganization.get(record.organizationId) ?? byOrganization.get(null) ?? [];
432
+ const runsUntil = record.endDate !== null && record.endDate < now ? record.endDate : now;
433
+ return periods
434
+ .filter((period) => period.startDate <= runsUntil && period.endDate >= record.startDate)
435
+ .map((period) => period.id);
436
+ }
437
+ /**
438
+ * Responsibility records carry no `updatedAt`, so there is no watermark to advance: they are written
439
+ * in full on every run. Records pointing at a responsibility that no longer exists are skipped.
440
+ */
441
+ async function syncResponsibilityRecords(knownResponsibilities, frozen) {
442
+ const columns = [
443
+ 'id',
444
+ 'periodId',
445
+ 'memberId',
446
+ 'groupId',
447
+ 'organizationId',
448
+ 'responsibilityId',
449
+ 'startDate',
450
+ 'endDate',
451
+ ];
452
+ const byOrganization = await loadOpenPeriodsByOrganization(frozen);
453
+ const connection = getStatisticsConnection();
454
+ const now = new Date();
455
+ let afterId = '';
456
+ for (;;) {
457
+ const records = (await MemberResponsibilityRecord.select()
458
+ .where(SQL.column('id'), SQLWhereSign.Greater, afterId)
459
+ .orderBy(SQL.column('id'), 'ASC')
460
+ .limit(fetchBatchSize)
461
+ .fetch());
462
+ if (records.length === 0) {
463
+ return;
464
+ }
465
+ // Which years a record runs through follows from its dates, so a record whose dates changed
466
+ // has to lose the years it no longer covers. Only outside the frozen ones: those are settled.
467
+ const ids = idsOf(records);
468
+ if (frozen.size > 0) {
469
+ await connection.delete('DELETE FROM `member_responsibility_records` WHERE `id` IN (?) AND `periodId` NOT IN (?)', [ids, [...frozen]]);
470
+ }
471
+ else {
472
+ await connection.delete('DELETE FROM `member_responsibility_records` WHERE `id` IN (?)', [ids]);
473
+ }
474
+ await upsertRows('member_responsibility_records', [...columns, ...sourceColumns], withSource(records
475
+ .filter((record) => knownResponsibilities.has(record.responsibilityId))
476
+ .flatMap((record) => periodIdsOfRecord(record, byOrganization, now).map((periodId) => flattenResponsibilityRecord(record, periodId)))), ['id', 'periodId']);
477
+ afterId = records[records.length - 1].id;
478
+ }
479
+ }
480
+ /**
481
+ * Of these statistics rows, the ones that do not belong to a frozen period. A deleted source row in a
482
+ * settled year stays exactly as it was counted.
483
+ */
484
+ async function withoutFrozen(table, ids, frozen, periodColumn) {
485
+ if (ids.length === 0 || frozen.size === 0) {
486
+ return ids;
487
+ }
488
+ const connection = getStatisticsConnection();
489
+ const column = connection.escapeId(periodColumn);
490
+ const [rows] = await connection.select(`SELECT \`id\` FROM ${connection.escapeId(table)} WHERE \`id\` IN (?) AND (${column} IS NULL OR ${column} NOT IN (?))`, [ids, [...frozen]], { nestTables: false });
491
+ return rows.map((row) => row.id);
492
+ }
493
+ async function syncIncrementalTable(definition, frozen) {
494
+ const startedAt = new Date();
495
+ const state = await readSyncState(definition.table);
496
+ const since = state.watermark ? new Date(state.watermark.getTime() - watermarkOverlap) : null;
497
+ const seen = [];
498
+ let afterId = '';
499
+ for (;;) {
500
+ const { rows, updatedAt, lastId } = await definition.fetch(since, afterId, fetchBatchSize);
501
+ if (lastId === afterId) {
502
+ break;
503
+ }
504
+ const live = definition.periodColumn
505
+ ? rows.filter((row) => !isFrozen(frozen, row[definition.periodColumn]))
506
+ : rows;
507
+ await upsertRows(definition.table, [...definition.columns, ...sourceColumns], withSource(live), definition.keyColumns);
508
+ seen.push(...updatedAt);
509
+ afterId = lastId;
510
+ }
511
+ await writeSyncState(definition.table, {
512
+ watermark: nextWatermark(state.watermark, seen, startedAt),
513
+ lastSucceededAt: new Date(),
514
+ });
515
+ }
516
+ function emptyKnownIds() {
517
+ return {
518
+ ageGroups: new Set(),
519
+ membershipTypes: new Set(),
520
+ responsibilities: new Set(),
521
+ };
522
+ }
523
+ /** The tables the delete reconciliation walks, which is every table it may take a row out of. */
524
+ export function reconciledTables() {
525
+ return [periodsTable(), ...buildIncrementalTables(emptyKnownIds(), new Set(), [])]
526
+ .filter((definition) => !definition.neverDelete)
527
+ .map((definition) => definition.table);
528
+ }
529
+ /**
530
+ * Bring the statistics database up to date with everything that changed since the last run.
531
+ *
532
+ * Written so a crash is harmless: every write is an upsert, and a table that throws keeps its old
533
+ * watermark, so the next run reads the same window again instead of skipping it.
534
+ */
535
+ export async function syncStatistics() {
536
+ await applyImportedCutoff(getImportedUntil());
537
+ // The periods before anything else, and the configuration before the rows that group by it: every
538
+ // table here is written per period, so a period that is not in yet is a period nothing can be
539
+ // written against.
540
+ //
541
+ // Only a settled year leaves its own row alone as well. A locked period keeps following the
542
+ // administration, because that row is where `locked` arrives: freezing it would freeze the one
543
+ // field an unlock has to come through.
544
+ await syncIncrementalTable(periodsTable(), await loadSettledPeriodIds());
545
+ // Also apply the cutoff for newly added rows
546
+ await applyImportedCutoff(getImportedUntil());
547
+ await releaseUnlockedPeriods();
548
+ const frozen = await loadFrozenPeriodIds();
549
+ const openPeriodIds = await loadOpenPeriodIds(frozen);
550
+ await syncPlatformConfig(openPeriodIds);
551
+ const known = {
552
+ ageGroups: await loadIdSet('default_age_groups'),
553
+ membershipTypes: await loadIdSet('platform_membership_types'),
554
+ responsibilities: await loadIdSet('responsibilities'),
555
+ };
556
+ for (const definition of buildIncrementalTables(known, frozen, openPeriodIds)) {
557
+ await syncIncrementalTable(definition, frozen);
558
+ }
559
+ await syncResponsibilityRecords(await loadIdSet('responsibilities'), frozen);
560
+ }
561
+ /**
562
+ * Remove statistics rows whose source row is gone. Deletes leave nothing behind to notice in an
563
+ * incremental pass, so they are reconciled separately by walking the statistics ids and asking the
564
+ * source which of them still exist.
565
+ */
566
+ export async function syncStatisticsDeletes() {
567
+ const frozen = await loadFrozenPeriodIds();
568
+ for (const definition of [
569
+ periodsTable(),
570
+ ...buildIncrementalTables(emptyKnownIds(), frozen, []),
571
+ ]) {
572
+ if (definition.neverDelete) {
573
+ continue;
574
+ }
575
+ for await (const ids of iterateIds(definition.table, syncSource)) {
576
+ const existing = await definition.existingIds(ids);
577
+ const missing = ids.filter((id) => !existing.has(id));
578
+ await deleteRows(definition.table, definition.periodColumn
579
+ ? await withoutFrozen(definition.table, missing, frozen, definition.periodColumn)
580
+ : missing);
581
+ }
582
+ await writeSyncState(definition.table, { lastReconciledAt: new Date() });
583
+ }
584
+ for await (const ids of iterateIds('member_responsibility_records', syncSource)) {
585
+ const existing = await existingModelIds(MemberResponsibilityRecord, ids);
586
+ await deleteRows('member_responsibility_records', ids.filter((id) => !existing.has(id)));
587
+ }
588
+ await writeSyncState('member_responsibility_records', { lastReconciledAt: new Date() });
589
+ }
590
+ /**
591
+ * One whole run of the sync: everything that changed, then the rows whose source is gone, then the
592
+ * periods the administration has locked since.
593
+ *
594
+ * The order is what makes each of the three sound, so they are run from here rather than from the
595
+ * cron that schedules them.
596
+ */
597
+ export async function runStatisticsCycle() {
598
+ await syncStatistics();
599
+ // After the incremental pass, never next to it: reconciling first would see a row the sync is
600
+ // about to write back and one that was deleted since the sync read it as equally present,
601
+ // leaving the deleted one behind for a full day.
602
+ await syncStatisticsDeletes();
603
+ // Last, and only when both passes came through: a locked period has had the changes and the
604
+ // deletions of the day it was locked written by now, so its numbers are final. A pass that threw
605
+ // never gets here, which leaves the period to be read again by the next run.
606
+ await settleLockedPeriods();
607
+ }
608
+ //# sourceMappingURL=sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/sync.ts"],"names":[],"mappings":"AACA,OAAO,EACH,KAAK,EACL,MAAM,EACN,wBAAwB,EACxB,0BAA0B,EAC1B,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,kBAAkB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EACH,mBAAmB,EACnB,gBAAgB,EAChB,QAAQ,EACR,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,GACtB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACH,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EAC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