sonamu 0.4.9 → 0.4.11
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/{base-model-C24du9JT.d.ts → base-model-Br6krkwK.d.ts} +1 -1
- package/dist/{base-model-IZdmwmB5.d.mts → base-model-BvVra-8f.d.mts} +1 -1
- package/dist/bin/cli.js +51 -51
- package/dist/bin/cli.mjs +2 -2
- package/dist/{chunk-OTL37JQ4.mjs → chunk-634GIW42.mjs} +10 -8
- package/dist/chunk-634GIW42.mjs.map +1 -0
- package/dist/{chunk-AK547YMV.mjs → chunk-A2BDNO7E.mjs} +2 -2
- package/dist/{chunk-LD7OHPVK.js → chunk-GUKIIOZI.js} +108 -106
- package/dist/chunk-GUKIIOZI.js.map +1 -0
- package/dist/{chunk-IV7ZWWBN.mjs → chunk-GUV6I64Y.mjs} +69 -40
- package/dist/chunk-GUV6I64Y.mjs.map +1 -0
- package/dist/{chunk-2VEHSKNA.js → chunk-KX4762I3.js} +69 -40
- package/dist/chunk-KX4762I3.js.map +1 -0
- package/dist/{chunk-L3RJSG2K.mjs → chunk-PGPMEMK6.mjs} +2 -2
- package/dist/{chunk-IDNBP4MH.js → chunk-QIHV5UYF.js} +4 -4
- package/dist/{chunk-GHF56FO6.js → chunk-Z53BUBO4.js} +7 -7
- package/dist/database/drivers/knex/base-model.d.mts +2 -2
- package/dist/database/drivers/knex/base-model.d.ts +2 -2
- package/dist/database/drivers/knex/base-model.js +8 -8
- package/dist/database/drivers/knex/base-model.mjs +3 -3
- package/dist/database/drivers/kysely/base-model.d.mts +2 -2
- package/dist/database/drivers/kysely/base-model.d.ts +2 -2
- package/dist/database/drivers/kysely/base-model.js +9 -9
- package/dist/database/drivers/kysely/base-model.mjs +3 -3
- package/dist/index.d.mts +13 -5
- package/dist/index.d.ts +13 -5
- package/dist/index.js +19 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -3
- package/dist/index.mjs.map +1 -1
- package/dist/{model-Dbbfpk2X.d.ts → model-DWoinpJ7.d.mts} +79 -9
- package/dist/{model-Dbbfpk2X.d.mts → model-DWoinpJ7.d.ts} +79 -9
- package/package.json +1 -1
- package/src/api/base-frame.ts +14 -0
- package/src/api/decorators.ts +2 -1
- package/src/entity/entity-utils.ts +1 -0
- package/src/entity/migrator.ts +8 -6
- package/src/index.ts +1 -0
- package/src/syncer/syncer.ts +76 -39
- package/src/templates/service.template.ts +4 -6
- package/src/types/types.ts +19 -7
- package/dist/chunk-2VEHSKNA.js.map +0 -1
- package/dist/chunk-IV7ZWWBN.mjs.map +0 -1
- package/dist/chunk-LD7OHPVK.js.map +0 -1
- package/dist/chunk-OTL37JQ4.mjs.map +0 -1
- /package/dist/{chunk-AK547YMV.mjs.map → chunk-A2BDNO7E.mjs.map} +0 -0
- /package/dist/{chunk-L3RJSG2K.mjs.map → chunk-PGPMEMK6.mjs.map} +0 -0
- /package/dist/{chunk-IDNBP4MH.js.map → chunk-QIHV5UYF.js.map} +0 -0
- /package/dist/{chunk-GHF56FO6.js.map → chunk-Z53BUBO4.js.map} +0 -0
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
var
|
|
19
|
+
var _chunkKX4762I3js = require('./chunk-KX4762I3.js');
|
|
20
20
|
|
|
21
21
|
// src/entity/migrator.ts
|
|
22
22
|
var _lodash = require('lodash'); var _lodash2 = _interopRequireDefault(_lodash);
|
|
@@ -34,10 +34,10 @@ var Migrator = class {
|
|
|
34
34
|
constructor(options) {
|
|
35
35
|
this.mode = options.mode;
|
|
36
36
|
if (this.mode === "dev") {
|
|
37
|
-
const devDB =
|
|
38
|
-
const testDB =
|
|
39
|
-
const fixtureLocalDB =
|
|
40
|
-
const uniqConfigs =
|
|
37
|
+
const devDB = _chunkKX4762I3js.DB.getClient("development_master");
|
|
38
|
+
const testDB = _chunkKX4762I3js.DB.getClient("test");
|
|
39
|
+
const fixtureLocalDB = _chunkKX4762I3js.DB.getClient("fixture_local");
|
|
40
|
+
const uniqConfigs = _chunkKX4762I3js.DB.getUniqueConfigs([
|
|
41
41
|
"development_master",
|
|
42
42
|
"test",
|
|
43
43
|
"fixture_local",
|
|
@@ -45,7 +45,7 @@ var Migrator = class {
|
|
|
45
45
|
]);
|
|
46
46
|
const applyDBs = [devDB, testDB, fixtureLocalDB];
|
|
47
47
|
if (uniqConfigs.length === 4) {
|
|
48
|
-
const fixtureRemoteDB =
|
|
48
|
+
const fixtureRemoteDB = _chunkKX4762I3js.DB.getClient("fixture_remote");
|
|
49
49
|
applyDBs.push(fixtureRemoteDB);
|
|
50
50
|
}
|
|
51
51
|
this.targets = {
|
|
@@ -55,8 +55,8 @@ var Migrator = class {
|
|
|
55
55
|
apply: applyDBs
|
|
56
56
|
};
|
|
57
57
|
} else if (this.mode === "deploy") {
|
|
58
|
-
const productionDB =
|
|
59
|
-
const testDB =
|
|
58
|
+
const productionDB = _chunkKX4762I3js.DB.getClient("production_master");
|
|
59
|
+
const testDB = _chunkKX4762I3js.DB.getClient("test");
|
|
60
60
|
this.targets = {
|
|
61
61
|
pending: productionDB,
|
|
62
62
|
shadow: testDB,
|
|
@@ -67,8 +67,8 @@ var Migrator = class {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
async getMigrationCodes() {
|
|
70
|
-
const srcMigrationsDir = `${
|
|
71
|
-
const distMigrationsDir = `${
|
|
70
|
+
const srcMigrationsDir = `${_chunkKX4762I3js.Sonamu.apiRootPath}/src/migrations`;
|
|
71
|
+
const distMigrationsDir = `${_chunkKX4762I3js.Sonamu.apiRootPath}/dist/migrations`;
|
|
72
72
|
if (_fsextra2.default.existsSync(srcMigrationsDir) === false) {
|
|
73
73
|
_fsextra2.default.mkdirSync(srcMigrationsDir, {
|
|
74
74
|
recursive: true
|
|
@@ -113,7 +113,7 @@ var Migrator = class {
|
|
|
113
113
|
const { normal, onlyTs, onlyJs } = await this.getMigrationCodes();
|
|
114
114
|
if (onlyTs.length > 0) {
|
|
115
115
|
console.debug({ onlyTs });
|
|
116
|
-
throw new (0,
|
|
116
|
+
throw new (0, _chunkKX4762I3js.ServiceUnavailableException)(
|
|
117
117
|
`There are un-compiled TS migration files.
|
|
118
118
|
Please compile them first.
|
|
119
119
|
|
|
@@ -130,12 +130,12 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
130
130
|
})
|
|
131
131
|
);
|
|
132
132
|
}
|
|
133
|
-
const connKeys = Object.keys(
|
|
133
|
+
const connKeys = Object.keys(_chunkKX4762I3js.DB.fullConfig).filter(
|
|
134
134
|
(key) => key.endsWith("_slave") === false
|
|
135
135
|
);
|
|
136
136
|
const statuses = await Promise.all(
|
|
137
137
|
connKeys.map(async (connKey) => {
|
|
138
|
-
const tConn =
|
|
138
|
+
const tConn = _chunkKX4762I3js.DB.getClient(connKey);
|
|
139
139
|
const status = await (async () => {
|
|
140
140
|
try {
|
|
141
141
|
return await tConn.status();
|
|
@@ -172,7 +172,7 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
172
172
|
if (status0conn === void 0) {
|
|
173
173
|
return [];
|
|
174
174
|
}
|
|
175
|
-
const compareDBconn =
|
|
175
|
+
const compareDBconn = _chunkKX4762I3js.DB.getClient(status0conn.connKey);
|
|
176
176
|
const genCodes = await this.compareMigrations(compareDBconn);
|
|
177
177
|
await compareDBconn.destroy();
|
|
178
178
|
return genCodes;
|
|
@@ -184,11 +184,11 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
184
184
|
};
|
|
185
185
|
}
|
|
186
186
|
async runAction(action, targets) {
|
|
187
|
-
const configs =
|
|
187
|
+
const configs = _chunkKX4762I3js.DB.getUniqueConfigs(targets);
|
|
188
188
|
const conns = await Promise.all(
|
|
189
189
|
configs.map(async (config) => ({
|
|
190
190
|
connKey: config.connKey,
|
|
191
|
-
db:
|
|
191
|
+
db: _chunkKX4762I3js.DB.getClient(config.connKey)
|
|
192
192
|
}))
|
|
193
193
|
);
|
|
194
194
|
const result = await (async () => {
|
|
@@ -236,8 +236,8 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
236
236
|
);
|
|
237
237
|
}
|
|
238
238
|
const delFiles = codeNames.map((codeName) => [
|
|
239
|
-
`${
|
|
240
|
-
`${
|
|
239
|
+
`${_chunkKX4762I3js.Sonamu.apiRootPath}/src/migrations/${codeName}.ts`,
|
|
240
|
+
`${_chunkKX4762I3js.Sonamu.apiRootPath}/dist/migrations/${codeName}.js`
|
|
241
241
|
]).flat();
|
|
242
242
|
const res = await Promise.all(
|
|
243
243
|
delFiles.map((delFile) => {
|
|
@@ -257,7 +257,7 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
257
257
|
console.log(_chalk2.default.green("\n\uD604\uC7AC \uBAA8\uB450 \uC2F1\uD06C\uB41C \uC0C1\uD0DC\uC785\uB2C8\uB2E4."));
|
|
258
258
|
return 0;
|
|
259
259
|
}
|
|
260
|
-
const migrationsDir = `${
|
|
260
|
+
const migrationsDir = `${_chunkKX4762I3js.Sonamu.apiRootPath}/src/migrations`;
|
|
261
261
|
preparedCodes.filter((pcode) => pcode.formatted).map((pcode, index) => {
|
|
262
262
|
const dateTag = _luxon.DateTime.local().plus({ seconds: index }).toFormat("yyyyMMddHHmmss");
|
|
263
263
|
const filePath = `${migrationsDir}/${dateTag}_${pcode.title}.ts`;
|
|
@@ -268,7 +268,7 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
268
268
|
}
|
|
269
269
|
async clearPendingList() {
|
|
270
270
|
const pendingList = await this.targets.pending.getMigrations();
|
|
271
|
-
const migrationsDir = `${
|
|
271
|
+
const migrationsDir = `${_chunkKX4762I3js.Sonamu.apiRootPath}/src/migrations`;
|
|
272
272
|
const delList = pendingList.map((df) => {
|
|
273
273
|
return _path2.default.join(migrationsDir, `${df}.ts`);
|
|
274
274
|
});
|
|
@@ -332,7 +332,7 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
332
332
|
if (answer.value === false) {
|
|
333
333
|
return;
|
|
334
334
|
}
|
|
335
|
-
const migrationsDir = `${
|
|
335
|
+
const migrationsDir = `${_chunkKX4762I3js.Sonamu.apiRootPath}/src/migrations`;
|
|
336
336
|
codes.filter((code) => code.formatted).map((code, index) => {
|
|
337
337
|
const dateTag = _luxon.DateTime.local().plus({ seconds: index }).toFormat("yyyyMMddHHmmss");
|
|
338
338
|
const filePath = `${migrationsDir}/${dateTag}_${code.title}.ts`;
|
|
@@ -354,7 +354,7 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
354
354
|
const files = ["src", "dist"].reduce(
|
|
355
355
|
(r, which) => {
|
|
356
356
|
const migrationPath = _path2.default.join(
|
|
357
|
-
|
|
357
|
+
_chunkKX4762I3js.Sonamu.apiRootPath,
|
|
358
358
|
which,
|
|
359
359
|
"migrations"
|
|
360
360
|
);
|
|
@@ -402,7 +402,7 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
404
|
const filesToRm = diffOnDist.map((filename) => {
|
|
405
|
-
return _path2.default.join(
|
|
405
|
+
return _path2.default.join(_chunkKX4762I3js.Sonamu.apiRootPath, "dist", "migrations", filename);
|
|
406
406
|
});
|
|
407
407
|
filesToRm.map((filePath) => {
|
|
408
408
|
_fsextra2.default.unlinkSync(filePath);
|
|
@@ -411,7 +411,7 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
411
411
|
}
|
|
412
412
|
}
|
|
413
413
|
async runShadowTest() {
|
|
414
|
-
const tdb =
|
|
414
|
+
const tdb = _chunkKX4762I3js.DB.getClient("test");
|
|
415
415
|
const tdbConn = tdb.connectionInfo;
|
|
416
416
|
const shadowDatabase = tdbConn.database + "__migration_shadow";
|
|
417
417
|
const tmpSqlPath = `/tmp/${shadowDatabase}.sql`;
|
|
@@ -449,7 +449,7 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
449
449
|
];
|
|
450
450
|
} catch (e) {
|
|
451
451
|
console.error(e);
|
|
452
|
-
throw new (0,
|
|
452
|
+
throw new (0, _chunkKX4762I3js.ServiceUnavailableException)("Shadow DB \uD14C\uC2A4\uD2B8 \uC9C4\uD589 \uC911 \uC5D0\uB7EC");
|
|
453
453
|
} finally {
|
|
454
454
|
await tdb.destroy();
|
|
455
455
|
}
|
|
@@ -472,19 +472,19 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
472
472
|
);
|
|
473
473
|
console.log({ rollbackAllResult });
|
|
474
474
|
console.timeEnd(_chalk2.default.red("rollback-all:"));
|
|
475
|
-
const migrationsDir = `${
|
|
475
|
+
const migrationsDir = `${_chunkKX4762I3js.Sonamu.apiRootPath}/src/migrations`;
|
|
476
476
|
console.time(_chalk2.default.red("delete migration files"));
|
|
477
477
|
_child_process.execSync.call(void 0, `rm -f ${migrationsDir}/*`);
|
|
478
478
|
_child_process.execSync.call(void 0, `rm -f ${migrationsDir.replace("/src/", "/dist/")}/*`);
|
|
479
479
|
console.timeEnd(_chalk2.default.red("delete migration files"));
|
|
480
480
|
}
|
|
481
481
|
async compareMigrations(compareDB) {
|
|
482
|
-
const entityIds =
|
|
482
|
+
const entityIds = _chunkKX4762I3js.EntityManager.getAllIds();
|
|
483
483
|
const entitySetsWithJoinTable = entityIds.filter((entityId) => {
|
|
484
|
-
const entity =
|
|
484
|
+
const entity = _chunkKX4762I3js.EntityManager.get(entityId);
|
|
485
485
|
return entity.props.length > 0;
|
|
486
486
|
}).map((entityId) => {
|
|
487
|
-
const entity =
|
|
487
|
+
const entity = _chunkKX4762I3js.EntityManager.get(entityId);
|
|
488
488
|
return this.getMigrationSetFromEntity(entity);
|
|
489
489
|
});
|
|
490
490
|
const joinTablesWithDup = entitySetsWithJoinTable.map((entitySet) => entitySet.joinTables).flat();
|
|
@@ -514,12 +514,12 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
514
514
|
);
|
|
515
515
|
if (dbSet === null) {
|
|
516
516
|
return [
|
|
517
|
-
await
|
|
517
|
+
await _chunkKX4762I3js.DB.generator.generateCreateCode_ColumnAndIndexes(
|
|
518
518
|
entitySet.table,
|
|
519
519
|
entitySet.columns,
|
|
520
520
|
entitySet.indexes
|
|
521
521
|
),
|
|
522
|
-
...await
|
|
522
|
+
...await _chunkKX4762I3js.DB.generator.generateCreateCode_Foreign(
|
|
523
523
|
entitySet.table,
|
|
524
524
|
entitySet.foreigns
|
|
525
525
|
)
|
|
@@ -565,7 +565,7 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
565
565
|
if (isEqualColumns && isEqualIndexes) {
|
|
566
566
|
return null;
|
|
567
567
|
} else {
|
|
568
|
-
return
|
|
568
|
+
return _chunkKX4762I3js.DB.generator.generateAlterCode_ColumnAndIndexes(
|
|
569
569
|
entitySet.table,
|
|
570
570
|
entityColumns,
|
|
571
571
|
entityIndexes,
|
|
@@ -591,7 +591,7 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
591
591
|
(a) => [a.to, ...a.columns].join("-")
|
|
592
592
|
).map((f) => replaceNoActionOnMySQL(f));
|
|
593
593
|
if (_fastdeepequal2.default.call(void 0, entityForeigns, dbForeigns) === false) {
|
|
594
|
-
return
|
|
594
|
+
return _chunkKX4762I3js.DB.generator.generateAlterCode_Foreigns(
|
|
595
595
|
entitySet.table,
|
|
596
596
|
entityForeigns,
|
|
597
597
|
dbForeigns
|
|
@@ -630,7 +630,7 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
630
630
|
table
|
|
631
631
|
);
|
|
632
632
|
} catch (e) {
|
|
633
|
-
if (
|
|
633
|
+
if (_chunkKX4762I3js.isKnexError.call(void 0, e) && e.code === "ER_NO_SUCH_TABLE") {
|
|
634
634
|
return null;
|
|
635
635
|
}
|
|
636
636
|
console.error(e);
|
|
@@ -807,17 +807,17 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
807
807
|
getMigrationSetFromEntity(entity) {
|
|
808
808
|
const migrationSet = entity.props.reduce(
|
|
809
809
|
(r, prop) => {
|
|
810
|
-
if (
|
|
810
|
+
if (_chunkKX4762I3js.isVirtualProp.call(void 0, prop)) {
|
|
811
811
|
return r;
|
|
812
812
|
}
|
|
813
|
-
if (
|
|
813
|
+
if (_chunkKX4762I3js.isHasManyRelationProp.call(void 0, prop)) {
|
|
814
814
|
return r;
|
|
815
815
|
}
|
|
816
|
-
if (!
|
|
816
|
+
if (!_chunkKX4762I3js.isRelationProp.call(void 0, prop)) {
|
|
817
817
|
let type;
|
|
818
|
-
if (
|
|
818
|
+
if (_chunkKX4762I3js.isTextProp.call(void 0, prop)) {
|
|
819
819
|
type = prop.textType;
|
|
820
|
-
} else if (
|
|
820
|
+
} else if (_chunkKX4762I3js.isEnumProp.call(void 0, prop)) {
|
|
821
821
|
type = "string";
|
|
822
822
|
} else {
|
|
823
823
|
type = prop.type;
|
|
@@ -825,8 +825,8 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
825
825
|
const column = {
|
|
826
826
|
name: prop.name,
|
|
827
827
|
type,
|
|
828
|
-
...
|
|
829
|
-
...(
|
|
828
|
+
..._chunkKX4762I3js.isIntegerProp.call(void 0, prop) && { unsigned: prop.unsigned === true },
|
|
829
|
+
...(_chunkKX4762I3js.isStringProp.call(void 0, prop) || _chunkKX4762I3js.isEnumProp.call(void 0, prop)) && {
|
|
830
830
|
length: prop.length
|
|
831
831
|
},
|
|
832
832
|
nullable: prop.nullable === true,
|
|
@@ -840,15 +840,15 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
840
840
|
})(),
|
|
841
841
|
// FIXME: float(N, M) deprecated
|
|
842
842
|
// Decimal, Float 타입의 경우 precision, scale 추가
|
|
843
|
-
...(
|
|
843
|
+
...(_chunkKX4762I3js.isDecimalProp.call(void 0, prop) || _chunkKX4762I3js.isFloatProp.call(void 0, prop)) && {
|
|
844
844
|
precision: _nullishCoalesce(prop.precision, () => ( 8)),
|
|
845
845
|
scale: _nullishCoalesce(prop.scale, () => ( 2))
|
|
846
846
|
}
|
|
847
847
|
};
|
|
848
848
|
r.columns.push(column);
|
|
849
849
|
}
|
|
850
|
-
if (
|
|
851
|
-
const relMd =
|
|
850
|
+
if (_chunkKX4762I3js.isManyToManyRelationProp.call(void 0, prop)) {
|
|
851
|
+
const relMd = _chunkKX4762I3js.EntityManager.get(prop.with);
|
|
852
852
|
const [table1, table2] = prop.joinTable.split("__");
|
|
853
853
|
const join = {
|
|
854
854
|
from: `${entity.table}.id`,
|
|
@@ -920,7 +920,7 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
920
920
|
})
|
|
921
921
|
});
|
|
922
922
|
return r;
|
|
923
|
-
} else if (
|
|
923
|
+
} else if (_chunkKX4762I3js.isBelongsToOneRelationProp.call(void 0, prop) || _chunkKX4762I3js.isOneToOneRelationProp.call(void 0, prop) && prop.hasJoinColumn) {
|
|
924
924
|
const idColumnName = prop.name + "_id";
|
|
925
925
|
r.columns.push({
|
|
926
926
|
name: idColumnName,
|
|
@@ -928,12 +928,14 @@ ${onlyTs.map((f) => f.name).join("\n")}`
|
|
|
928
928
|
unsigned: true,
|
|
929
929
|
nullable: _nullishCoalesce(prop.nullable, () => ( false))
|
|
930
930
|
});
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
931
|
+
if ((_nullishCoalesce(prop.useConstraint, () => ( true))) === true) {
|
|
932
|
+
r.foreigns.push({
|
|
933
|
+
columns: [idColumnName],
|
|
934
|
+
to: `${_inflection2.default.underscore(_inflection2.default.pluralize(prop.with)).toLowerCase()}.id`,
|
|
935
|
+
onUpdate: _nullishCoalesce(prop.onUpdate, () => ( "RESTRICT")),
|
|
936
|
+
onDelete: _nullishCoalesce(prop.onDelete, () => ( "RESTRICT"))
|
|
937
|
+
});
|
|
938
|
+
}
|
|
937
939
|
}
|
|
938
940
|
return r;
|
|
939
941
|
},
|
|
@@ -1056,13 +1058,13 @@ var RelationGraph = (_class = class {constructor() { _class.prototype.__init.cal
|
|
|
1056
1058
|
const node = this.graph.get(fixture.fixtureId);
|
|
1057
1059
|
for (const [, column] of Object.entries(fixture.columns)) {
|
|
1058
1060
|
const prop = column.prop;
|
|
1059
|
-
if (
|
|
1060
|
-
if (
|
|
1061
|
+
if (_chunkKX4762I3js.isRelationProp.call(void 0, prop)) {
|
|
1062
|
+
if (_chunkKX4762I3js.isBelongsToOneRelationProp.call(void 0, prop) || _chunkKX4762I3js.isOneToOneRelationProp.call(void 0, prop) && prop.hasJoinColumn) {
|
|
1061
1063
|
const relatedFixtureId = `${prop.with}#${column.value}`;
|
|
1062
1064
|
if (this.graph.has(relatedFixtureId)) {
|
|
1063
1065
|
node.related.add(relatedFixtureId);
|
|
1064
1066
|
}
|
|
1065
|
-
} else if (
|
|
1067
|
+
} else if (_chunkKX4762I3js.isManyToManyRelationProp.call(void 0, prop)) {
|
|
1066
1068
|
const relatedIds = column.value;
|
|
1067
1069
|
for (const relatedId of relatedIds) {
|
|
1068
1070
|
const relatedFixtureId = `${prop.with}#${relatedId}`;
|
|
@@ -1088,11 +1090,11 @@ var RelationGraph = (_class = class {constructor() { _class.prototype.__init.cal
|
|
|
1088
1090
|
}
|
|
1089
1091
|
tempVisited.add(fixtureId);
|
|
1090
1092
|
const node = this.graph.get(fixtureId);
|
|
1091
|
-
const entity =
|
|
1093
|
+
const entity = _chunkKX4762I3js.EntityManager.get(node.entityId);
|
|
1092
1094
|
for (const depId of node.related) {
|
|
1093
1095
|
const depNode = this.graph.get(depId);
|
|
1094
1096
|
const relationProp = entity.props.find(
|
|
1095
|
-
(prop) =>
|
|
1097
|
+
(prop) => _chunkKX4762I3js.isRelationProp.call(void 0, prop) && (_chunkKX4762I3js.isBelongsToOneRelationProp.call(void 0, prop) || _chunkKX4762I3js.isOneToOneRelationProp.call(void 0, prop) && prop.hasJoinColumn) && prop.with === depNode.entityId
|
|
1096
1098
|
);
|
|
1097
1099
|
if (relationProp && !relationProp.nullable) {
|
|
1098
1100
|
visit(depId);
|
|
@@ -1118,39 +1120,39 @@ var RelationGraph = (_class = class {constructor() { _class.prototype.__init.cal
|
|
|
1118
1120
|
var FixtureManagerClass = (_class2 = class {constructor() { _class2.prototype.__init2.call(this); }
|
|
1119
1121
|
__init2() {this.relationGraph = new RelationGraph()}
|
|
1120
1122
|
init() {
|
|
1121
|
-
|
|
1123
|
+
_chunkKX4762I3js.DB.testInit();
|
|
1122
1124
|
}
|
|
1123
1125
|
async cleanAndSeed(usingTables) {
|
|
1124
1126
|
const tableNames = await (async () => {
|
|
1125
1127
|
if (usingTables) {
|
|
1126
1128
|
return usingTables;
|
|
1127
1129
|
}
|
|
1128
|
-
const tables = await
|
|
1130
|
+
const tables = await _chunkKX4762I3js.DB.tdb.raw(
|
|
1129
1131
|
`SHOW TABLE STATUS WHERE Engine IS NOT NULL`
|
|
1130
1132
|
);
|
|
1131
1133
|
return tables.map((tableInfo) => tableInfo["Name"]);
|
|
1132
1134
|
})();
|
|
1133
|
-
await
|
|
1135
|
+
await _chunkKX4762I3js.DB.tdb.raw(`SET FOREIGN_KEY_CHECKS = 0`);
|
|
1134
1136
|
for await (let tableName of tableNames) {
|
|
1135
1137
|
if (tableName == "migrations") {
|
|
1136
1138
|
continue;
|
|
1137
1139
|
}
|
|
1138
|
-
const [fdbChecksumRow] = await
|
|
1140
|
+
const [fdbChecksumRow] = await _chunkKX4762I3js.DB.fdb.raw(
|
|
1139
1141
|
`CHECKSUM TABLE ${tableName}`
|
|
1140
1142
|
);
|
|
1141
1143
|
const fdbChecksum = fdbChecksumRow["Checksum"];
|
|
1142
|
-
const [tdbChecksumRow] = await
|
|
1144
|
+
const [tdbChecksumRow] = await _chunkKX4762I3js.DB.tdb.raw(
|
|
1143
1145
|
`CHECKSUM TABLE ${tableName}`
|
|
1144
1146
|
);
|
|
1145
1147
|
const tdbChecksum = tdbChecksumRow["Checksum"];
|
|
1146
1148
|
if (fdbChecksum !== tdbChecksum) {
|
|
1147
|
-
await
|
|
1148
|
-
const rawQuery = `INSERT INTO ${
|
|
1149
|
-
SELECT * FROM ${
|
|
1150
|
-
await
|
|
1149
|
+
await _chunkKX4762I3js.DB.tdb.truncate(tableName);
|
|
1150
|
+
const rawQuery = `INSERT INTO ${_chunkKX4762I3js.DB.connectionInfo.test.database}.${tableName}
|
|
1151
|
+
SELECT * FROM ${_chunkKX4762I3js.DB.connectionInfo.fixture_local.database}.${tableName}`;
|
|
1152
|
+
await _chunkKX4762I3js.DB.tdb.raw(rawQuery);
|
|
1151
1153
|
}
|
|
1152
1154
|
}
|
|
1153
|
-
await
|
|
1155
|
+
await _chunkKX4762I3js.DB.tdb.raw(`SET FOREIGN_KEY_CHECKS = 1`);
|
|
1154
1156
|
}
|
|
1155
1157
|
async getChecksum(db, tableName) {
|
|
1156
1158
|
const [checksumRow] = await db.raw(
|
|
@@ -1159,8 +1161,8 @@ var FixtureManagerClass = (_class2 = class {constructor() { _class2.prototype.__
|
|
|
1159
1161
|
return checksumRow.Checksum;
|
|
1160
1162
|
}
|
|
1161
1163
|
async sync() {
|
|
1162
|
-
const frdb =
|
|
1163
|
-
const tables = await
|
|
1164
|
+
const frdb = _chunkKX4762I3js.DB.getClient("fixture_remote");
|
|
1165
|
+
const tables = await _chunkKX4762I3js.DB.fdb.raw(
|
|
1164
1166
|
"SHOW TABLE STATUS WHERE Engine IS NOT NULL"
|
|
1165
1167
|
);
|
|
1166
1168
|
const tableNames = tables.map(
|
|
@@ -1169,13 +1171,13 @@ var FixtureManagerClass = (_class2 = class {constructor() { _class2.prototype.__
|
|
|
1169
1171
|
console.log(_chalk2.default.magenta("SYNC..."));
|
|
1170
1172
|
await Promise.all(
|
|
1171
1173
|
tableNames.map(async (tableName) => {
|
|
1172
|
-
if (tableName.startsWith(
|
|
1174
|
+
if (tableName.startsWith(_chunkKX4762I3js.DB.migrationTable)) {
|
|
1173
1175
|
return;
|
|
1174
1176
|
}
|
|
1175
1177
|
const remoteChecksum = await this.getChecksum(frdb, tableName);
|
|
1176
|
-
const localChecksum = await this.getChecksum(
|
|
1178
|
+
const localChecksum = await this.getChecksum(_chunkKX4762I3js.DB.fdb, tableName);
|
|
1177
1179
|
if (remoteChecksum !== localChecksum) {
|
|
1178
|
-
await
|
|
1180
|
+
await _chunkKX4762I3js.DB.fdb.trx(async (transaction) => {
|
|
1179
1181
|
await transaction.raw(`SET FOREIGN_KEY_CHECKS = 0`);
|
|
1180
1182
|
await transaction.truncate(tableName);
|
|
1181
1183
|
const rows = await frdb.raw(`SELECT * FROM ${tableName}`);
|
|
@@ -1218,7 +1220,7 @@ var FixtureManagerClass = (_class2 = class {constructor() { _class2.prototype.__
|
|
|
1218
1220
|
})
|
|
1219
1221
|
)).flat()
|
|
1220
1222
|
);
|
|
1221
|
-
const wdb =
|
|
1223
|
+
const wdb = _chunkKX4762I3js.DB.toClient(_chunkKX4762I3js.DB.getDB("w"));
|
|
1222
1224
|
for (let query of queries) {
|
|
1223
1225
|
const [rsh] = await wdb.raw(query);
|
|
1224
1226
|
console.log({
|
|
@@ -1229,23 +1231,23 @@ var FixtureManagerClass = (_class2 = class {constructor() { _class2.prototype.__
|
|
|
1229
1231
|
}
|
|
1230
1232
|
async getImportQueries(entityId, field, id) {
|
|
1231
1233
|
console.log({ entityId, field, id });
|
|
1232
|
-
const entity =
|
|
1233
|
-
const wdb =
|
|
1234
|
+
const entity = _chunkKX4762I3js.EntityManager.get(entityId);
|
|
1235
|
+
const wdb = _chunkKX4762I3js.DB.toClient(_chunkKX4762I3js.DB.getDB("w"));
|
|
1234
1236
|
const [row] = await wdb.raw(
|
|
1235
1237
|
`SELECT * FROM ${entity.table} WHERE ${field} = ${id} LIMIT 1`
|
|
1236
1238
|
);
|
|
1237
1239
|
if (row === void 0) {
|
|
1238
1240
|
throw new Error(`${entityId}#${id} row\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.`);
|
|
1239
1241
|
}
|
|
1240
|
-
const fixtureDatabase =
|
|
1241
|
-
const realDatabase =
|
|
1242
|
+
const fixtureDatabase = _chunkKX4762I3js.DB.connectionInfo.fixture_remote.database;
|
|
1243
|
+
const realDatabase = _chunkKX4762I3js.DB.connectionInfo.production_master.database;
|
|
1242
1244
|
const selfQuery = `INSERT IGNORE INTO \`${fixtureDatabase}\`.\`${entity.table}\` (SELECT * FROM \`${realDatabase}\`.\`${entity.table}\` WHERE \`id\` = ${id})`;
|
|
1243
1245
|
const args = Object.entries(entity.relations).filter(
|
|
1244
|
-
([, relation]) =>
|
|
1246
|
+
([, relation]) => _chunkKX4762I3js.isBelongsToOneRelationProp.call(void 0, relation) || _chunkKX4762I3js.isOneToOneRelationProp.call(void 0, relation) && relation.customJoinClause === void 0
|
|
1245
1247
|
).map(([, relation]) => {
|
|
1246
1248
|
let field2;
|
|
1247
1249
|
let id2;
|
|
1248
|
-
if (
|
|
1250
|
+
if (_chunkKX4762I3js.isOneToOneRelationProp.call(void 0, relation) && !relation.hasJoinColumn) {
|
|
1249
1251
|
field2 = `${relation.name}_id`;
|
|
1250
1252
|
id2 = row["id"];
|
|
1251
1253
|
} else {
|
|
@@ -1266,14 +1268,14 @@ var FixtureManagerClass = (_class2 = class {constructor() { _class2.prototype.__
|
|
|
1266
1268
|
return [..._lodash2.default.uniq(relQueries.reverse().flat()), selfQuery];
|
|
1267
1269
|
}
|
|
1268
1270
|
async destory() {
|
|
1269
|
-
await
|
|
1270
|
-
await
|
|
1271
|
+
await _chunkKX4762I3js.DB.testDestroy();
|
|
1272
|
+
await _chunkKX4762I3js.DB.destroy();
|
|
1271
1273
|
}
|
|
1272
1274
|
async getFixtures(sourceDBName, targetDBName, searchOptions) {
|
|
1273
|
-
const sourceDB =
|
|
1274
|
-
const targetDB =
|
|
1275
|
+
const sourceDB = _chunkKX4762I3js.DB.getClient(sourceDBName);
|
|
1276
|
+
const targetDB = _chunkKX4762I3js.DB.getClient(targetDBName);
|
|
1275
1277
|
const { entityId, field, value, searchType } = searchOptions;
|
|
1276
|
-
const entity =
|
|
1278
|
+
const entity = _chunkKX4762I3js.EntityManager.get(entityId);
|
|
1277
1279
|
const column = _optionalChain([entity, 'access', _10 => _10.props, 'access', _11 => _11.find, 'call', _12 => _12((prop) => prop.name === field), 'optionalAccess', _13 => _13.type]) === "relation" ? `${field}_id` : field;
|
|
1278
1280
|
let query = sourceDB.from(entity.table).selectAll();
|
|
1279
1281
|
if (searchType === "equals") {
|
|
@@ -1298,7 +1300,7 @@ var FixtureManagerClass = (_class2 = class {constructor() { _class2.prototype.__
|
|
|
1298
1300
|
}
|
|
1299
1301
|
}
|
|
1300
1302
|
for await (const fixture of fixtures) {
|
|
1301
|
-
const entity2 =
|
|
1303
|
+
const entity2 = _chunkKX4762I3js.EntityManager.get(fixture.entityId);
|
|
1302
1304
|
const [row] = await targetDB.from(entity2.table).selectAll().where(["id", "=", fixture.id]).first().execute();
|
|
1303
1305
|
if (row) {
|
|
1304
1306
|
const [record] = await this.createFixtureRecord(entity2, row, {
|
|
@@ -1341,43 +1343,43 @@ var FixtureManagerClass = (_class2 = class {constructor() { _class2.prototype.__
|
|
|
1341
1343
|
belongsRecords: []
|
|
1342
1344
|
};
|
|
1343
1345
|
for (const prop of entity2.props) {
|
|
1344
|
-
if (
|
|
1346
|
+
if (_chunkKX4762I3js.isVirtualProp.call(void 0, prop)) {
|
|
1345
1347
|
continue;
|
|
1346
1348
|
}
|
|
1347
1349
|
record.columns[prop.name] = {
|
|
1348
1350
|
prop,
|
|
1349
1351
|
value: row2[prop.name]
|
|
1350
1352
|
};
|
|
1351
|
-
const db = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _14 => _14._db]), () => (
|
|
1352
|
-
if (
|
|
1353
|
-
const relatedEntity =
|
|
1353
|
+
const db = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _14 => _14._db]), () => ( _chunkKX4762I3js.DB.toClient(_chunkKX4762I3js.DB.getDB("w"))));
|
|
1354
|
+
if (_chunkKX4762I3js.isManyToManyRelationProp.call(void 0, prop)) {
|
|
1355
|
+
const relatedEntity = _chunkKX4762I3js.EntityManager.get(prop.with);
|
|
1354
1356
|
const throughTable = prop.joinTable;
|
|
1355
1357
|
const fromColumn = `${_inflection2.default.singularize(entity2.table)}_id`;
|
|
1356
1358
|
const toColumn = `${_inflection2.default.singularize(relatedEntity.table)}_id`;
|
|
1357
1359
|
const _relatedIds = await db.from(throughTable).select(toColumn).where([fromColumn, "=", row2.id]).execute();
|
|
1358
1360
|
const relatedIds = _relatedIds.map((r) => parseInt(r[toColumn]));
|
|
1359
1361
|
record.columns[prop.name].value = relatedIds;
|
|
1360
|
-
} else if (
|
|
1361
|
-
const relatedEntity =
|
|
1362
|
+
} else if (_chunkKX4762I3js.isHasManyRelationProp.call(void 0, prop)) {
|
|
1363
|
+
const relatedEntity = _chunkKX4762I3js.EntityManager.get(prop.with);
|
|
1362
1364
|
const relatedIds = await db.from(relatedEntity.table).select("id").where([prop.joinColumn, "=", row2.id]).pluck("id");
|
|
1363
1365
|
record.columns[prop.name].value = relatedIds;
|
|
1364
|
-
} else if (
|
|
1365
|
-
const relatedEntity =
|
|
1366
|
+
} else if (_chunkKX4762I3js.isOneToOneRelationProp.call(void 0, prop) && !prop.hasJoinColumn) {
|
|
1367
|
+
const relatedEntity = _chunkKX4762I3js.EntityManager.get(prop.with);
|
|
1366
1368
|
const relatedProp = relatedEntity.props.find(
|
|
1367
|
-
(p) =>
|
|
1369
|
+
(p) => _chunkKX4762I3js.isRelationProp.call(void 0, p) && p.with === entity2.id
|
|
1368
1370
|
);
|
|
1369
1371
|
if (relatedProp) {
|
|
1370
1372
|
const [relatedRow] = await db.from(relatedEntity.table).select("id").where([relatedProp.name, "=", row2.id]).first().execute();
|
|
1371
1373
|
record.columns[prop.name].value = _optionalChain([relatedRow, 'optionalAccess', _15 => _15.id]);
|
|
1372
1374
|
}
|
|
1373
|
-
} else if (
|
|
1375
|
+
} else if (_chunkKX4762I3js.isRelationProp.call(void 0, prop)) {
|
|
1374
1376
|
const relatedId = row2[`${prop.name}_id`];
|
|
1375
1377
|
record.columns[prop.name].value = relatedId;
|
|
1376
1378
|
if (relatedId) {
|
|
1377
1379
|
record.belongsRecords.push(`${prop.with}#${relatedId}`);
|
|
1378
1380
|
}
|
|
1379
1381
|
if (!_optionalChain([options, 'optionalAccess', _16 => _16.singleRecord]) && relatedId) {
|
|
1380
|
-
const relatedEntity =
|
|
1382
|
+
const relatedEntity = _chunkKX4762I3js.EntityManager.get(prop.with);
|
|
1381
1383
|
const [relatedRow] = await db.from(relatedEntity.table).selectAll().where(["id", "=", relatedId]).first().execute();
|
|
1382
1384
|
if (relatedRow) {
|
|
1383
1385
|
await create(relatedEntity, relatedRow);
|
|
@@ -1394,7 +1396,7 @@ var FixtureManagerClass = (_class2 = class {constructor() { _class2.prototype.__
|
|
|
1394
1396
|
const fixtures = _lodash2.default.uniqBy(_fixtures, (f) => f.fixtureId);
|
|
1395
1397
|
this.relationGraph.buildGraph(fixtures);
|
|
1396
1398
|
const insertionOrder = this.relationGraph.getInsertionOrder();
|
|
1397
|
-
const db =
|
|
1399
|
+
const db = _chunkKX4762I3js.DB.getClient(dbName);
|
|
1398
1400
|
await db.trx(async (trx) => {
|
|
1399
1401
|
await trx.raw(`SET FOREIGN_KEY_CHECKS = 0`);
|
|
1400
1402
|
for (const fixtureId of insertionOrder) {
|
|
@@ -1424,7 +1426,7 @@ var FixtureManagerClass = (_class2 = class {constructor() { _class2.prototype.__
|
|
|
1424
1426
|
});
|
|
1425
1427
|
const records = [];
|
|
1426
1428
|
for await (const r of fixtures) {
|
|
1427
|
-
const entity =
|
|
1429
|
+
const entity = _chunkKX4762I3js.EntityManager.get(r.entityId);
|
|
1428
1430
|
const [record] = await db.from(entity.table).selectAll().where(["id", "=", r.id]).first().execute();
|
|
1429
1431
|
records.push({
|
|
1430
1432
|
entityId: r.entityId,
|
|
@@ -1436,17 +1438,17 @@ var FixtureManagerClass = (_class2 = class {constructor() { _class2.prototype.__
|
|
|
1436
1438
|
prepareInsertData(fixture) {
|
|
1437
1439
|
const insertData = {};
|
|
1438
1440
|
for (const [propName, column] of Object.entries(fixture.columns)) {
|
|
1439
|
-
if (
|
|
1441
|
+
if (_chunkKX4762I3js.isVirtualProp.call(void 0, column.prop)) {
|
|
1440
1442
|
continue;
|
|
1441
1443
|
}
|
|
1442
1444
|
const prop = column.prop;
|
|
1443
|
-
if (!
|
|
1445
|
+
if (!_chunkKX4762I3js.isRelationProp.call(void 0, prop)) {
|
|
1444
1446
|
if (prop.type === "json") {
|
|
1445
1447
|
insertData[propName] = JSON.stringify(column.value);
|
|
1446
1448
|
} else {
|
|
1447
1449
|
insertData[propName] = column.value;
|
|
1448
1450
|
}
|
|
1449
|
-
} else if (
|
|
1451
|
+
} else if (_chunkKX4762I3js.isBelongsToOneRelationProp.call(void 0, prop) || _chunkKX4762I3js.isOneToOneRelationProp.call(void 0, prop) && prop.hasJoinColumn) {
|
|
1450
1452
|
insertData[`${propName}_id`] = column.value;
|
|
1451
1453
|
}
|
|
1452
1454
|
}
|
|
@@ -1454,7 +1456,7 @@ var FixtureManagerClass = (_class2 = class {constructor() { _class2.prototype.__
|
|
|
1454
1456
|
}
|
|
1455
1457
|
async insertFixture(db, fixture) {
|
|
1456
1458
|
const insertData = this.prepareInsertData(fixture);
|
|
1457
|
-
const entity =
|
|
1459
|
+
const entity = _chunkKX4762I3js.EntityManager.get(fixture.entityId);
|
|
1458
1460
|
try {
|
|
1459
1461
|
const uniqueFound = await this.checkUniqueViolation(db, entity, fixture);
|
|
1460
1462
|
if (uniqueFound) {
|
|
@@ -1483,15 +1485,15 @@ var FixtureManagerClass = (_class2 = class {constructor() { _class2.prototype.__
|
|
|
1483
1485
|
async handleManyToManyRelations(db, fixture, fixtures) {
|
|
1484
1486
|
for (const [, column] of Object.entries(fixture.columns)) {
|
|
1485
1487
|
const prop = column.prop;
|
|
1486
|
-
if (
|
|
1488
|
+
if (_chunkKX4762I3js.isManyToManyRelationProp.call(void 0, prop)) {
|
|
1487
1489
|
const joinTable = prop.joinTable;
|
|
1488
1490
|
const relatedIds = column.value;
|
|
1489
1491
|
for (const relatedId of relatedIds) {
|
|
1490
1492
|
if (!fixtures.find((f) => f.fixtureId === `${prop.with}#${relatedId}`)) {
|
|
1491
1493
|
continue;
|
|
1492
1494
|
}
|
|
1493
|
-
const entity =
|
|
1494
|
-
const relatedEntity =
|
|
1495
|
+
const entity = _chunkKX4762I3js.EntityManager.get(fixture.entityId);
|
|
1496
|
+
const relatedEntity = _chunkKX4762I3js.EntityManager.get(prop.with);
|
|
1495
1497
|
if (!entity || !relatedEntity) {
|
|
1496
1498
|
throw new Error(
|
|
1497
1499
|
`Entity not found: ${fixture.entityId}, ${prop.with}`
|
|
@@ -1524,7 +1526,7 @@ var FixtureManagerClass = (_class2 = class {constructor() { _class2.prototype.__
|
|
|
1524
1526
|
}
|
|
1525
1527
|
}
|
|
1526
1528
|
async addFixtureLoader(code) {
|
|
1527
|
-
const path2 =
|
|
1529
|
+
const path2 = _chunkKX4762I3js.Sonamu.apiRootPath + "/src/testing/fixture.ts";
|
|
1528
1530
|
let content = _fs.readFileSync.call(void 0, path2).toString();
|
|
1529
1531
|
const fixtureLoaderStart = content.indexOf("const fixtureLoader = {");
|
|
1530
1532
|
const fixtureLoaderEnd = content.indexOf("};", fixtureLoaderStart);
|
|
@@ -1576,4 +1578,4 @@ var FixtureManager = new FixtureManagerClass();
|
|
|
1576
1578
|
|
|
1577
1579
|
|
|
1578
1580
|
exports.Migrator = Migrator; exports.FixtureManagerClass = FixtureManagerClass; exports.FixtureManager = FixtureManager;
|
|
1579
|
-
//# sourceMappingURL=chunk-
|
|
1581
|
+
//# sourceMappingURL=chunk-GUKIIOZI.js.map
|