aiex-cli 0.0.1-beta.3 → 0.0.1-beta.30
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/README.md +58 -26
- package/dist/cli.mjs +7301 -2816
- package/dist/completions-C3rmTwXZ.mjs +90 -0
- package/dist/core/schema-sqlite/migrate-helper.mjs +49 -42
- package/dist/{doctor-BhNd6jt6.mjs → doctor-collector-DhiJrVw5.mjs} +280 -219
- package/dist/index.d.mts +15 -15
- package/dist/index.mjs +1 -1
- package/dist/table-schema.json +4 -0
- package/dist/web/assets/AISettings-BjXxD5Ts.js +339 -0
- package/dist/web/assets/DataBrowser-CwcTG80-.js +6 -0
- package/dist/web/assets/DataBrowser-DZT0kGQE.css +1 -0
- package/dist/web/assets/ExtractionViewer-CsdK1kKK.js +1 -0
- package/dist/web/assets/JsonSchemaEditor-BhY9BNOn.js +570 -0
- package/dist/web/assets/api-client-D2Y_-4JM.js +1 -0
- package/dist/web/assets/button-Cdgr9Igy.js +927 -0
- package/dist/web/assets/chunk-DtRyYLXJ.js +1 -0
- package/dist/web/assets/{cssMode-BloHqzZF.js → cssMode-CPThwItX.js} +1 -1
- package/dist/web/assets/dialog-CUkPLPNP.js +109 -0
- package/dist/web/assets/dist-9yHVMqQ0.js +1 -0
- package/dist/web/assets/{editor.api-BG499EJF.js → editor.api-C8BHpRhn.js} +1 -1
- package/dist/web/assets/{editor.main-BhEWG0_P.js → editor.main-BnOkwRFv.js} +2 -2
- package/dist/web/assets/{freemarker2-DOHaFATh.js → freemarker2-DWDTYVJR.js} +1 -1
- package/dist/web/assets/{handlebars-BIFWety9.js → handlebars-D4DzjGQ7.js} +1 -1
- package/dist/web/assets/{html-YGaqGZNd.js → html-DnzhKSoD.js} +1 -1
- package/dist/web/assets/{htmlMode-Bu3PyHjq.js → htmlMode-CR7UKfEH.js} +1 -1
- package/dist/web/assets/iconfont.1776926463538-BllfKX1O.ttf +0 -0
- package/dist/web/assets/iconfont.1776926463538-D9epzWxu.woff +0 -0
- package/dist/web/assets/index-C9N8oWt4.css +2 -0
- package/dist/web/assets/index-DCAKotsV.js +882 -0
- package/dist/web/assets/{javascript-N0gZqDK0.js → javascript-D2srszZ8.js} +1 -1
- package/dist/web/assets/{jsonMode-z5YscjcG.js → jsonMode-B4jaPYEr.js} +1 -1
- package/dist/web/assets/{liquid-BHfNNVLs.js → liquid-CIT2Wl_l.js} +1 -1
- package/dist/web/assets/{mdx-Dqu2t0et.js → mdx-CWLaEOFy.js} +1 -1
- package/dist/web/assets/{monaco.contribution-ByQ3yI-W.js → monaco.contribution-DDv5ldfS.js} +2 -2
- package/dist/web/assets/object-utils-DPPzLQjH.js +1 -0
- package/dist/web/assets/{python-icfse9Ji.js → python-6CGfpCNq.js} +1 -1
- package/dist/web/assets/{razor-DwVkryG9.js → razor-DEMMh3TD.js} +1 -1
- package/dist/web/assets/runtime-dom.esm-bundler-ei_N7Xjw.js +1 -0
- package/dist/web/assets/select-BGex2SPs.js +439 -0
- package/dist/web/assets/{tsMode-CLrI3bdf.js → tsMode-Cm1NtjPs.js} +1 -1
- package/dist/web/assets/{typescript-BzuZVF7m.js → typescript-BM9aPEFg.js} +1 -1
- package/dist/web/assets/{xml-Cr85kdqA.js → xml-CoSbvcg5.js} +1 -1
- package/dist/web/assets/{yaml-D3RbJnnO.js → yaml-56GOgy8k.js} +1 -1
- package/dist/web/index.html +10 -4
- package/package.json +19 -2
- package/src/core/schema-sqlite/migrate-helper.ts +41 -50
- package/src/core/schema-sqlite/migration-name.ts +14 -0
- package/dist/web/assets/chunk-BEqpzyXh.js +0 -1
- package/dist/web/assets/index-Bi376XVf.css +0 -2
- package/dist/web/assets/index-c6KB-9C-.js +0 -3262
- /package/dist/web/assets/{abap-Cry0R76c.js → abap-Bgec7Keq.js} +0 -0
- /package/dist/web/assets/{apex-xqbJ58nJ.js → apex-VBlPwEoQ.js} +0 -0
- /package/dist/web/assets/{azcli-D7JTNGKs.js → azcli-DKqrEFBx.js} +0 -0
- /package/dist/web/assets/{bat-Cuq6hn0K.js → bat-DdgQWy_0.js} +0 -0
- /package/dist/web/assets/{bicep-eTuQjz9F.js → bicep-CRMM43EB.js} +0 -0
- /package/dist/web/assets/{cameligo-DKgCRl36.js → cameligo-UatALtML.js} +0 -0
- /package/dist/web/assets/{clojure-B_aTBtVh.js → clojure-D8JU08RA.js} +0 -0
- /package/dist/web/assets/{coffee-BWAYpIPu.js → coffee-C56wu358.js} +0 -0
- /package/dist/web/assets/{cpp-BduBQE8d.js → cpp-CyZLvhJG.js} +0 -0
- /package/dist/web/assets/{csharp-CMqOVYKK.js → csharp-BJl3ixva.js} +0 -0
- /package/dist/web/assets/{csp-6cGliXw2.js → csp-CxEKxmO-.js} +0 -0
- /package/dist/web/assets/{css-CHnKqS9Q.js → css-B0t_muXd.js} +0 -0
- /package/dist/web/assets/{cypher-DMzZBj2L.js → cypher-D1hqiMFD.js} +0 -0
- /package/dist/web/assets/{dart-7hYfJ1Dv.js → dart-Bz550Pyv.js} +0 -0
- /package/dist/web/assets/{dockerfile-BflvjnJW.js → dockerfile-CIXgVAuA.js} +0 -0
- /package/dist/web/assets/{ecl-BEt6xb2p.js → ecl-D9qbvZoA.js} +0 -0
- /package/dist/web/assets/{elixir-CnrQCt6o.js → elixir-b2M38fAy.js} +0 -0
- /package/dist/web/assets/{flow9-CfLCoUuB.js → flow9-Dq1UYMkt.js} +0 -0
- /package/dist/web/assets/{fsharp-BQqR9uQ6.js → fsharp-BaeLhgfq.js} +0 -0
- /package/dist/web/assets/{go-C3AlMVwy.js → go-Bd-NFKIC.js} +0 -0
- /package/dist/web/assets/{graphql-O_-hDldf.js → graphql-DZVerJfy.js} +0 -0
- /package/dist/web/assets/{hcl-BQQD6Mtj.js → hcl-CAVzrZfH.js} +0 -0
- /package/dist/web/assets/{ini-Bf0RDfP_.js → ini-CyXdX58t.js} +0 -0
- /package/dist/web/assets/{java-nqX2KEDD.js → java-B5pNgvhy.js} +0 -0
- /package/dist/web/assets/{julia-B6P9U5er.js → julia-XRhmV3AN.js} +0 -0
- /package/dist/web/assets/{kotlin-B-LRk09-.js → kotlin-DOd3J5vr.js} +0 -0
- /package/dist/web/assets/{less-CEaIdW1f.js → less-veZSnyw6.js} +0 -0
- /package/dist/web/assets/{lexon-Qv4pvFSW.js → lexon-QWGkuK0H.js} +0 -0
- /package/dist/web/assets/{lua-CFpyR7YN.js → lua-CYGpjuO5.js} +0 -0
- /package/dist/web/assets/{m3-CvKhVPQn.js → m3-yNnrZkdc.js} +0 -0
- /package/dist/web/assets/{markdown-qldG3Vc4.js → markdown-BCSWEPSX.js} +0 -0
- /package/dist/web/assets/{mips-0D8PRyHq.js → mips-OpYmcC30.js} +0 -0
- /package/dist/web/assets/{msdax-DwZXSC5M.js → msdax-2oxoTO9Z.js} +0 -0
- /package/dist/web/assets/{mysql-BWq85KY4.js → mysql-5KlC-K_9.js} +0 -0
- /package/dist/web/assets/{objective-c-D653JUMG.js → objective-c-CcDCgtLx.js} +0 -0
- /package/dist/web/assets/{pascal-rWjRDdnR.js → pascal-BZGsbaEV.js} +0 -0
- /package/dist/web/assets/{pascaligo-Db8EehaF.js → pascaligo-DtD5qU3G.js} +0 -0
- /package/dist/web/assets/{perl-C68oq8-D.js → perl-C1jNNS3E.js} +0 -0
- /package/dist/web/assets/{pgsql-BXeHe33s.js → pgsql-CT0fhiZa.js} +0 -0
- /package/dist/web/assets/{php-CDVsAbfl.js → php-D6DrXoPM.js} +0 -0
- /package/dist/web/assets/{pla-DnryFT0q.js → pla-b3-HN2pF.js} +0 -0
- /package/dist/web/assets/{postiats-CDg_4Ev-.js → postiats-Bin2ApVS.js} +0 -0
- /package/dist/web/assets/{powerquery-CWPi8ROz.js → powerquery-7ASnn-ZG.js} +0 -0
- /package/dist/web/assets/{powershell-C5A0QX3-.js → powershell-t4p7sU1H.js} +0 -0
- /package/dist/web/assets/{preload-helper-DSXbuxSR.js → preload-helper-Dd-HcVz_.js} +0 -0
- /package/dist/web/assets/{protobuf-Cgt-BQbL.js → protobuf-BUGeWa_j.js} +0 -0
- /package/dist/web/assets/{pug-RPYJC9QB.js → pug-BuKcgC9s.js} +0 -0
- /package/dist/web/assets/{qsharp-BZ3S7fu_.js → qsharp-DxLLX8mo.js} +0 -0
- /package/dist/web/assets/{r-CN875f1X.js → r-DMlFgn7A.js} +0 -0
- /package/dist/web/assets/{redis-BLesvTwR.js → redis-cXItkC5u.js} +0 -0
- /package/dist/web/assets/{redshift-Byf_0XqD.js → redshift-BZVbW7HE.js} +0 -0
- /package/dist/web/assets/{restructuredtext-DYg_6BiZ.js → restructuredtext-BzjxwS8h.js} +0 -0
- /package/dist/web/assets/{ruby-C4OkxbC-.js → ruby-C5nyLV4l.js} +0 -0
- /package/dist/web/assets/{rust-xAoaEFMh.js → rust-BcmMsHdf.js} +0 -0
- /package/dist/web/assets/{sb-C8dHOW_y.js → sb-Dnb1iy6B.js} +0 -0
- /package/dist/web/assets/{scala-Spx0wP1o.js → scala-anMIFYpA.js} +0 -0
- /package/dist/web/assets/{scheme-D2mZlAUz.js → scheme-BItQTe08.js} +0 -0
- /package/dist/web/assets/{scss-DDCn3Ylu.js → scss-BOv51BJ5.js} +0 -0
- /package/dist/web/assets/{shell-M6px0EWn.js → shell-BsRYRTNN.js} +0 -0
- /package/dist/web/assets/{solidity-DUWMJi-f.js → solidity-BtuLgGDx.js} +0 -0
- /package/dist/web/assets/{sophia-DwJbUG-2.js → sophia-B0Vkc5MF.js} +0 -0
- /package/dist/web/assets/{sparql-ClQxbRPI.js → sparql-B7lvkZQM.js} +0 -0
- /package/dist/web/assets/{sql-BQdjW7Vy.js → sql-DvP5MpA3.js} +0 -0
- /package/dist/web/assets/{st-BpISyZ_v.js → st-GVUeyB3U.js} +0 -0
- /package/dist/web/assets/{swift-CMbl5gM4.js → swift-DSPIoCjm.js} +0 -0
- /package/dist/web/assets/{systemverilog-jx2Xs7uO.js → systemverilog-Icj2-k23.js} +0 -0
- /package/dist/web/assets/{tcl-GIGnfs89.js → tcl-Cd8KQcm-.js} +0 -0
- /package/dist/web/assets/{twig-Bc0mxc_m.js → twig-CBHmt8z3.js} +0 -0
- /package/dist/web/assets/{typespec-CEioAsEm.js → typespec-Ckc037mq.js} +0 -0
- /package/dist/web/assets/{vb-BPk67J-d.js → vb-B97GW9Wb.js} +0 -0
- /package/dist/web/assets/{wgsl-DOnyt8_J.js → wgsl-DIKmb3YH.js} +0 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import { readFileSync } from "jsonfile";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
|
|
6
|
+
//#region src/core/completions.ts
|
|
7
|
+
const LEADING_DASHES = /^-+/;
|
|
8
|
+
function getArgNames(cmd) {
|
|
9
|
+
if (!cmd.args) return [];
|
|
10
|
+
return Object.entries(cmd.args).flatMap(([key, arg]) => {
|
|
11
|
+
const names = [`--${key}`];
|
|
12
|
+
if (arg.alias) names.push(`-${arg.alias}`);
|
|
13
|
+
return names;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function getCommandNames(cmds) {
|
|
17
|
+
return Object.keys(cmds).filter((c) => !c.startsWith("_"));
|
|
18
|
+
}
|
|
19
|
+
function getFileCompletions(pattern) {
|
|
20
|
+
try {
|
|
21
|
+
const files = fs.readdirSync(path.dirname(pattern));
|
|
22
|
+
const ext = path.extname(pattern);
|
|
23
|
+
const prefix = path.basename(pattern).replace(ext, "");
|
|
24
|
+
return files.filter((f) => f.endsWith(ext) && f.startsWith(prefix)).map((f) => f.replace(ext, ""));
|
|
25
|
+
} catch {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function getJsonModelNames(configPath) {
|
|
30
|
+
try {
|
|
31
|
+
const config = readFileSync(configPath);
|
|
32
|
+
if (config.provider?.models) return config.provider.models.map((m) => m.name);
|
|
33
|
+
} catch {}
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
function getValueCompletions(prevArg) {
|
|
37
|
+
switch (prevArg) {
|
|
38
|
+
case "--schema":
|
|
39
|
+
case "-s": {
|
|
40
|
+
const cwd = process.cwd();
|
|
41
|
+
return getFileCompletions(path.join(cwd, ".aiex/schema/*.json"));
|
|
42
|
+
}
|
|
43
|
+
case "--model":
|
|
44
|
+
case "-m": {
|
|
45
|
+
const cwd = process.cwd();
|
|
46
|
+
return getJsonModelNames(path.join(cwd, ".aiex/ai-config.json"));
|
|
47
|
+
}
|
|
48
|
+
case "--file":
|
|
49
|
+
case "-f":
|
|
50
|
+
case "--text":
|
|
51
|
+
case "-t":
|
|
52
|
+
case "--name":
|
|
53
|
+
case "--port":
|
|
54
|
+
case "-p": return [];
|
|
55
|
+
default: return [];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function getCompletions(subCommands, args) {
|
|
59
|
+
const cmds = getCommandNames(subCommands);
|
|
60
|
+
if (args.length <= 1) {
|
|
61
|
+
const word = args[0] ?? "";
|
|
62
|
+
if (!word) return cmds;
|
|
63
|
+
return cmds.filter((c) => c.startsWith(word));
|
|
64
|
+
}
|
|
65
|
+
const cmdName = args[0];
|
|
66
|
+
const cmd = subCommands[cmdName];
|
|
67
|
+
const rest = args.slice(1);
|
|
68
|
+
if (!cmd) {
|
|
69
|
+
const matched = cmds.filter((c) => c.startsWith(cmdName));
|
|
70
|
+
if (matched.length > 0) return matched;
|
|
71
|
+
return cmds;
|
|
72
|
+
}
|
|
73
|
+
const current = rest[rest.length - 1] ?? "";
|
|
74
|
+
const prev = rest.length > 1 ? rest[rest.length - 2] : void 0;
|
|
75
|
+
if (current.startsWith("-")) {
|
|
76
|
+
const names = getArgNames(cmd);
|
|
77
|
+
if (!current) return names;
|
|
78
|
+
const key = current.replace(LEADING_DASHES, "");
|
|
79
|
+
if (!key) return names;
|
|
80
|
+
return names.filter((n) => n.replace(LEADING_DASHES, "").startsWith(key));
|
|
81
|
+
}
|
|
82
|
+
if (!current && prev) {
|
|
83
|
+
const values = getValueCompletions(prev);
|
|
84
|
+
if (values.length > 0) return values;
|
|
85
|
+
}
|
|
86
|
+
return getArgNames(cmd);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
export { getCompletions };
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import process from "node:process";
|
|
5
|
+
import { readFile, writeFile } from "jsonfile";
|
|
4
6
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import fs from "node:fs/promises";
|
|
6
7
|
import Database from "better-sqlite3";
|
|
7
8
|
import * as esbuild from "esbuild";
|
|
9
|
+
import lockfile from "proper-lockfile";
|
|
10
|
+
|
|
11
|
+
//#region src/core/schema-sqlite/migration-name.ts
|
|
12
|
+
function sanitizeMigrationName(name) {
|
|
13
|
+
if (!name) return void 0;
|
|
14
|
+
return name.trim().toLowerCase().replace(/[^a-z0-9_\s-]/g, "_").replace(/[\s-]+/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "") || void 0;
|
|
15
|
+
}
|
|
8
16
|
|
|
17
|
+
//#endregion
|
|
9
18
|
//#region src/core/schema-sqlite/migrate-helper.ts
|
|
10
19
|
const require = createRequire(import.meta.url);
|
|
11
20
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -55,22 +64,21 @@ async function loadSchemaExports(schemaPath) {
|
|
|
55
64
|
async function loadPrevSnapshot(migrationsPath) {
|
|
56
65
|
const metaPath = path.join(migrationsPath, "meta", "_journal.json");
|
|
57
66
|
try {
|
|
58
|
-
const journal =
|
|
67
|
+
const journal = await readFile(metaPath);
|
|
59
68
|
if (!journal.entries?.length) return null;
|
|
60
69
|
const latestEntry = journal.entries[journal.entries.length - 1];
|
|
61
|
-
|
|
62
|
-
return JSON.parse(await fs.readFile(snapshotPath, "utf-8"));
|
|
70
|
+
return await readFile(path.join(migrationsPath, "meta", `${latestEntry.tag}_snapshot.json`));
|
|
63
71
|
} catch {
|
|
64
72
|
return null;
|
|
65
73
|
}
|
|
66
74
|
}
|
|
67
|
-
async function saveSnapshot(migrationsPath, snapshot) {
|
|
75
|
+
async function saveSnapshot(migrationsPath, snapshot, migrationName) {
|
|
68
76
|
const metaPath = path.join(migrationsPath, "meta");
|
|
69
77
|
await fs.mkdir(metaPath, { recursive: true });
|
|
70
78
|
const journalPath = path.join(metaPath, "_journal.json");
|
|
71
79
|
let journal;
|
|
72
80
|
try {
|
|
73
|
-
journal =
|
|
81
|
+
journal = await readFile(journalPath);
|
|
74
82
|
} catch {
|
|
75
83
|
journal = {
|
|
76
84
|
version: "6",
|
|
@@ -79,9 +87,12 @@ async function saveSnapshot(migrationsPath, snapshot) {
|
|
|
79
87
|
};
|
|
80
88
|
}
|
|
81
89
|
const idx = journal.entries.length + 1;
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
await
|
|
90
|
+
const suffix = sanitizeMigrationName(migrationName) || snapshot.id.replace(/-/g, "_").substring(0, 8);
|
|
91
|
+
const tag = `${String(idx).padStart(4, "0")}_${suffix}`;
|
|
92
|
+
await writeFile(path.join(metaPath, `${tag}_snapshot.json`), snapshot, {
|
|
93
|
+
spaces: 2,
|
|
94
|
+
EOL: "\n"
|
|
95
|
+
});
|
|
85
96
|
journal.entries.push({
|
|
86
97
|
idx,
|
|
87
98
|
version: snapshot.id,
|
|
@@ -89,7 +100,10 @@ async function saveSnapshot(migrationsPath, snapshot) {
|
|
|
89
100
|
tag,
|
|
90
101
|
breakpoints: true
|
|
91
102
|
});
|
|
92
|
-
await
|
|
103
|
+
await writeFile(journalPath, journal, {
|
|
104
|
+
spaces: 2,
|
|
105
|
+
EOL: "\n"
|
|
106
|
+
});
|
|
93
107
|
return tag;
|
|
94
108
|
}
|
|
95
109
|
async function saveMigrationFile(migrationsPath, tag, sqlStatements) {
|
|
@@ -111,50 +125,43 @@ function applyMigrationWithTransaction(dbPath, sqlStatements) {
|
|
|
111
125
|
}
|
|
112
126
|
}
|
|
113
127
|
const LOCK_FILE = ".migrate.lock";
|
|
114
|
-
async function
|
|
115
|
-
const lockPath = path.join(aiexDir, LOCK_FILE);
|
|
128
|
+
async function acquireMigrationLock(aiexDir) {
|
|
116
129
|
await fs.mkdir(aiexDir, { recursive: true });
|
|
117
130
|
try {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return acquireLock(aiexDir);
|
|
130
|
-
}
|
|
131
|
-
throw new Error(`Migration is already running (PID ${lockPid}, started ${Math.round(lockAge / 1e3)}s ago). Wait for it to complete or remove ${lockPath} if stale.`);
|
|
132
|
-
} catch {
|
|
133
|
-
await fs.unlink(lockPath).catch(() => {});
|
|
134
|
-
return acquireLock(aiexDir);
|
|
135
|
-
}
|
|
136
|
-
throw e;
|
|
131
|
+
return await lockfile.lock(aiexDir, {
|
|
132
|
+
lockfilePath: path.join(aiexDir, LOCK_FILE),
|
|
133
|
+
realpath: false,
|
|
134
|
+
stale: 3e5,
|
|
135
|
+
update: 1e4,
|
|
136
|
+
retries: 0
|
|
137
|
+
});
|
|
138
|
+
} catch (error) {
|
|
139
|
+
const lockPath = path.join(aiexDir, LOCK_FILE);
|
|
140
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
141
|
+
throw new Error(`Migration is already running or the lock could not be acquired. Wait for it to complete or remove ${lockPath} if stale. ${message}`);
|
|
137
142
|
}
|
|
138
143
|
}
|
|
139
|
-
async function releaseLock(aiexDir) {
|
|
140
|
-
const lockPath = path.join(aiexDir, LOCK_FILE);
|
|
141
|
-
await fs.unlink(lockPath).catch(() => {});
|
|
142
|
-
}
|
|
143
144
|
async function main() {
|
|
144
145
|
const args = process.argv.slice(2);
|
|
145
146
|
const schemaPath = args[0];
|
|
146
147
|
const migrationsPath = args[1];
|
|
147
148
|
const dbPath = args[2];
|
|
149
|
+
const migrationName = args[3];
|
|
148
150
|
if (!schemaPath || !migrationsPath || !dbPath) {
|
|
149
|
-
console.error("Usage: migrate-helper.ts <schemaPath> <migrationsPath> <dbPath>");
|
|
151
|
+
console.error("Usage: migrate-helper.ts <schemaPath> <migrationsPath> <dbPath> [migrationName]");
|
|
150
152
|
process.exit(1);
|
|
151
153
|
}
|
|
152
154
|
try {
|
|
153
|
-
const
|
|
154
|
-
await acquireLock(aiexDir);
|
|
155
|
+
const releaseLock = await acquireMigrationLock(path.dirname(path.dirname(migrationsPath)));
|
|
155
156
|
try {
|
|
156
157
|
const exports = await loadSchemaExports(schemaPath);
|
|
157
|
-
|
|
158
|
+
let dbMissing = false;
|
|
159
|
+
try {
|
|
160
|
+
await fs.access(dbPath);
|
|
161
|
+
} catch {
|
|
162
|
+
dbMissing = true;
|
|
163
|
+
}
|
|
164
|
+
const prevSnapshot = dbMissing ? null : await loadPrevSnapshot(migrationsPath);
|
|
158
165
|
const currentSnapshot = await generateSQLiteDrizzleJson(exports, prevSnapshot?.id);
|
|
159
166
|
const sqlStatements = await generateSQLiteMigration(prevSnapshot || EMPTY_SNAPSHOT, currentSnapshot);
|
|
160
167
|
if (sqlStatements.length === 0) {
|
|
@@ -165,7 +172,7 @@ async function main() {
|
|
|
165
172
|
return;
|
|
166
173
|
}
|
|
167
174
|
applyMigrationWithTransaction(dbPath, sqlStatements);
|
|
168
|
-
const tag = await saveSnapshot(migrationsPath, currentSnapshot);
|
|
175
|
+
const tag = await saveSnapshot(migrationsPath, currentSnapshot, migrationName);
|
|
169
176
|
await saveMigrationFile(migrationsPath, tag, sqlStatements);
|
|
170
177
|
console.log(JSON.stringify({
|
|
171
178
|
success: true,
|
|
@@ -173,7 +180,7 @@ async function main() {
|
|
|
173
180
|
tag
|
|
174
181
|
}));
|
|
175
182
|
} finally {
|
|
176
|
-
await releaseLock(
|
|
183
|
+
await releaseLock();
|
|
177
184
|
}
|
|
178
185
|
} catch (error) {
|
|
179
186
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -184,7 +191,7 @@ async function main() {
|
|
|
184
191
|
process.exit(1);
|
|
185
192
|
}
|
|
186
193
|
}
|
|
187
|
-
main();
|
|
194
|
+
if (process.argv[1] && __filename === path.resolve(process.argv[1])) main();
|
|
188
195
|
|
|
189
196
|
//#endregion
|
|
190
197
|
export { };
|