@gate-forge/pack-alembic 0.8.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/LICENSE +202 -0
- package/README.md +60 -0
- package/dist/compile.d.ts +168 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +623 -0
- package/dist/compile.js.map +1 -0
- package/dist/detector.d.ts +46 -0
- package/dist/detector.d.ts.map +1 -0
- package/dist/detector.js +77 -0
- package/dist/detector.js.map +1 -0
- package/dist/execute.d.ts +75 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/execute.js +101 -0
- package/dist/execute.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/lineage.d.ts +6 -0
- package/dist/lineage.d.ts.map +1 -0
- package/dist/lineage.js +6 -0
- package/dist/lineage.js.map +1 -0
- package/dist/merge-safety.d.ts +5 -0
- package/dist/merge-safety.d.ts.map +1 -0
- package/dist/merge-safety.js +5 -0
- package/dist/merge-safety.js.map +1 -0
- package/dist/obligations.d.ts +5 -0
- package/dist/obligations.d.ts.map +1 -0
- package/dist/obligations.js +5 -0
- package/dist/obligations.js.map +1 -0
- package/dist/opt-in.d.ts +21 -0
- package/dist/opt-in.d.ts.map +1 -0
- package/dist/opt-in.js +56 -0
- package/dist/opt-in.js.map +1 -0
- package/dist/preservation.d.ts +5 -0
- package/dist/preservation.d.ts.map +1 -0
- package/dist/preservation.js +5 -0
- package/dist/preservation.js.map +1 -0
- package/dist/roundtrip.d.ts +6 -0
- package/dist/roundtrip.d.ts.map +1 -0
- package/dist/roundtrip.js +6 -0
- package/dist/roundtrip.js.map +1 -0
- package/dist/scratch.d.ts +69 -0
- package/dist/scratch.d.ts.map +1 -0
- package/dist/scratch.js +131 -0
- package/dist/scratch.js.map +1 -0
- package/dist/version.d.ts +8 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +8 -0
- package/dist/version.js.map +1 -0
- package/package.json +43 -0
- package/python/gateforge_alembic_detector/__init__.py +11 -0
- package/python/gateforge_alembic_detector/__main__.py +45 -0
- package/python/gateforge_alembic_detector/runner.py +430 -0
- package/python/gateforge_alembic_detector/scan.py +386 -0
package/dist/scratch.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disposable Postgres databases for Alembic obligations.
|
|
3
|
+
*
|
|
4
|
+
* The engine creates and drops only names that start with `gf_tmp_`.
|
|
5
|
+
* The admin URL comes from trusted configuration. This module never
|
|
6
|
+
* reads `DATABASE_URL` or any other environment variable.
|
|
7
|
+
*/
|
|
8
|
+
import { randomBytes } from 'node:crypto';
|
|
9
|
+
import { spawnSync } from 'node:child_process';
|
|
10
|
+
/** Prefix every engine-created database name must carry. */
|
|
11
|
+
export const SCRATCH_PREFIX = 'gf_tmp_';
|
|
12
|
+
/** Thrown when a database name or URL is not a disposable scratch database. */
|
|
13
|
+
export class ScratchUnsafeError extends Error {
|
|
14
|
+
/**
|
|
15
|
+
* Builds one scratch-safety error.
|
|
16
|
+
*
|
|
17
|
+
* Args:
|
|
18
|
+
* message: single-cause explanation.
|
|
19
|
+
*/
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = 'ScratchUnsafeError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Whether a database name is an engine-created scratch database.
|
|
27
|
+
*
|
|
28
|
+
* Args:
|
|
29
|
+
* name: database name, not a URL.
|
|
30
|
+
*
|
|
31
|
+
* Returns:
|
|
32
|
+
* boolean: true only for `gf_tmp_` plus lowercase hex.
|
|
33
|
+
*/
|
|
34
|
+
export function isScratchDatabaseName(name) {
|
|
35
|
+
return /^gf_tmp_[a-f0-9]{8,}$/.test(name);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Replaces the database name in a postgres URL.
|
|
39
|
+
*
|
|
40
|
+
* Args:
|
|
41
|
+
* adminUrl: trusted admin URL from configuration.
|
|
42
|
+
* name: scratch database name.
|
|
43
|
+
*
|
|
44
|
+
* Returns:
|
|
45
|
+
* string: URL pointing at `name`.
|
|
46
|
+
*/
|
|
47
|
+
export function urlForDatabase(adminUrl, name) {
|
|
48
|
+
if (!isScratchDatabaseName(name)) {
|
|
49
|
+
throw new ScratchUnsafeError(`refusing database name '${name}'`);
|
|
50
|
+
}
|
|
51
|
+
const parsed = new URL(adminUrl);
|
|
52
|
+
parsed.pathname = `/${name}`;
|
|
53
|
+
return parsed.toString();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Runs psql against the admin URL. Never consults the process environment
|
|
57
|
+
* for a database URL.
|
|
58
|
+
*
|
|
59
|
+
* Args:
|
|
60
|
+
* adminUrl: trusted admin URL.
|
|
61
|
+
* sql: one SQL statement.
|
|
62
|
+
*
|
|
63
|
+
* Returns:
|
|
64
|
+
* void: throws when psql exits non-zero.
|
|
65
|
+
*/
|
|
66
|
+
function psql(adminUrl, sql) {
|
|
67
|
+
const result = spawnSync('psql', [adminUrl, '-v', 'ON_ERROR_STOP=1', '-c', sql], {
|
|
68
|
+
encoding: 'utf8',
|
|
69
|
+
env: { PATH: process.env['PATH'] ?? '', HOME: process.env['HOME'] ?? '' },
|
|
70
|
+
});
|
|
71
|
+
if (result.error !== undefined) {
|
|
72
|
+
throw new ScratchUnsafeError(`cannot run psql: ${result.error.message}`);
|
|
73
|
+
}
|
|
74
|
+
if (result.status !== 0) {
|
|
75
|
+
const detail = (result.stderr ?? result.stdout ?? '').trim().split('\n')[0] ?? 'psql failed';
|
|
76
|
+
throw new ScratchUnsafeError(detail);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Creates a disposable database from a trusted admin URL.
|
|
81
|
+
*
|
|
82
|
+
* Args:
|
|
83
|
+
* adminUrl: trusted admin URL. Not read from the environment.
|
|
84
|
+
*
|
|
85
|
+
* Returns:
|
|
86
|
+
* object: scratch name and URL. The caller must drop the database.
|
|
87
|
+
*/
|
|
88
|
+
export function createScratchDatabase(adminUrl) {
|
|
89
|
+
if (!adminUrl.startsWith('postgresql://') && !adminUrl.startsWith('postgres://')) {
|
|
90
|
+
throw new ScratchUnsafeError('scratch adminUrl must be a postgresql URL from trusted configuration');
|
|
91
|
+
}
|
|
92
|
+
const name = `${SCRATCH_PREFIX}${randomBytes(8).toString('hex')}`;
|
|
93
|
+
if (!isScratchDatabaseName(name)) {
|
|
94
|
+
throw new ScratchUnsafeError(`refusing database name '${name}'`);
|
|
95
|
+
}
|
|
96
|
+
psql(adminUrl, `CREATE DATABASE ${name}`);
|
|
97
|
+
return { name, url: urlForDatabase(adminUrl, name) };
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Drops a disposable database. Refuses any name that is not `gf_tmp_`.
|
|
101
|
+
*
|
|
102
|
+
* Args:
|
|
103
|
+
* adminUrl: trusted admin URL.
|
|
104
|
+
* name: database name to drop.
|
|
105
|
+
*
|
|
106
|
+
* Returns:
|
|
107
|
+
* void: the database is gone, or the call throws before touching it.
|
|
108
|
+
*/
|
|
109
|
+
export function dropScratchDatabase(adminUrl, name) {
|
|
110
|
+
if (!isScratchDatabaseName(name)) {
|
|
111
|
+
throw new ScratchUnsafeError(`refusing to drop database '${name}'`);
|
|
112
|
+
}
|
|
113
|
+
psql(adminUrl, `DROP DATABASE IF EXISTS ${name} WITH (FORCE)`);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Whether a scratch database still exists.
|
|
117
|
+
*
|
|
118
|
+
* Args:
|
|
119
|
+
* adminUrl: trusted admin URL.
|
|
120
|
+
* name: database name.
|
|
121
|
+
*
|
|
122
|
+
* Returns:
|
|
123
|
+
* boolean: true when the catalog lists the name.
|
|
124
|
+
*/
|
|
125
|
+
export function scratchDatabaseExists(adminUrl, name) {
|
|
126
|
+
if (!isScratchDatabaseName(name))
|
|
127
|
+
return false;
|
|
128
|
+
const result = spawnSync('psql', [adminUrl, '-v', 'ON_ERROR_STOP=1', '-tAc', `SELECT 1 FROM pg_database WHERE datname = '${name}'`], { encoding: 'utf8', env: { PATH: process.env['PATH'] ?? '', HOME: process.env['HOME'] ?? '' } });
|
|
129
|
+
return (result.stdout ?? '').trim() === '1';
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=scratch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scratch.js","sourceRoot":"","sources":["../src/scratch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,4DAA4D;AAC5D,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC;AAExC,+EAA+E;AAC/E,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C;;;;;OAKG;IACH,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,OAAO,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB,EAAE,IAAY;IAC3D,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,kBAAkB,CAAC,2BAA2B,IAAI,GAAG,CAAC,CAAC;IACnE,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;IACjC,MAAM,CAAC,QAAQ,GAAG,IAAI,IAAI,EAAE,CAAC;IAC7B,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC;AAC3B,CAAC;AAED;;;;;;;;;;GAUG;AACH,S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to. */
|
|
5
|
+
export declare const PACK_PLUGIN_ID = "gateforge.pack-alembic";
|
|
6
|
+
/** Detector/pack version. Must match python/gateforge_alembic_detector/__init__.py. */
|
|
7
|
+
export declare const PACK_VERSION = "0.1.0";
|
|
8
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,8DAA8D;AAC9D,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD,uFAAuF;AACvF,eAAO,MAAM,YAAY,UAAU,CAAC"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pack identity constants for @gate-forge/pack-alembic.
|
|
3
|
+
*/
|
|
4
|
+
/** Plugin id every Alembic pack contribution is pinned to. */
|
|
5
|
+
export const PACK_PLUGIN_ID = 'gateforge.pack-alembic';
|
|
6
|
+
/** Detector/pack version. Must match python/gateforge_alembic_detector/__init__.py. */
|
|
7
|
+
export const PACK_VERSION = '0.1.0';
|
|
8
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEvD,uFAAuF;AACvF,MAAM,CAAC,MAAM,YAAY,GAAG,OAAO,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gate-forge/pack-alembic",
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"description": "Alembic migration obligations pack: static lineage verification, engine-run roundtrip on disposable database, data-preservation checks, and multi-developer merge safety.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"README.md",
|
|
18
|
+
"dist",
|
|
19
|
+
"python"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc -p tsconfig.build.json",
|
|
23
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
24
|
+
"test": "vitest run"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@gate-forge/core": "^0.8.0",
|
|
28
|
+
"@gate-forge/plugin-protocol": "^0.8.0",
|
|
29
|
+
"zod": "^4.1.5"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/umiddey/gateforge.git",
|
|
37
|
+
"directory": "packages/pack-alembic"
|
|
38
|
+
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/umiddey/gateforge/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/umiddey/gateforge#readme"
|
|
43
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""AST-only Alembic migration discovery for Gateforge (GPP/3 detector).
|
|
2
|
+
|
|
3
|
+
Parses Python migration files with the stdlib ast module and reports
|
|
4
|
+
Alembic migration revisions, lineage graphs, operations, and no-op
|
|
5
|
+
downgrades without importing or executing any application code.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
PLUGIN_ID = "gateforge.pack-alembic"
|
|
11
|
+
VERSION = "0.1.0"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""GPP/3 serve entry for the Gateforge Alembic detector.
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
python3 -m gateforge_alembic_detector [root]
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import sys
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
try:
|
|
14
|
+
from gateforge_plugin import ProtocolError, serve
|
|
15
|
+
except ImportError:
|
|
16
|
+
_protocol_py = Path(__file__).resolve().parents[3] / "plugin-protocol" / "python"
|
|
17
|
+
sys.path.insert(0, str(_protocol_py))
|
|
18
|
+
from gateforge_plugin import ProtocolError, serve # noqa: E402
|
|
19
|
+
|
|
20
|
+
from gateforge_alembic_detector import PLUGIN_ID, VERSION
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
_scan_root = Path(sys.argv[1]).resolve() if len(sys.argv) > 1 else None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _discover(paths: list[str]) -> dict:
|
|
27
|
+
"""GPP/3 discover handler: scans each repo-relative path in order.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
paths (list[str]): List of paths requested for discovery.
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
dict: The discovery outcome payload.
|
|
34
|
+
"""
|
|
35
|
+
from gateforge_alembic_detector import scan
|
|
36
|
+
|
|
37
|
+
return scan.scan(paths, _scan_root)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
try:
|
|
42
|
+
raise SystemExit(serve(PLUGIN_ID, VERSION, _discover))
|
|
43
|
+
except ProtocolError as error:
|
|
44
|
+
print(f"gateforge_alembic_detector: {error}", file=sys.stderr)
|
|
45
|
+
raise SystemExit(4) from None
|