@loomcore/api 0.1.91 → 0.1.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -201
- package/README.md +77 -77
- package/dist/__tests__/common-test.utils.js +0 -4
- package/dist/__tests__/postgres-test-migrations/postgres-test-schema.js +266 -266
- package/dist/__tests__/postgres.test-database.js +8 -8
- package/dist/config/base-api-config.d.ts +1 -1
- package/dist/config/base-api-config.js +12 -7
- package/dist/databases/migrations/migration-runner.d.ts +3 -5
- package/dist/databases/migrations/migration-runner.js +40 -44
- package/dist/databases/mongo-db/migrations/mongo-initial-schema.d.ts +2 -3
- package/dist/databases/mongo-db/migrations/mongo-initial-schema.js +102 -81
- package/dist/databases/mongo-db/utils/build-mongo-url.util.d.ts +4 -2
- package/dist/databases/mongo-db/utils/convert-operations-to-pipeline.util.js +141 -39
- package/dist/databases/postgres/commands/postgres-batch-update.command.js +7 -7
- package/dist/databases/postgres/commands/postgres-create-many.command.js +4 -4
- package/dist/databases/postgres/commands/postgres-create.command.js +4 -4
- package/dist/databases/postgres/commands/postgres-full-update-by-id.command.js +13 -13
- package/dist/databases/postgres/commands/postgres-partial-update-by-id.command.js +7 -7
- package/dist/databases/postgres/commands/postgres-update.command.js +7 -7
- package/dist/databases/postgres/migrations/__tests__/test-migration-helper.js +8 -1
- package/dist/databases/postgres/migrations/postgres-initial-schema.d.ts +2 -3
- package/dist/databases/postgres/migrations/postgres-initial-schema.js +263 -266
- package/dist/databases/postgres/postgres.database.js +17 -17
- package/dist/databases/postgres/utils/build-join-clauses.js +151 -151
- package/dist/databases/postgres/utils/build-postgres-url.util.d.ts +4 -2
- package/dist/databases/postgres/utils/build-select-clause.js +6 -6
- package/dist/databases/postgres/utils/does-table-exist.util.js +4 -4
- package/dist/models/app-config.interface.d.ts +8 -0
- package/dist/models/base-api-config.interface.d.ts +4 -17
- package/dist/models/database-config.interface.d.ts +7 -0
- package/dist/models/index.d.ts +3 -1
- package/dist/models/index.js +3 -1
- package/dist/models/initial-database-config.interface.d.ts +16 -0
- package/dist/models/initial-database-config.interface.js +1 -0
- package/package.json +92 -92
- package/dist/models/multi-tenant-config.interface.d.ts +0 -4
- package/dist/models/reset-api-config.interface.d.ts +0 -6
- /package/dist/models/{multi-tenant-config.interface.js → app-config.interface.js} +0 -0
- /package/dist/models/{reset-api-config.interface.js → database-config.interface.js} +0 -0
|
@@ -20,13 +20,6 @@ export function convertOperationsToPipeline(operations) {
|
|
|
20
20
|
const joinAliases = operations
|
|
21
21
|
.filter(op => op instanceof Join || op instanceof JoinMany || op instanceof JoinThrough || op instanceof JoinThroughMany)
|
|
22
22
|
.map(op => op.as);
|
|
23
|
-
if (joinAliases.length > 0) {
|
|
24
|
-
pipeline.push({
|
|
25
|
-
$set: {
|
|
26
|
-
_joinData: {}
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
23
|
operations.forEach(operation => {
|
|
31
24
|
if (operation instanceof Join) {
|
|
32
25
|
const needsObjectIdConversion = operation.foreignField === '_id';
|
|
@@ -63,7 +56,12 @@ export function convertOperationsToPipeline(operations) {
|
|
|
63
56
|
}
|
|
64
57
|
}, {
|
|
65
58
|
$addFields: {
|
|
66
|
-
|
|
59
|
+
_joinData: {
|
|
60
|
+
$mergeObjects: [
|
|
61
|
+
{ $ifNull: ['$_joinData', {}] },
|
|
62
|
+
{ [operation.as]: `$${operation.as}Arr` }
|
|
63
|
+
]
|
|
64
|
+
}
|
|
67
65
|
}
|
|
68
66
|
}, {
|
|
69
67
|
$project: {
|
|
@@ -86,7 +84,12 @@ export function convertOperationsToPipeline(operations) {
|
|
|
86
84
|
}
|
|
87
85
|
}, {
|
|
88
86
|
$addFields: {
|
|
89
|
-
|
|
87
|
+
_joinData: {
|
|
88
|
+
$mergeObjects: [
|
|
89
|
+
{ $ifNull: ['$_joinData', {}] },
|
|
90
|
+
{ [operation.as]: `$${operation.as}Arr` }
|
|
91
|
+
]
|
|
92
|
+
}
|
|
90
93
|
}
|
|
91
94
|
}, {
|
|
92
95
|
$project: {
|
|
@@ -99,11 +102,35 @@ export function convertOperationsToPipeline(operations) {
|
|
|
99
102
|
const parentJoin = processedOperations.find(op => (op instanceof Join || op instanceof JoinMany || op instanceof JoinThrough || op instanceof JoinThroughMany) && op.as === parentAlias);
|
|
100
103
|
if (parentJoin) {
|
|
101
104
|
pipeline.push({
|
|
102
|
-
$
|
|
103
|
-
|
|
105
|
+
$addFields: {
|
|
106
|
+
_joinData: {
|
|
104
107
|
$mergeObjects: [
|
|
105
|
-
{ $ifNull: [
|
|
106
|
-
{
|
|
108
|
+
{ $ifNull: ['$_joinData', {}] },
|
|
109
|
+
{
|
|
110
|
+
[parentAlias]: {
|
|
111
|
+
$mergeObjects: [
|
|
112
|
+
{
|
|
113
|
+
$ifNull: [
|
|
114
|
+
{
|
|
115
|
+
$getField: {
|
|
116
|
+
field: parentAlias,
|
|
117
|
+
input: { $ifNull: ['$_joinData', {}] }
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
{}
|
|
121
|
+
]
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
[operation.as]: {
|
|
125
|
+
$getField: {
|
|
126
|
+
field: operation.as,
|
|
127
|
+
input: { $ifNull: ['$_joinData', {}] }
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
}
|
|
107
134
|
]
|
|
108
135
|
}
|
|
109
136
|
}
|
|
@@ -144,7 +171,12 @@ export function convertOperationsToPipeline(operations) {
|
|
|
144
171
|
}
|
|
145
172
|
}, {
|
|
146
173
|
$addFields: {
|
|
147
|
-
|
|
174
|
+
_joinData: {
|
|
175
|
+
$mergeObjects: [
|
|
176
|
+
{ $ifNull: ['$_joinData', {}] },
|
|
177
|
+
{ [operation.as]: `$${operation.as}_temp` }
|
|
178
|
+
]
|
|
179
|
+
}
|
|
148
180
|
}
|
|
149
181
|
}, {
|
|
150
182
|
$project: {
|
|
@@ -156,11 +188,18 @@ export function convertOperationsToPipeline(operations) {
|
|
|
156
188
|
const parentJoin = processedOperations.find(op => (op instanceof Join || op instanceof JoinMany || op instanceof JoinThrough || op instanceof JoinThroughMany) && op.as === parentAlias);
|
|
157
189
|
if (parentJoin) {
|
|
158
190
|
pipeline.push({
|
|
159
|
-
$
|
|
160
|
-
|
|
191
|
+
$addFields: {
|
|
192
|
+
_joinData: {
|
|
161
193
|
$mergeObjects: [
|
|
162
|
-
{ $ifNull: [
|
|
163
|
-
{
|
|
194
|
+
{ $ifNull: ['$_joinData', {}] },
|
|
195
|
+
{
|
|
196
|
+
[parentAlias]: {
|
|
197
|
+
$mergeObjects: [
|
|
198
|
+
{ $ifNull: [`$_joinData.${parentAlias}`, {}] },
|
|
199
|
+
{ [operation.as]: `$_joinData.${operation.as}` }
|
|
200
|
+
]
|
|
201
|
+
}
|
|
202
|
+
}
|
|
164
203
|
]
|
|
165
204
|
}
|
|
166
205
|
}
|
|
@@ -181,7 +220,12 @@ export function convertOperationsToPipeline(operations) {
|
|
|
181
220
|
}
|
|
182
221
|
}, {
|
|
183
222
|
$addFields: {
|
|
184
|
-
|
|
223
|
+
_joinData: {
|
|
224
|
+
$mergeObjects: [
|
|
225
|
+
{ $ifNull: ['$_joinData', {}] },
|
|
226
|
+
{ [operation.as]: `$${operation.as}_temp` }
|
|
227
|
+
]
|
|
228
|
+
}
|
|
185
229
|
}
|
|
186
230
|
}, {
|
|
187
231
|
$project: {
|
|
@@ -272,7 +316,12 @@ export function convertOperationsToPipeline(operations) {
|
|
|
272
316
|
}
|
|
273
317
|
}, {
|
|
274
318
|
$addFields: {
|
|
275
|
-
|
|
319
|
+
_joinData: {
|
|
320
|
+
$mergeObjects: [
|
|
321
|
+
{ $ifNull: ['$_joinData', {}] },
|
|
322
|
+
{ [operation.as]: `$${operation.as}_temp` }
|
|
323
|
+
]
|
|
324
|
+
}
|
|
276
325
|
}
|
|
277
326
|
}, {
|
|
278
327
|
$project: {
|
|
@@ -285,11 +334,18 @@ export function convertOperationsToPipeline(operations) {
|
|
|
285
334
|
const parentJoin = processedOperations.find(op => (op instanceof Join || op instanceof JoinThrough) && op.as === parentAlias);
|
|
286
335
|
if (parentJoin) {
|
|
287
336
|
pipeline.push({
|
|
288
|
-
$
|
|
289
|
-
|
|
337
|
+
$addFields: {
|
|
338
|
+
_joinData: {
|
|
290
339
|
$mergeObjects: [
|
|
291
|
-
{ $ifNull: [
|
|
292
|
-
{
|
|
340
|
+
{ $ifNull: ['$_joinData', {}] },
|
|
341
|
+
{
|
|
342
|
+
[parentAlias]: {
|
|
343
|
+
$mergeObjects: [
|
|
344
|
+
{ $ifNull: [`$_joinData.${parentAlias}`, {}] },
|
|
345
|
+
{ [operation.as]: `$_joinData.${operation.as}` }
|
|
346
|
+
]
|
|
347
|
+
}
|
|
348
|
+
}
|
|
293
349
|
]
|
|
294
350
|
}
|
|
295
351
|
}
|
|
@@ -356,7 +412,12 @@ export function convertOperationsToPipeline(operations) {
|
|
|
356
412
|
}
|
|
357
413
|
}, {
|
|
358
414
|
$addFields: {
|
|
359
|
-
|
|
415
|
+
_joinData: {
|
|
416
|
+
$mergeObjects: [
|
|
417
|
+
{ $ifNull: ['$_joinData', {}] },
|
|
418
|
+
{ [operation.as]: `$${operation.as}_temp` }
|
|
419
|
+
]
|
|
420
|
+
}
|
|
360
421
|
}
|
|
361
422
|
}, {
|
|
362
423
|
$project: {
|
|
@@ -369,11 +430,18 @@ export function convertOperationsToPipeline(operations) {
|
|
|
369
430
|
const parentJoin = processedOperations.find(op => (op instanceof Join || op instanceof JoinThrough) && op.as === parentAlias);
|
|
370
431
|
if (parentJoin) {
|
|
371
432
|
pipeline.push({
|
|
372
|
-
$
|
|
373
|
-
|
|
433
|
+
$addFields: {
|
|
434
|
+
_joinData: {
|
|
374
435
|
$mergeObjects: [
|
|
375
|
-
{ $ifNull: [
|
|
376
|
-
{
|
|
436
|
+
{ $ifNull: ['$_joinData', {}] },
|
|
437
|
+
{
|
|
438
|
+
[parentAlias]: {
|
|
439
|
+
$mergeObjects: [
|
|
440
|
+
{ $ifNull: [`$_joinData.${parentAlias}`, {}] },
|
|
441
|
+
{ [operation.as]: `$_joinData.${operation.as}` }
|
|
442
|
+
]
|
|
443
|
+
}
|
|
444
|
+
}
|
|
377
445
|
]
|
|
378
446
|
}
|
|
379
447
|
}
|
|
@@ -468,7 +536,17 @@ export function convertOperationsToPipeline(operations) {
|
|
|
468
536
|
}, {
|
|
469
537
|
$replaceRoot: {
|
|
470
538
|
newRoot: {
|
|
471
|
-
$mergeObjects: [
|
|
539
|
+
$mergeObjects: [
|
|
540
|
+
'$root',
|
|
541
|
+
{
|
|
542
|
+
_joinData: {
|
|
543
|
+
$mergeObjects: [
|
|
544
|
+
{ $ifNull: ['$root._joinData', {}] },
|
|
545
|
+
{ [operation.as]: `$${operation.as}_temp_grouped` }
|
|
546
|
+
]
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
]
|
|
472
550
|
}
|
|
473
551
|
}
|
|
474
552
|
}, {
|
|
@@ -483,11 +561,18 @@ export function convertOperationsToPipeline(operations) {
|
|
|
483
561
|
const parentJoin = processedOperations.find(op => (op instanceof Join || op instanceof JoinThrough) && op.as === parentAlias);
|
|
484
562
|
if (parentJoin) {
|
|
485
563
|
pipeline.push({
|
|
486
|
-
$
|
|
487
|
-
|
|
564
|
+
$addFields: {
|
|
565
|
+
_joinData: {
|
|
488
566
|
$mergeObjects: [
|
|
489
|
-
{ $ifNull: [
|
|
490
|
-
{
|
|
567
|
+
{ $ifNull: ['$_joinData', {}] },
|
|
568
|
+
{
|
|
569
|
+
[parentAlias]: {
|
|
570
|
+
$mergeObjects: [
|
|
571
|
+
{ $ifNull: [`$_joinData.${parentAlias}`, {}] },
|
|
572
|
+
{ [operation.as]: `$_joinData.${operation.as}` }
|
|
573
|
+
]
|
|
574
|
+
}
|
|
575
|
+
}
|
|
491
576
|
]
|
|
492
577
|
}
|
|
493
578
|
}
|
|
@@ -555,7 +640,17 @@ export function convertOperationsToPipeline(operations) {
|
|
|
555
640
|
}, {
|
|
556
641
|
$replaceRoot: {
|
|
557
642
|
newRoot: {
|
|
558
|
-
$mergeObjects: [
|
|
643
|
+
$mergeObjects: [
|
|
644
|
+
'$root',
|
|
645
|
+
{
|
|
646
|
+
_joinData: {
|
|
647
|
+
$mergeObjects: [
|
|
648
|
+
{ $ifNull: ['$root._joinData', {}] },
|
|
649
|
+
{ [operation.as]: `$${operation.as}_temp_grouped` }
|
|
650
|
+
]
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
]
|
|
559
654
|
}
|
|
560
655
|
}
|
|
561
656
|
}, {
|
|
@@ -570,11 +665,18 @@ export function convertOperationsToPipeline(operations) {
|
|
|
570
665
|
const parentJoin = processedOperations.find(op => (op instanceof Join || op instanceof JoinThrough) && op.as === parentAlias);
|
|
571
666
|
if (parentJoin) {
|
|
572
667
|
pipeline.push({
|
|
573
|
-
$
|
|
574
|
-
|
|
668
|
+
$addFields: {
|
|
669
|
+
_joinData: {
|
|
575
670
|
$mergeObjects: [
|
|
576
|
-
{ $ifNull: [
|
|
577
|
-
{
|
|
671
|
+
{ $ifNull: ['$_joinData', {}] },
|
|
672
|
+
{
|
|
673
|
+
[parentAlias]: {
|
|
674
|
+
$mergeObjects: [
|
|
675
|
+
{ $ifNull: [`$_joinData.${parentAlias}`, {}] },
|
|
676
|
+
{ [operation.as]: `$_joinData.${operation.as}` }
|
|
677
|
+
]
|
|
678
|
+
}
|
|
679
|
+
}
|
|
578
680
|
]
|
|
579
681
|
}
|
|
580
682
|
}
|
|
@@ -31,10 +31,10 @@ export async function batchUpdate(client, entities, operations, queryObject, plu
|
|
|
31
31
|
const setClause = columns.map((col, index) => `${col} = $${index + 1}`).join(', ');
|
|
32
32
|
queryObject.filters._id = { eq: _id };
|
|
33
33
|
const { whereClause } = buildWhereClause(queryObject, values);
|
|
34
|
-
const query = `
|
|
35
|
-
UPDATE "${pluralResourceName}"
|
|
36
|
-
SET ${setClause}
|
|
37
|
-
${whereClause}
|
|
34
|
+
const query = `
|
|
35
|
+
UPDATE "${pluralResourceName}"
|
|
36
|
+
SET ${setClause}
|
|
37
|
+
${whereClause}
|
|
38
38
|
`;
|
|
39
39
|
await client.query(query, values);
|
|
40
40
|
}
|
|
@@ -47,9 +47,9 @@ export async function batchUpdate(client, entities, operations, queryObject, plu
|
|
|
47
47
|
const selectClause = hasJoins
|
|
48
48
|
? await buildSelectClause(client, pluralResourceName, pluralResourceName, operations)
|
|
49
49
|
: '*';
|
|
50
|
-
const selectQuery = `
|
|
51
|
-
SELECT ${selectClause} FROM "${pluralResourceName}" ${joinClauses}
|
|
52
|
-
${whereClause}
|
|
50
|
+
const selectQuery = `
|
|
51
|
+
SELECT ${selectClause} FROM "${pluralResourceName}" ${joinClauses}
|
|
52
|
+
${whereClause}
|
|
53
53
|
`;
|
|
54
54
|
const result = await client.query(selectQuery, values);
|
|
55
55
|
return hasJoins
|
|
@@ -33,10 +33,10 @@ export async function createMany(client, pluralResourceName, entities) {
|
|
|
33
33
|
valueClauses.push(`(${placeholders})`);
|
|
34
34
|
allValues.push(...values);
|
|
35
35
|
});
|
|
36
|
-
const query = `
|
|
37
|
-
INSERT INTO "${pluralResourceName}" (${columns.map(col => `"${col}"`).join(', ')})
|
|
38
|
-
VALUES ${valueClauses.join(', ')}
|
|
39
|
-
RETURNING *
|
|
36
|
+
const query = `
|
|
37
|
+
INSERT INTO "${pluralResourceName}" (${columns.map(col => `"${col}"`).join(', ')})
|
|
38
|
+
VALUES ${valueClauses.join(', ')}
|
|
39
|
+
RETURNING *
|
|
40
40
|
`;
|
|
41
41
|
const result = await client.query(query, allValues);
|
|
42
42
|
if (result.rows.length !== entities.length) {
|
|
@@ -5,10 +5,10 @@ export async function create(client, pluralResourceName, entity) {
|
|
|
5
5
|
delete entity._id;
|
|
6
6
|
const { columns, values } = columnsAndValuesFromEntity(entity);
|
|
7
7
|
const placeholders = columns.map((_, index) => `$${index + 1}`).join(', ');
|
|
8
|
-
const query = `
|
|
9
|
-
INSERT INTO "${pluralResourceName}" (${columns.join(', ')})
|
|
10
|
-
VALUES (${placeholders})
|
|
11
|
-
RETURNING *
|
|
8
|
+
const query = `
|
|
9
|
+
INSERT INTO "${pluralResourceName}" (${columns.join(', ')})
|
|
10
|
+
VALUES (${placeholders})
|
|
11
|
+
RETURNING *
|
|
12
12
|
`;
|
|
13
13
|
const result = await client.query(query, values);
|
|
14
14
|
if (result.rows.length === 0) {
|
|
@@ -2,12 +2,12 @@ import { BadRequestError, IdNotFoundError } from "../../../errors/index.js";
|
|
|
2
2
|
import { buildJoinClauses } from '../utils/build-join-clauses.js';
|
|
3
3
|
export async function fullUpdateById(client, operations, id, entity, pluralResourceName) {
|
|
4
4
|
try {
|
|
5
|
-
const tableColumns = await client.query(`
|
|
6
|
-
SELECT column_name, column_default
|
|
7
|
-
FROM information_schema.columns
|
|
8
|
-
WHERE table_schema = current_schema()
|
|
9
|
-
AND table_name = $1
|
|
10
|
-
ORDER BY ordinal_position
|
|
5
|
+
const tableColumns = await client.query(`
|
|
6
|
+
SELECT column_name, column_default
|
|
7
|
+
FROM information_schema.columns
|
|
8
|
+
WHERE table_schema = current_schema()
|
|
9
|
+
AND table_name = $1
|
|
10
|
+
ORDER BY ordinal_position
|
|
11
11
|
`, [pluralResourceName]);
|
|
12
12
|
if (tableColumns.rows.length === 0) {
|
|
13
13
|
throw new BadRequestError(`Unable to resolve columns for ${pluralResourceName}`);
|
|
@@ -40,19 +40,19 @@ export async function fullUpdateById(client, operations, id, entity, pluralResou
|
|
|
40
40
|
throw new BadRequestError('Cannot perform full update with no fields to update');
|
|
41
41
|
}
|
|
42
42
|
const setClause = updateColumns.join(', ');
|
|
43
|
-
const query = `
|
|
44
|
-
UPDATE "${pluralResourceName}"
|
|
45
|
-
SET ${setClause}
|
|
46
|
-
WHERE "_id" = $${paramIndex}
|
|
43
|
+
const query = `
|
|
44
|
+
UPDATE "${pluralResourceName}"
|
|
45
|
+
SET ${setClause}
|
|
46
|
+
WHERE "_id" = $${paramIndex}
|
|
47
47
|
`;
|
|
48
48
|
const result = await client.query(query, [...updateValues, id]);
|
|
49
49
|
if (result.rowCount === 0) {
|
|
50
50
|
throw new IdNotFoundError();
|
|
51
51
|
}
|
|
52
52
|
const joinClauses = buildJoinClauses(operations);
|
|
53
|
-
const selectQuery = `
|
|
54
|
-
SELECT * FROM "${pluralResourceName}" ${joinClauses}
|
|
55
|
-
WHERE "_id" = $1 LIMIT 1
|
|
53
|
+
const selectQuery = `
|
|
54
|
+
SELECT * FROM "${pluralResourceName}" ${joinClauses}
|
|
55
|
+
WHERE "_id" = $1 LIMIT 1
|
|
56
56
|
`;
|
|
57
57
|
const selectResult = await client.query(selectQuery, [id]);
|
|
58
58
|
if (selectResult.rows.length === 0) {
|
|
@@ -10,19 +10,19 @@ export async function partialUpdateById(client, operations, id, entity, pluralRe
|
|
|
10
10
|
throw new BadRequestError('Cannot perform partial update with no fields to update');
|
|
11
11
|
}
|
|
12
12
|
const setClause = updateColumns.map((col, index) => `${col} = $${index + 1}`).join(', ');
|
|
13
|
-
const query = `
|
|
14
|
-
UPDATE "${pluralResourceName}"
|
|
15
|
-
SET ${setClause}
|
|
16
|
-
WHERE "_id" = $${updateValues.length + 1}
|
|
13
|
+
const query = `
|
|
14
|
+
UPDATE "${pluralResourceName}"
|
|
15
|
+
SET ${setClause}
|
|
16
|
+
WHERE "_id" = $${updateValues.length + 1}
|
|
17
17
|
`;
|
|
18
18
|
const result = await client.query(query, [...updateValues, id]);
|
|
19
19
|
if (result.rowCount === 0) {
|
|
20
20
|
throw new IdNotFoundError();
|
|
21
21
|
}
|
|
22
22
|
const joinClauses = buildJoinClauses(operations);
|
|
23
|
-
const selectQuery = `
|
|
24
|
-
SELECT * FROM "${pluralResourceName}" ${joinClauses}
|
|
25
|
-
WHERE "_id" = $1 LIMIT 1
|
|
23
|
+
const selectQuery = `
|
|
24
|
+
SELECT * FROM "${pluralResourceName}" ${joinClauses}
|
|
25
|
+
WHERE "_id" = $1 LIMIT 1
|
|
26
26
|
`;
|
|
27
27
|
const selectResult = await client.query(selectQuery, [id]);
|
|
28
28
|
if (selectResult.rows.length === 0) {
|
|
@@ -17,10 +17,10 @@ export async function update(client, queryObject, entity, operations, pluralReso
|
|
|
17
17
|
const originalIndex = parseInt(num, 10);
|
|
18
18
|
return `$${originalIndex + updateValues.length}`;
|
|
19
19
|
});
|
|
20
|
-
const updateQuery = `
|
|
21
|
-
UPDATE "${pluralResourceName}"
|
|
22
|
-
SET ${setClause}
|
|
23
|
-
${whereClauseWithAdjustedParams}
|
|
20
|
+
const updateQuery = `
|
|
21
|
+
UPDATE "${pluralResourceName}"
|
|
22
|
+
SET ${setClause}
|
|
23
|
+
${whereClauseWithAdjustedParams}
|
|
24
24
|
`;
|
|
25
25
|
const allUpdateValues = [...updateValues, ...whereValues];
|
|
26
26
|
const result = await client.query(updateQuery, allUpdateValues);
|
|
@@ -29,9 +29,9 @@ export async function update(client, queryObject, entity, operations, pluralReso
|
|
|
29
29
|
}
|
|
30
30
|
const joinClauses = buildJoinClauses(operations);
|
|
31
31
|
const orderByClause = buildOrderByClause(queryObject);
|
|
32
|
-
const selectQuery = `
|
|
33
|
-
SELECT * FROM "${pluralResourceName}" ${joinClauses}
|
|
34
|
-
${whereClause} ${orderByClause}
|
|
32
|
+
const selectQuery = `
|
|
33
|
+
SELECT * FROM "${pluralResourceName}" ${joinClauses}
|
|
34
|
+
${whereClause} ${orderByClause}
|
|
35
35
|
`.trim();
|
|
36
36
|
const selectResult = await client.query(selectQuery, whereValues);
|
|
37
37
|
return selectResult.rows;
|
|
@@ -2,7 +2,14 @@ import { Umzug } from 'umzug';
|
|
|
2
2
|
import { getPostgresInitialSchema } from '../postgres-initial-schema.js';
|
|
3
3
|
import { getPostgresTestSchema } from '../../../../__tests__/postgres-test-migrations/postgres-test-schema.js';
|
|
4
4
|
export async function runInitialSchemaMigrations(pool, config) {
|
|
5
|
-
const
|
|
5
|
+
const migrationConfig = {
|
|
6
|
+
app: config.app,
|
|
7
|
+
database: config.database,
|
|
8
|
+
adminUser: config.adminUser ?? { email: 'admin@test.com', password: 'admin-password' },
|
|
9
|
+
multiTenant: config.multiTenant ?? (config.app.isMultiTenant ? { metaOrgName: 'Test Meta Organization', metaOrgCode: 'TEST_META_ORG' } : { metaOrgName: '', metaOrgCode: '' }),
|
|
10
|
+
email: config.email,
|
|
11
|
+
};
|
|
12
|
+
const initialSchema = getPostgresInitialSchema(migrationConfig);
|
|
6
13
|
const umzug = new Umzug({
|
|
7
14
|
migrations: async () => {
|
|
8
15
|
return initialSchema.map(m => ({
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Pool } from 'pg';
|
|
2
|
-
import {
|
|
3
|
-
import { IResetApiConfig } from '../../../models/reset-api-config.interface.js';
|
|
2
|
+
import { IInitialDbMigrationConfig } from '../../../models/initial-database-config.interface.js';
|
|
4
3
|
export interface SyntheticMigration {
|
|
5
4
|
name: string;
|
|
6
5
|
up: (context: {
|
|
@@ -10,4 +9,4 @@ export interface SyntheticMigration {
|
|
|
10
9
|
context: Pool;
|
|
11
10
|
}) => Promise<void>;
|
|
12
11
|
}
|
|
13
|
-
export declare const getPostgresInitialSchema: (
|
|
12
|
+
export declare const getPostgresInitialSchema: (dbConfig: IInitialDbMigrationConfig) => SyntheticMigration[];
|