sasat 0.22.7 → 0.22.9
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/cli/index.cjs +24 -3
- package/dist/cli/index.mjs +25 -4
- package/dist/comparison-Bkk-qNRi.d.cts +79 -0
- package/dist/comparison-HpKmxsjs.d.mts +79 -0
- package/dist/index-1a8KLRT7.d.mts +495 -0
- package/dist/index-lrk3IfPF.d.cts +495 -0
- package/dist/index.cjs +22 -825
- package/dist/index.d.cts +3 -495
- package/dist/index.d.mts +3 -495
- package/dist/index.mjs +2 -804
- package/dist/{migrate-DnqBdQ6r.mjs → migrate-D-XR7Z0F.mjs} +93 -71
- package/dist/{migrate-BDE07ocG.cjs → migrate-iJE4FjRh.cjs} +96 -68
- package/dist/migration/index.cjs +1 -1
- package/dist/migration/index.d.cts +2 -2
- package/dist/migration/index.d.mts +2 -2
- package/dist/migration/index.mjs +1 -1
- package/dist/src-CdwAbJV0.cjs +926 -0
- package/dist/src-DebKrtYl.mjs +806 -0
- package/dist/testing/index.cjs +70 -1
- package/dist/testing/index.d.cts +19 -2
- package/dist/testing/index.d.mts +19 -2
- package/dist/testing/index.mjs +69 -2
- package/package.json +1 -1
- package/dist/comparison-BpTtc1iD.d.mts +0 -42
- package/dist/comparison-CIb9xu5T.d.cts +0 -42
- package/dist/dbClient-2mFJTQw7.d.mts +0 -35
- package/dist/dbClient-Bnk1JKBU.d.cts +0 -35
- /package/dist/{makeCondition-3MdYUm5k.mjs → makeCondition-BQj-Av95.mjs} +0 -0
- /package/dist/{makeCondition-DKSyAkri.cjs → makeCondition-DljWZv_v.cjs} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as Conditions } from "./makeCondition-
|
|
1
|
+
import { f as setConfig, g as writeFileIfNotExist, h as writeCurrentSchema, i as SasatError, l as SqlString, m as readInitialSchema, p as mkDirIfNotExist, r as unique, t as nonNullable, u as config } from "./util-Dkw5bD7a.mjs";
|
|
2
|
+
import { t as Conditions } from "./makeCondition-BQj-Av95.mjs";
|
|
3
3
|
import fs, { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
4
|
import * as path$1 from "node:path";
|
|
5
|
-
import path from "node:path";
|
|
5
|
+
import path, { join } from "node:path";
|
|
6
6
|
import { mkdir, readdir, rm, writeFile } from "node:fs/promises";
|
|
7
7
|
import "pluralize";
|
|
8
8
|
import chalk from "chalk";
|
|
@@ -1015,6 +1015,7 @@ var StoreMigrator = class StoreMigrator {
|
|
|
1015
1015
|
constructor() {
|
|
1016
1016
|
this.tables = [];
|
|
1017
1017
|
this.migrationQueue = [];
|
|
1018
|
+
this.currentOption = { skipOnTest: false };
|
|
1018
1019
|
}
|
|
1019
1020
|
static new() {
|
|
1020
1021
|
if (fs.existsSync(path.join(config().migration.dir, "initialSchema.yml"))) return StoreMigrator.deserialize(readInitialSchema());
|
|
@@ -1092,10 +1093,9 @@ const calcRunMigrationFileNames = (records) => {
|
|
|
1092
1093
|
});
|
|
1093
1094
|
return result;
|
|
1094
1095
|
};
|
|
1095
|
-
const getCurrentMigration = async (options) => {
|
|
1096
|
+
const getCurrentMigration = async (client, options) => {
|
|
1096
1097
|
const migrationTable = SqlString.escapeId(config().migration.table);
|
|
1097
1098
|
const files = getMigrationFileNames();
|
|
1098
|
-
const client = getDbClient();
|
|
1099
1099
|
const query = `CREATE TABLE IF NOT EXISTS ${migrationTable} (id int auto_increment primary key , name varchar(100) not null,direction enum('up', 'down') not null, migrated_at timestamp default current_timestamp)`;
|
|
1100
1100
|
if (!options.silent) {
|
|
1101
1101
|
Console.log(`creating migration table: ${migrationTable} :: ${Buffer.from(migrationTable).toString("base64")}`);
|
|
@@ -1105,7 +1105,6 @@ const getCurrentMigration = async (options) => {
|
|
|
1105
1105
|
const q = `SELECT name, direction FROM ${migrationTable} ORDER BY id ASC`;
|
|
1106
1106
|
if (!options.silent) Console.debug(q);
|
|
1107
1107
|
const result = await client.rawQuery(q);
|
|
1108
|
-
console.debug(result);
|
|
1109
1108
|
if (!result.length) return;
|
|
1110
1109
|
const runs = calcRunMigrationFileNames(result);
|
|
1111
1110
|
if (runs.length === 0) return;
|
|
@@ -1130,6 +1129,7 @@ const compileMigrationFiles = () => {
|
|
|
1130
1129
|
platform: "node",
|
|
1131
1130
|
format: "esm",
|
|
1132
1131
|
outExtension: { ".js": ".mjs" },
|
|
1132
|
+
external: ["server-only"],
|
|
1133
1133
|
banner: { js: `import { createRequire as topLevelCreateRequire } from 'module';
|
|
1134
1134
|
const require = topLevelCreateRequire(import.meta.url);
|
|
1135
1135
|
import { fileURLToPath as __topLevelFileURLToPath } from 'url';
|
|
@@ -1156,6 +1156,7 @@ const readMigration = async (store, tsFileName, direction) => {
|
|
|
1156
1156
|
await instance.down(store);
|
|
1157
1157
|
if (instance.afterDown) await instance.afterDown();
|
|
1158
1158
|
}
|
|
1159
|
+
store.currentOption = { skipOnTest: instance.skipOnTest ?? false };
|
|
1159
1160
|
return store;
|
|
1160
1161
|
};
|
|
1161
1162
|
//#endregion
|
|
@@ -1170,6 +1171,88 @@ const createCurrentMigrationDataStore = async (targetMigrationName) => {
|
|
|
1170
1171
|
return store;
|
|
1171
1172
|
};
|
|
1172
1173
|
//#endregion
|
|
1174
|
+
//#region src/migration/exec/getMigrationTarget.ts
|
|
1175
|
+
const getMigrationTargets = (files, current) => {
|
|
1176
|
+
const currentIndex = current ? files.indexOf(current) + 1 : 0;
|
|
1177
|
+
const targetIndex = files.indexOf(config().migration.target || files[files.length - 1]) + 1;
|
|
1178
|
+
if (currentIndex === -1 || targetIndex === -1) throw new Error("migration target not found");
|
|
1179
|
+
if (targetIndex >= currentIndex) return {
|
|
1180
|
+
direction: "up",
|
|
1181
|
+
files: files.slice(currentIndex, targetIndex)
|
|
1182
|
+
};
|
|
1183
|
+
return {
|
|
1184
|
+
direction: "down",
|
|
1185
|
+
files: files.slice(targetIndex, currentIndex).reverse()
|
|
1186
|
+
};
|
|
1187
|
+
};
|
|
1188
|
+
//#endregion
|
|
1189
|
+
//#region src/migration/exec/runMigration.ts
|
|
1190
|
+
const runMigration = async (client, store, migrationName, direction, options) => {
|
|
1191
|
+
const sqls = store.getSql();
|
|
1192
|
+
const conf = store.getUpdateConfig();
|
|
1193
|
+
if (conf) setConfig(conf);
|
|
1194
|
+
store.resetQueue();
|
|
1195
|
+
if (!options.silent) sqls.forEach(Console.log);
|
|
1196
|
+
if (options.dry) return;
|
|
1197
|
+
const transaction = await client.transaction();
|
|
1198
|
+
try {
|
|
1199
|
+
for (const sql of sqls) await transaction.rawQuery(sql).catch((e) => {
|
|
1200
|
+
Console.error(`ERROR ON ${migrationName}`);
|
|
1201
|
+
Console.error(`SQL: ${sql}`);
|
|
1202
|
+
Console.error(`MESSAGE: ${e.message}`);
|
|
1203
|
+
process.exit(1);
|
|
1204
|
+
});
|
|
1205
|
+
await transaction.query`insert into ${() => config().migration.table} (name, direction) values (${[migrationName, direction]})`;
|
|
1206
|
+
return await transaction.commit();
|
|
1207
|
+
} catch (e) {
|
|
1208
|
+
await transaction.rollback();
|
|
1209
|
+
throw e;
|
|
1210
|
+
}
|
|
1211
|
+
};
|
|
1212
|
+
//#endregion
|
|
1213
|
+
//#region src/migration/controller.ts
|
|
1214
|
+
var MigrationController = class {
|
|
1215
|
+
async migrate(client, currentMigration, options, execute = runMigration) {
|
|
1216
|
+
const fileNames = getMigrationFileNames();
|
|
1217
|
+
if (!options.silent) Console.log("--current migration--: " + currentMigration);
|
|
1218
|
+
let store = await createCurrentMigrationDataStore(currentMigration);
|
|
1219
|
+
if (store.getUpdateConfig()) setConfig(store.getUpdateConfig());
|
|
1220
|
+
const target = getMigrationTargets(fileNames, currentMigration);
|
|
1221
|
+
for (const tsFileName of target.files) {
|
|
1222
|
+
if (!options.silent) Console.log("---------\n" + tsFileName);
|
|
1223
|
+
store = await readMigration(store, tsFileName, target.direction);
|
|
1224
|
+
await execute(client, store, tsFileName, target.direction, options);
|
|
1225
|
+
store.resetQueue();
|
|
1226
|
+
}
|
|
1227
|
+
return {
|
|
1228
|
+
store: store.serialize(),
|
|
1229
|
+
currentMigration: config().migration.target || fileNames[fileNames.length - 1]
|
|
1230
|
+
};
|
|
1231
|
+
}
|
|
1232
|
+
};
|
|
1233
|
+
//#endregion
|
|
1234
|
+
//#region src/cli/commands/generateTestMigrationFile.ts
|
|
1235
|
+
async function generateTestMigrationFile(client) {
|
|
1236
|
+
try {
|
|
1237
|
+
await compileMigrationFiles();
|
|
1238
|
+
const migration = new MigrationController();
|
|
1239
|
+
const sqls = [];
|
|
1240
|
+
const exec = async (_, store) => {
|
|
1241
|
+
if (!store.currentOption.skipOnTest) sqls.push(...store.getSql());
|
|
1242
|
+
};
|
|
1243
|
+
await migration.migrate(client, void 0, {
|
|
1244
|
+
generateFiles: false,
|
|
1245
|
+
silent: true,
|
|
1246
|
+
dry: false,
|
|
1247
|
+
skipBuild: false
|
|
1248
|
+
}, exec);
|
|
1249
|
+
fs.writeFileSync(join(config().migration.dir, "test.migration.json"), JSON.stringify(sqls));
|
|
1250
|
+
} catch (e) {
|
|
1251
|
+
Console.error(e.message);
|
|
1252
|
+
throw e;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
//#endregion
|
|
1173
1256
|
//#region src/generatorv2/fs/emptyDir.ts
|
|
1174
1257
|
async function emptyDir(dir) {
|
|
1175
1258
|
let items;
|
|
@@ -3492,76 +3575,15 @@ var CodeGen_v2 = class {
|
|
|
3492
3575
|
}
|
|
3493
3576
|
};
|
|
3494
3577
|
//#endregion
|
|
3495
|
-
//#region src/migration/exec/getMigrationTarget.ts
|
|
3496
|
-
const getMigrationTargets = (files, current) => {
|
|
3497
|
-
const currentIndex = current ? files.indexOf(current) + 1 : 0;
|
|
3498
|
-
const targetIndex = files.indexOf(config().migration.target || files[files.length - 1]) + 1;
|
|
3499
|
-
if (currentIndex === -1 || targetIndex === -1) throw new Error("migration target not found");
|
|
3500
|
-
if (targetIndex >= currentIndex) return {
|
|
3501
|
-
direction: "up",
|
|
3502
|
-
files: files.slice(currentIndex, targetIndex)
|
|
3503
|
-
};
|
|
3504
|
-
return {
|
|
3505
|
-
direction: "down",
|
|
3506
|
-
files: files.slice(targetIndex, currentIndex).reverse()
|
|
3507
|
-
};
|
|
3508
|
-
};
|
|
3509
|
-
//#endregion
|
|
3510
|
-
//#region src/migration/exec/runMigration.ts
|
|
3511
|
-
const runMigration = async (client, store, migrationName, direction, options) => {
|
|
3512
|
-
const sqls = store.getSql();
|
|
3513
|
-
const conf = store.getUpdateConfig();
|
|
3514
|
-
if (conf) setConfig(conf);
|
|
3515
|
-
store.resetQueue();
|
|
3516
|
-
if (!options.silent) sqls.forEach(Console.log);
|
|
3517
|
-
if (options.dry) return;
|
|
3518
|
-
const transaction = await client.transaction();
|
|
3519
|
-
try {
|
|
3520
|
-
for (const sql of sqls) await transaction.rawQuery(sql).catch((e) => {
|
|
3521
|
-
Console.error(`ERROR ON ${migrationName}`);
|
|
3522
|
-
Console.error(`SQL: ${sql}`);
|
|
3523
|
-
Console.error(`MESSAGE: ${e.message}`);
|
|
3524
|
-
process.exit(1);
|
|
3525
|
-
});
|
|
3526
|
-
await transaction.query`insert into ${() => config().migration.table} (name, direction) values (${[migrationName, direction]})`;
|
|
3527
|
-
return await transaction.commit();
|
|
3528
|
-
} catch (e) {
|
|
3529
|
-
await transaction.rollback();
|
|
3530
|
-
throw e;
|
|
3531
|
-
}
|
|
3532
|
-
};
|
|
3533
|
-
//#endregion
|
|
3534
|
-
//#region src/migration/controller.ts
|
|
3535
|
-
var MigrationController = class {
|
|
3536
|
-
async migrate(client, options) {
|
|
3537
|
-
const fileNames = getMigrationFileNames();
|
|
3538
|
-
const currentMigration = await getCurrentMigration(options);
|
|
3539
|
-
if (!options.silent) Console.log("--current migration--: " + currentMigration);
|
|
3540
|
-
let store = await createCurrentMigrationDataStore(currentMigration);
|
|
3541
|
-
if (store.getUpdateConfig()) setConfig(store.getUpdateConfig());
|
|
3542
|
-
const target = getMigrationTargets(fileNames, currentMigration);
|
|
3543
|
-
for (const tsFileName of target.files) {
|
|
3544
|
-
if (!options.silent) Console.log("---------\n" + tsFileName);
|
|
3545
|
-
store = await readMigration(store, tsFileName, target.direction);
|
|
3546
|
-
await runMigration(client, store, tsFileName, target.direction, options);
|
|
3547
|
-
store.resetQueue();
|
|
3548
|
-
}
|
|
3549
|
-
return {
|
|
3550
|
-
store: store.serialize(),
|
|
3551
|
-
currentMigration: config().migration.target || fileNames[fileNames.length - 1]
|
|
3552
|
-
};
|
|
3553
|
-
}
|
|
3554
|
-
};
|
|
3555
|
-
//#endregion
|
|
3556
3578
|
//#region src/cli/commands/migrate.ts
|
|
3557
3579
|
const migrate = async (client, options) => {
|
|
3558
3580
|
let current;
|
|
3559
3581
|
if (!options.silent) Console.log("--migration started--");
|
|
3560
3582
|
try {
|
|
3561
3583
|
if (!options.skipBuild) await compileMigrationFiles();
|
|
3562
|
-
const
|
|
3563
|
-
|
|
3564
|
-
const result = await
|
|
3584
|
+
const migration = new MigrationController();
|
|
3585
|
+
const currentMigration = await getCurrentMigration(client, options);
|
|
3586
|
+
const result = await migration.migrate(client, currentMigration, options);
|
|
3565
3587
|
current = result.currentMigration;
|
|
3566
3588
|
if (options.generateFiles) {
|
|
3567
3589
|
const storeHandler = new DataStoreHandler(result.store);
|
|
@@ -3575,4 +3597,4 @@ const migrate = async (client, options) => {
|
|
|
3575
3597
|
}
|
|
3576
3598
|
};
|
|
3577
3599
|
//#endregion
|
|
3578
|
-
export {
|
|
3600
|
+
export { compileMigrationFiles as a, Directory as c, columnTypeToGqlPrimitive as d, DBColumnTypes as f, capitalizeFirstLetter as h, createCurrentMigrationDataStore as i, defaultColumnOption as l, camelize as m, CodeGen_v2 as n, getMigrationFileNames as o, Console as p, generateTestMigrationFile as r, DataStoreHandler as s, migrate as t, defaultGQLOption as u };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_util = require("./util-C5Jevn5B.cjs");
|
|
2
|
-
const require_makeCondition = require("./makeCondition-
|
|
2
|
+
const require_makeCondition = require("./makeCondition-DljWZv_v.cjs");
|
|
3
3
|
let node_fs = require("node:fs");
|
|
4
4
|
node_fs = require_util.__toESM(node_fs, 1);
|
|
5
5
|
let node_path = require("node:path");
|
|
@@ -1018,6 +1018,7 @@ var StoreMigrator = class StoreMigrator {
|
|
|
1018
1018
|
constructor() {
|
|
1019
1019
|
this.tables = [];
|
|
1020
1020
|
this.migrationQueue = [];
|
|
1021
|
+
this.currentOption = { skipOnTest: false };
|
|
1021
1022
|
}
|
|
1022
1023
|
static new() {
|
|
1023
1024
|
if (node_fs.default.existsSync(node_path.default.join(require_util.config().migration.dir, "initialSchema.yml"))) return StoreMigrator.deserialize(require_util.readInitialSchema());
|
|
@@ -1095,10 +1096,9 @@ const calcRunMigrationFileNames = (records) => {
|
|
|
1095
1096
|
});
|
|
1096
1097
|
return result;
|
|
1097
1098
|
};
|
|
1098
|
-
const getCurrentMigration = async (options) => {
|
|
1099
|
+
const getCurrentMigration = async (client, options) => {
|
|
1099
1100
|
const migrationTable = require_util.SqlString.escapeId(require_util.config().migration.table);
|
|
1100
1101
|
const files = getMigrationFileNames();
|
|
1101
|
-
const client = require_util.getDbClient();
|
|
1102
1102
|
const query = `CREATE TABLE IF NOT EXISTS ${migrationTable} (id int auto_increment primary key , name varchar(100) not null,direction enum('up', 'down') not null, migrated_at timestamp default current_timestamp)`;
|
|
1103
1103
|
if (!options.silent) {
|
|
1104
1104
|
Console.log(`creating migration table: ${migrationTable} :: ${Buffer.from(migrationTable).toString("base64")}`);
|
|
@@ -1108,7 +1108,6 @@ const getCurrentMigration = async (options) => {
|
|
|
1108
1108
|
const q = `SELECT name, direction FROM ${migrationTable} ORDER BY id ASC`;
|
|
1109
1109
|
if (!options.silent) Console.debug(q);
|
|
1110
1110
|
const result = await client.rawQuery(q);
|
|
1111
|
-
console.debug(result);
|
|
1112
1111
|
if (!result.length) return;
|
|
1113
1112
|
const runs = calcRunMigrationFileNames(result);
|
|
1114
1113
|
if (runs.length === 0) return;
|
|
@@ -1133,6 +1132,7 @@ const compileMigrationFiles = () => {
|
|
|
1133
1132
|
platform: "node",
|
|
1134
1133
|
format: "esm",
|
|
1135
1134
|
outExtension: { ".js": ".mjs" },
|
|
1135
|
+
external: ["server-only"],
|
|
1136
1136
|
banner: { js: `import { createRequire as topLevelCreateRequire } from 'module';
|
|
1137
1137
|
const require = topLevelCreateRequire(import.meta.url);
|
|
1138
1138
|
import { fileURLToPath as __topLevelFileURLToPath } from 'url';
|
|
@@ -1159,6 +1159,7 @@ const readMigration = async (store, tsFileName, direction) => {
|
|
|
1159
1159
|
await instance.down(store);
|
|
1160
1160
|
if (instance.afterDown) await instance.afterDown();
|
|
1161
1161
|
}
|
|
1162
|
+
store.currentOption = { skipOnTest: instance.skipOnTest ?? false };
|
|
1162
1163
|
return store;
|
|
1163
1164
|
};
|
|
1164
1165
|
//#endregion
|
|
@@ -1173,6 +1174,88 @@ const createCurrentMigrationDataStore = async (targetMigrationName) => {
|
|
|
1173
1174
|
return store;
|
|
1174
1175
|
};
|
|
1175
1176
|
//#endregion
|
|
1177
|
+
//#region src/migration/exec/getMigrationTarget.ts
|
|
1178
|
+
const getMigrationTargets = (files, current) => {
|
|
1179
|
+
const currentIndex = current ? files.indexOf(current) + 1 : 0;
|
|
1180
|
+
const targetIndex = files.indexOf(require_util.config().migration.target || files[files.length - 1]) + 1;
|
|
1181
|
+
if (currentIndex === -1 || targetIndex === -1) throw new Error("migration target not found");
|
|
1182
|
+
if (targetIndex >= currentIndex) return {
|
|
1183
|
+
direction: "up",
|
|
1184
|
+
files: files.slice(currentIndex, targetIndex)
|
|
1185
|
+
};
|
|
1186
|
+
return {
|
|
1187
|
+
direction: "down",
|
|
1188
|
+
files: files.slice(targetIndex, currentIndex).reverse()
|
|
1189
|
+
};
|
|
1190
|
+
};
|
|
1191
|
+
//#endregion
|
|
1192
|
+
//#region src/migration/exec/runMigration.ts
|
|
1193
|
+
const runMigration = async (client, store, migrationName, direction, options) => {
|
|
1194
|
+
const sqls = store.getSql();
|
|
1195
|
+
const conf = store.getUpdateConfig();
|
|
1196
|
+
if (conf) require_util.setConfig(conf);
|
|
1197
|
+
store.resetQueue();
|
|
1198
|
+
if (!options.silent) sqls.forEach(Console.log);
|
|
1199
|
+
if (options.dry) return;
|
|
1200
|
+
const transaction = await client.transaction();
|
|
1201
|
+
try {
|
|
1202
|
+
for (const sql of sqls) await transaction.rawQuery(sql).catch((e) => {
|
|
1203
|
+
Console.error(`ERROR ON ${migrationName}`);
|
|
1204
|
+
Console.error(`SQL: ${sql}`);
|
|
1205
|
+
Console.error(`MESSAGE: ${e.message}`);
|
|
1206
|
+
process.exit(1);
|
|
1207
|
+
});
|
|
1208
|
+
await transaction.query`insert into ${() => require_util.config().migration.table} (name, direction) values (${[migrationName, direction]})`;
|
|
1209
|
+
return await transaction.commit();
|
|
1210
|
+
} catch (e) {
|
|
1211
|
+
await transaction.rollback();
|
|
1212
|
+
throw e;
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1215
|
+
//#endregion
|
|
1216
|
+
//#region src/migration/controller.ts
|
|
1217
|
+
var MigrationController = class {
|
|
1218
|
+
async migrate(client, currentMigration, options, execute = runMigration) {
|
|
1219
|
+
const fileNames = getMigrationFileNames();
|
|
1220
|
+
if (!options.silent) Console.log("--current migration--: " + currentMigration);
|
|
1221
|
+
let store = await createCurrentMigrationDataStore(currentMigration);
|
|
1222
|
+
if (store.getUpdateConfig()) require_util.setConfig(store.getUpdateConfig());
|
|
1223
|
+
const target = getMigrationTargets(fileNames, currentMigration);
|
|
1224
|
+
for (const tsFileName of target.files) {
|
|
1225
|
+
if (!options.silent) Console.log("---------\n" + tsFileName);
|
|
1226
|
+
store = await readMigration(store, tsFileName, target.direction);
|
|
1227
|
+
await execute(client, store, tsFileName, target.direction, options);
|
|
1228
|
+
store.resetQueue();
|
|
1229
|
+
}
|
|
1230
|
+
return {
|
|
1231
|
+
store: store.serialize(),
|
|
1232
|
+
currentMigration: require_util.config().migration.target || fileNames[fileNames.length - 1]
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
};
|
|
1236
|
+
//#endregion
|
|
1237
|
+
//#region src/cli/commands/generateTestMigrationFile.ts
|
|
1238
|
+
async function generateTestMigrationFile(client) {
|
|
1239
|
+
try {
|
|
1240
|
+
await compileMigrationFiles();
|
|
1241
|
+
const migration = new MigrationController();
|
|
1242
|
+
const sqls = [];
|
|
1243
|
+
const exec = async (_, store) => {
|
|
1244
|
+
if (!store.currentOption.skipOnTest) sqls.push(...store.getSql());
|
|
1245
|
+
};
|
|
1246
|
+
await migration.migrate(client, void 0, {
|
|
1247
|
+
generateFiles: false,
|
|
1248
|
+
silent: true,
|
|
1249
|
+
dry: false,
|
|
1250
|
+
skipBuild: false
|
|
1251
|
+
}, exec);
|
|
1252
|
+
node_fs.default.writeFileSync((0, node_path.join)(require_util.config().migration.dir, "test.migration.json"), JSON.stringify(sqls));
|
|
1253
|
+
} catch (e) {
|
|
1254
|
+
Console.error(e.message);
|
|
1255
|
+
throw e;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
//#endregion
|
|
1176
1259
|
//#region src/generatorv2/fs/emptyDir.ts
|
|
1177
1260
|
async function emptyDir(dir) {
|
|
1178
1261
|
let items;
|
|
@@ -3495,76 +3578,15 @@ var CodeGen_v2 = class {
|
|
|
3495
3578
|
}
|
|
3496
3579
|
};
|
|
3497
3580
|
//#endregion
|
|
3498
|
-
//#region src/migration/exec/getMigrationTarget.ts
|
|
3499
|
-
const getMigrationTargets = (files, current) => {
|
|
3500
|
-
const currentIndex = current ? files.indexOf(current) + 1 : 0;
|
|
3501
|
-
const targetIndex = files.indexOf(require_util.config().migration.target || files[files.length - 1]) + 1;
|
|
3502
|
-
if (currentIndex === -1 || targetIndex === -1) throw new Error("migration target not found");
|
|
3503
|
-
if (targetIndex >= currentIndex) return {
|
|
3504
|
-
direction: "up",
|
|
3505
|
-
files: files.slice(currentIndex, targetIndex)
|
|
3506
|
-
};
|
|
3507
|
-
return {
|
|
3508
|
-
direction: "down",
|
|
3509
|
-
files: files.slice(targetIndex, currentIndex).reverse()
|
|
3510
|
-
};
|
|
3511
|
-
};
|
|
3512
|
-
//#endregion
|
|
3513
|
-
//#region src/migration/exec/runMigration.ts
|
|
3514
|
-
const runMigration = async (client, store, migrationName, direction, options) => {
|
|
3515
|
-
const sqls = store.getSql();
|
|
3516
|
-
const conf = store.getUpdateConfig();
|
|
3517
|
-
if (conf) require_util.setConfig(conf);
|
|
3518
|
-
store.resetQueue();
|
|
3519
|
-
if (!options.silent) sqls.forEach(Console.log);
|
|
3520
|
-
if (options.dry) return;
|
|
3521
|
-
const transaction = await client.transaction();
|
|
3522
|
-
try {
|
|
3523
|
-
for (const sql of sqls) await transaction.rawQuery(sql).catch((e) => {
|
|
3524
|
-
Console.error(`ERROR ON ${migrationName}`);
|
|
3525
|
-
Console.error(`SQL: ${sql}`);
|
|
3526
|
-
Console.error(`MESSAGE: ${e.message}`);
|
|
3527
|
-
process.exit(1);
|
|
3528
|
-
});
|
|
3529
|
-
await transaction.query`insert into ${() => require_util.config().migration.table} (name, direction) values (${[migrationName, direction]})`;
|
|
3530
|
-
return await transaction.commit();
|
|
3531
|
-
} catch (e) {
|
|
3532
|
-
await transaction.rollback();
|
|
3533
|
-
throw e;
|
|
3534
|
-
}
|
|
3535
|
-
};
|
|
3536
|
-
//#endregion
|
|
3537
|
-
//#region src/migration/controller.ts
|
|
3538
|
-
var MigrationController = class {
|
|
3539
|
-
async migrate(client, options) {
|
|
3540
|
-
const fileNames = getMigrationFileNames();
|
|
3541
|
-
const currentMigration = await getCurrentMigration(options);
|
|
3542
|
-
if (!options.silent) Console.log("--current migration--: " + currentMigration);
|
|
3543
|
-
let store = await createCurrentMigrationDataStore(currentMigration);
|
|
3544
|
-
if (store.getUpdateConfig()) require_util.setConfig(store.getUpdateConfig());
|
|
3545
|
-
const target = getMigrationTargets(fileNames, currentMigration);
|
|
3546
|
-
for (const tsFileName of target.files) {
|
|
3547
|
-
if (!options.silent) Console.log("---------\n" + tsFileName);
|
|
3548
|
-
store = await readMigration(store, tsFileName, target.direction);
|
|
3549
|
-
await runMigration(client, store, tsFileName, target.direction, options);
|
|
3550
|
-
store.resetQueue();
|
|
3551
|
-
}
|
|
3552
|
-
return {
|
|
3553
|
-
store: store.serialize(),
|
|
3554
|
-
currentMigration: require_util.config().migration.target || fileNames[fileNames.length - 1]
|
|
3555
|
-
};
|
|
3556
|
-
}
|
|
3557
|
-
};
|
|
3558
|
-
//#endregion
|
|
3559
3581
|
//#region src/cli/commands/migrate.ts
|
|
3560
3582
|
const migrate = async (client, options) => {
|
|
3561
3583
|
let current;
|
|
3562
3584
|
if (!options.silent) Console.log("--migration started--");
|
|
3563
3585
|
try {
|
|
3564
3586
|
if (!options.skipBuild) await compileMigrationFiles();
|
|
3565
|
-
const
|
|
3566
|
-
|
|
3567
|
-
const result = await
|
|
3587
|
+
const migration = new MigrationController();
|
|
3588
|
+
const currentMigration = await getCurrentMigration(client, options);
|
|
3589
|
+
const result = await migration.migrate(client, currentMigration, options);
|
|
3568
3590
|
current = result.currentMigration;
|
|
3569
3591
|
if (options.generateFiles) {
|
|
3570
3592
|
const storeHandler = new DataStoreHandler(result.store);
|
|
@@ -3650,6 +3672,12 @@ Object.defineProperty(exports, "defaultGQLOption", {
|
|
|
3650
3672
|
return defaultGQLOption;
|
|
3651
3673
|
}
|
|
3652
3674
|
});
|
|
3675
|
+
Object.defineProperty(exports, "generateTestMigrationFile", {
|
|
3676
|
+
enumerable: true,
|
|
3677
|
+
get: function() {
|
|
3678
|
+
return generateTestMigrationFile;
|
|
3679
|
+
}
|
|
3680
|
+
});
|
|
3653
3681
|
Object.defineProperty(exports, "getMigrationFileNames", {
|
|
3654
3682
|
enumerable: true,
|
|
3655
3683
|
get: function() {
|
package/dist/migration/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_makeCondition = require("../makeCondition-
|
|
2
|
+
const require_makeCondition = require("../makeCondition-DljWZv_v.cjs");
|
|
3
3
|
//#region src/migration/makeMutaion.ts
|
|
4
4
|
const formatSubscription = (subscription) => {
|
|
5
5
|
if (subscription === void 0 || subscription === false) return {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { s as SqlValueType } from "../dbClient-Bnk1JKBU.cjs";
|
|
1
|
+
import { l as SqlValueType, n as ComparisonOperators, p as NestedPartial, u as SasatConfig } from "../comparison-Bkk-qNRi.cjs";
|
|
3
2
|
|
|
4
3
|
//#region src/migration/data/relation.d.ts
|
|
5
4
|
type Relation = "One" | "OneOrZero" | "Many";
|
|
@@ -586,6 +585,7 @@ interface SasatMigration {
|
|
|
586
585
|
afterUp?: () => void | Promise<void>;
|
|
587
586
|
beforeDown?: () => void | Promise<void>;
|
|
588
587
|
afterDown?: () => void | Promise<void>;
|
|
588
|
+
skipOnTest?: boolean | undefined;
|
|
589
589
|
}
|
|
590
590
|
//#endregion
|
|
591
591
|
//#region src/migration/makeCondition.d.ts
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { s as SqlValueType } from "../dbClient-2mFJTQw7.mjs";
|
|
1
|
+
import { l as SqlValueType, n as ComparisonOperators, p as NestedPartial, u as SasatConfig } from "../comparison-HpKmxsjs.mjs";
|
|
3
2
|
|
|
4
3
|
//#region src/migration/data/relation.d.ts
|
|
5
4
|
type Relation = "One" | "OneOrZero" | "Many";
|
|
@@ -586,6 +585,7 @@ interface SasatMigration {
|
|
|
586
585
|
afterUp?: () => void | Promise<void>;
|
|
587
586
|
beforeDown?: () => void | Promise<void>;
|
|
588
587
|
afterDown?: () => void | Promise<void>;
|
|
588
|
+
skipOnTest?: boolean | undefined;
|
|
589
589
|
}
|
|
590
590
|
//#endregion
|
|
591
591
|
//#region src/migration/makeCondition.d.ts
|
package/dist/migration/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Conditions } from "../makeCondition-
|
|
1
|
+
import { t as Conditions } from "../makeCondition-BQj-Av95.mjs";
|
|
2
2
|
//#region src/migration/makeMutaion.ts
|
|
3
3
|
const formatSubscription = (subscription) => {
|
|
4
4
|
if (subscription === void 0 || subscription === false) return {
|