@gate-forge/pack-alembic 0.9.0 → 0.10.0
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/opt-in.d.ts +4 -2
- package/dist/opt-in.d.ts.map +1 -1
- package/dist/opt-in.js +84 -12
- package/dist/opt-in.js.map +1 -1
- package/package.json +3 -3
package/dist/opt-in.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reads `script_location` from
|
|
2
|
+
* Reads `script_location` from the alembic.ini discovery finds
|
|
3
|
+
* (root or first-level subdirectory).
|
|
3
4
|
*
|
|
4
5
|
* Args:
|
|
5
6
|
* cwd: repository root.
|
|
6
7
|
*
|
|
7
8
|
* Returns:
|
|
8
|
-
* string | null: versions directory
|
|
9
|
+
* string | null: root-relative versions directory, or null when
|
|
10
|
+
* alembic.ini is absent.
|
|
9
11
|
*/
|
|
10
12
|
export declare function detectAlembicVersionsDir(cwd: string): string | null;
|
|
11
13
|
/**
|
package/dist/opt-in.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opt-in.d.ts","sourceRoot":"","sources":["../src/opt-in.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"opt-in.d.ts","sourceRoot":"","sources":["../src/opt-in.ts"],"names":[],"mappings":"AAkFA;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAoB7D"}
|
package/dist/opt-in.js
CHANGED
|
@@ -2,25 +2,97 @@
|
|
|
2
2
|
* Setup text for the opt-in Alembic block. Init prints it. It does not
|
|
3
3
|
* enable the pack.
|
|
4
4
|
*/
|
|
5
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
6
|
-
import { join } from 'node:path';
|
|
5
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
6
|
+
import { dirname, isAbsolute, join, relative } from 'node:path';
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Directory names that never hold the project's alembic.ini:
|
|
9
|
+
* dependency trees, VCS state, and test fixtures are not
|
|
10
|
+
* migration roots.
|
|
11
|
+
*/
|
|
12
|
+
const ALEMBIC_INI_PRUNED_DIRS = {
|
|
13
|
+
node_modules: true,
|
|
14
|
+
'.git': true,
|
|
15
|
+
test: true,
|
|
16
|
+
tests: true,
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Finds the alembic.ini the opt-in block describes: at the
|
|
20
|
+
* repository root, or in ONE first-level subdirectory (the
|
|
21
|
+
* backend/ monorepo layout). The root file always wins;
|
|
22
|
+
* subdirectory ties break alphabetically so the answer is
|
|
23
|
+
* deterministic.
|
|
9
24
|
*
|
|
10
25
|
* Args:
|
|
11
26
|
* cwd: repository root.
|
|
12
27
|
*
|
|
13
28
|
* Returns:
|
|
14
|
-
* string | null:
|
|
29
|
+
* string | null: absolute ini path, or null when no alembic.ini
|
|
30
|
+
* exists at the root or one level down.
|
|
15
31
|
*/
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
32
|
+
function findAlembicIni(cwd) {
|
|
33
|
+
const rootIni = join(cwd, 'alembic.ini');
|
|
34
|
+
if (existsSync(rootIni))
|
|
35
|
+
return rootIni;
|
|
36
|
+
const found = [];
|
|
37
|
+
for (const entry of readdirSync(cwd, { withFileTypes: true })) {
|
|
38
|
+
if (!entry.isDirectory())
|
|
39
|
+
continue;
|
|
40
|
+
if (ALEMBIC_INI_PRUNED_DIRS[entry.name] === true)
|
|
41
|
+
continue;
|
|
42
|
+
if (existsSync(join(cwd, entry.name, 'alembic.ini')))
|
|
43
|
+
found.push(entry.name);
|
|
44
|
+
}
|
|
45
|
+
found.sort();
|
|
46
|
+
const [first] = found;
|
|
47
|
+
return first !== undefined ? join(cwd, first, 'alembic.ini') : null;
|
|
48
|
+
}
|
|
49
|
+
/** Repo-root-relative posix form of an absolute path. */
|
|
50
|
+
function toRepoRelative(cwd, path) {
|
|
51
|
+
return relative(cwd, path).split('\\').join('/');
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Resolves the alembic.ini and its versions directory, both
|
|
55
|
+
* relative to the repository root. `%(here)s` in
|
|
56
|
+
* `script_location` anchors to the ini's OWN directory
|
|
57
|
+
* (alembic's idiom for configs that move with their package);
|
|
58
|
+
* a plain relative location stays root-relative, and an
|
|
59
|
+
* absolute location is taken verbatim.
|
|
60
|
+
*
|
|
61
|
+
* Args:
|
|
62
|
+
* cwd: repository root.
|
|
63
|
+
*
|
|
64
|
+
* Returns:
|
|
65
|
+
* { ini, versions } | null: root-relative paths, or null when
|
|
66
|
+
* no alembic.ini exists.
|
|
67
|
+
*/
|
|
68
|
+
function resolveAlembicLocations(cwd) {
|
|
69
|
+
const iniPath = findAlembicIni(cwd);
|
|
70
|
+
if (iniPath === null)
|
|
19
71
|
return null;
|
|
20
72
|
const text = readFileSync(iniPath, 'utf8');
|
|
21
73
|
const match = text.match(/^\s*script_location\s*=\s*(\S+)/m);
|
|
22
74
|
const script = match?.[1]?.replace(/\\/g, '/') ?? 'migrations';
|
|
23
|
-
|
|
75
|
+
const located = script.includes('%(here)s')
|
|
76
|
+
? script.replaceAll('%(here)s', dirname(iniPath))
|
|
77
|
+
: isAbsolute(script)
|
|
78
|
+
? script
|
|
79
|
+
: join(cwd, script);
|
|
80
|
+
const versions = located.endsWith('/versions') ? located : `${located}/versions`;
|
|
81
|
+
return { ini: toRepoRelative(cwd, iniPath), versions: toRepoRelative(cwd, versions) };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Reads `script_location` from the alembic.ini discovery finds
|
|
85
|
+
* (root or first-level subdirectory).
|
|
86
|
+
*
|
|
87
|
+
* Args:
|
|
88
|
+
* cwd: repository root.
|
|
89
|
+
*
|
|
90
|
+
* Returns:
|
|
91
|
+
* string | null: root-relative versions directory, or null when
|
|
92
|
+
* alembic.ini is absent.
|
|
93
|
+
*/
|
|
94
|
+
export function detectAlembicVersionsDir(cwd) {
|
|
95
|
+
return resolveAlembicLocations(cwd)?.versions ?? null;
|
|
24
96
|
}
|
|
25
97
|
/**
|
|
26
98
|
* Prints the commented opt-in block and the command that proves it.
|
|
@@ -32,8 +104,8 @@ export function detectAlembicVersionsDir(cwd) {
|
|
|
32
104
|
* string | null: text to print, or null when no alembic.ini exists.
|
|
33
105
|
*/
|
|
34
106
|
export function renderAlembicOptIn(cwd) {
|
|
35
|
-
const
|
|
36
|
-
if (
|
|
107
|
+
const locations = resolveAlembicLocations(cwd);
|
|
108
|
+
if (locations === null)
|
|
37
109
|
return null;
|
|
38
110
|
return [
|
|
39
111
|
'alembic detected: alembic.ini. Migration obligations are opt-in and are not enabled.',
|
|
@@ -41,10 +113,10 @@ export function renderAlembicOptIn(cwd) {
|
|
|
41
113
|
'alembic:',
|
|
42
114
|
' chains:',
|
|
43
115
|
' - name: default',
|
|
44
|
-
` migrations: ${versions}`,
|
|
116
|
+
` migrations: ${locations.versions}`,
|
|
45
117
|
' models:',
|
|
46
118
|
' - models.py',
|
|
47
|
-
|
|
119
|
+
` alembicIni: ${locations.ini}`,
|
|
48
120
|
' scratch:',
|
|
49
121
|
' # Trusted admin URL. The engine creates and drops only gf_tmp_<id> databases.',
|
|
50
122
|
' adminUrl: postgresql://gateforge:gateforge@127.0.0.1:5432/postgres',
|
package/dist/opt-in.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opt-in.js","sourceRoot":"","sources":["../src/opt-in.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"opt-in.js","sourceRoot":"","sources":["../src/opt-in.ts"],"names":[],"mappings":"AAAA;;;GAG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AM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,MAAM,SAAS,GAAG,uBAAuB,CAAC,GAAG,CAAC,CAAC;IAC/C,IAAI,SAAS,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACpC,OAAO;QACL,sFAAsF;QACtF,uBAAuB;QACvB,UAAU;QACV,WAAW;QACX,qBAAqB;QACrB,qBAAqB,SAAS,CAAC,QAAQ,EAAE;QACzC,eAAe;QACf,qBAAqB;QACrB,qBAAqB,SAAS,CAAC,GAAG,EAAE;QACpC,YAAY;QACZ,mFAAmF;QACnF,wEAAwE;QACxE,oBAAoB;QACpB,qBAAqB;QACrB,0BAA0B;KAC3B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gate-forge/pack-alembic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Alembic migration obligations pack: static lineage verification, engine-run roundtrip on disposable database, data-preservation checks, and multi-developer merge safety.",
|
|
6
6
|
"type": "module",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"test": "vitest run"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@gate-forge/core": "^0.
|
|
31
|
-
"@gate-forge/plugin-protocol": "^0.
|
|
30
|
+
"@gate-forge/core": "^0.10.0",
|
|
31
|
+
"@gate-forge/plugin-protocol": "^0.10.0",
|
|
32
32
|
"zod": "^4.1.5"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|