@ingeniumgolf/migrations 0.1.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 +21 -0
- package/README.md +147 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +182 -0
- package/dist/cli.js.map +1 -0
- package/dist/files.d.ts +9 -0
- package/dist/files.js +114 -0
- package/dist/files.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +2 -0
- package/dist/loader.js +55 -0
- package/dist/loader.js.map +1 -0
- package/dist/migrator.d.ts +30 -0
- package/dist/migrator.js +213 -0
- package/dist/migrator.js.map +1 -0
- package/dist/types.d.ts +45 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ingenium Golf
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# @ingeniumgolf/migrations
|
|
2
|
+
|
|
3
|
+
Small, SQL-first PostgreSQL migration runner built on [pg-promise](https://github.com/vitaly-t/pg-promise). Migrations are TypeScript (or JavaScript) files exporting `up` and optionally `down`.
|
|
4
|
+
|
|
5
|
+
- Timestamped versions (`YYYYMMDDHHMMSS`), so parallel branches don't collide
|
|
6
|
+
- One transaction per migration, with an opt-out for statements like `CREATE INDEX CONCURRENTLY`
|
|
7
|
+
- Postgres advisory lock, so overlapping deploys never run a migration twice
|
|
8
|
+
- Checksums: `status` flags applied migrations that were edited afterwards
|
|
9
|
+
- `baseline` to adopt the runner on an existing database
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pnpm add @ingeniumgolf/migrations
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Requires Node.js 22.18 or newer, which runs `.ts` migrations natively. Projects that already use `tsx` or `ts-node` can load migrations through those instead.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
glfr-migrate create add users table # migrations/20261006120000_add_users_table.ts
|
|
23
|
+
glfr-migrate up # apply all pending migrations
|
|
24
|
+
glfr-migrate up --step 1 # apply the next migration only
|
|
25
|
+
glfr-migrate status
|
|
26
|
+
glfr-migrate down # roll back the latest migration
|
|
27
|
+
glfr-migrate down --step 3
|
|
28
|
+
glfr-migrate baseline 20261006120000 # mark everything up to this version as applied
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
| Option | Default |
|
|
32
|
+
| ------------------- | ----------------------------------------------------------------------------------------------------- |
|
|
33
|
+
| `--dir <path>` | `./migrations` |
|
|
34
|
+
| `--url <url>` | `$DATABASE_URL`, then libpq `PG*` env vars (`PGHOST`, `PGPORT`, `PGDATABASE`, `PGUSER`, `PGPASSWORD`) |
|
|
35
|
+
| `--table <name>` | `glfr_migrations`, may be schema-qualified (`ops.glfr_migrations`) |
|
|
36
|
+
| `--env-file <path>` | none; loads a `.env` file before connecting |
|
|
37
|
+
|
|
38
|
+
Typical `package.json` scripts:
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"scripts": {
|
|
43
|
+
"migrate": "glfr-migrate --env-file .env",
|
|
44
|
+
"migrate:create": "glfr-migrate create"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Migration files
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import type { MigrationTask } from "@ingeniumgolf/migrations";
|
|
53
|
+
|
|
54
|
+
export const up = async (t: MigrationTask): Promise<void> => {
|
|
55
|
+
await t.none(`--sql
|
|
56
|
+
CREATE TABLE widgets (id SERIAL PRIMARY KEY, name TEXT NOT NULL);
|
|
57
|
+
`);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const down = async (t: MigrationTask): Promise<void> => {
|
|
61
|
+
await t.none(`--sql
|
|
62
|
+
DROP TABLE widgets;
|
|
63
|
+
`);
|
|
64
|
+
};
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
- `t` is a pg-promise task (`t.none`, `t.any`, `t.one`, …) running inside a transaction.
|
|
68
|
+
- Omit `down` for irreversible migrations; `glfr-migrate down` will refuse to roll them back.
|
|
69
|
+
- Export `transaction = false` for statements that cannot run in a transaction:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
export const transaction = false;
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
- Use `import type` for type-only imports. Node's type stripping removes them; a plain `import { MigrationTask }` would fail at runtime.
|
|
76
|
+
- Never edit a migration after it has run on a shared database; add a new one instead. `status` marks edited migrations as `modified`.
|
|
77
|
+
|
|
78
|
+
### Custom connection settings
|
|
79
|
+
|
|
80
|
+
If your project names its connection variables differently, wrap the CLI:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
// scripts/migrate.ts
|
|
84
|
+
import { runCli } from "@ingeniumgolf/migrations";
|
|
85
|
+
|
|
86
|
+
runCli(process.argv.slice(2), {
|
|
87
|
+
dir: "db/migrations",
|
|
88
|
+
connection: () => ({
|
|
89
|
+
host: process.env.DB_HOST,
|
|
90
|
+
port: Number(process.env.DB_PORT),
|
|
91
|
+
database: process.env.DB_NAME,
|
|
92
|
+
user: process.env.DB_USER,
|
|
93
|
+
password: process.env.DB_PASS,
|
|
94
|
+
}),
|
|
95
|
+
}).then((code) => {
|
|
96
|
+
process.exitCode = code;
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`--url` and `DATABASE_URL` still take precedence over the wrapper's `connection`.
|
|
101
|
+
|
|
102
|
+
### Programmatic API
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { Migrator } from "@ingeniumgolf/migrations";
|
|
106
|
+
|
|
107
|
+
const migrator = new Migrator({
|
|
108
|
+
connection: process.env.DATABASE_URL!,
|
|
109
|
+
dir: "migrations",
|
|
110
|
+
});
|
|
111
|
+
try {
|
|
112
|
+
await migrator.up();
|
|
113
|
+
} finally {
|
|
114
|
+
await migrator.close();
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Adopting an existing database
|
|
119
|
+
|
|
120
|
+
1. Add a first migration that recreates the current schema, e.g. from `pg_dump --schema-only`.
|
|
121
|
+
2. On databases that already have that schema, run `glfr-migrate baseline <its version>` once. This records it as applied without running it.
|
|
122
|
+
3. Fresh databases run it normally with `glfr-migrate up`.
|
|
123
|
+
|
|
124
|
+
## Development
|
|
125
|
+
|
|
126
|
+
```sh
|
|
127
|
+
pnpm install
|
|
128
|
+
pnpm test:db # starts Postgres 18 on localhost:54329 via Docker
|
|
129
|
+
TEST_DATABASE_URL=postgres://postgres:postgres@localhost:54329/postgres pnpm test
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Integration tests are skipped when `TEST_DATABASE_URL` is unset.
|
|
133
|
+
|
|
134
|
+
## Releasing
|
|
135
|
+
|
|
136
|
+
Releases are published to npm by the [release workflow](.github/workflows/release.yml) when a `v*` tag is pushed, using npm trusted publishing (no npm tokens stored anywhere):
|
|
137
|
+
|
|
138
|
+
```sh
|
|
139
|
+
npm version patch # or minor / major: bumps package.json, commits, tags
|
|
140
|
+
git push --follow-tags
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The workflow checks that the tag matches `package.json`, runs the tests, and publishes with provenance.
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
MIT
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import type { ConnectionOptions } from "./types";
|
|
3
|
+
export interface CliOptions {
|
|
4
|
+
/** Connection used when --url and DATABASE_URL are not set. Lets wrappers map project-specific env vars. */
|
|
5
|
+
connection?: ConnectionOptions | (() => ConnectionOptions);
|
|
6
|
+
/** Default migrations directory, relative to the working directory. */
|
|
7
|
+
dir?: string;
|
|
8
|
+
table?: string;
|
|
9
|
+
}
|
|
10
|
+
/** Runs the CLI. Returns the process exit code. */
|
|
11
|
+
export declare const runCli: (argv?: string[], options?: CliOptions) => Promise<number>;
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.runCli = void 0;
|
|
38
|
+
const fs = __importStar(require("node:fs"));
|
|
39
|
+
const path = __importStar(require("node:path"));
|
|
40
|
+
const node_util_1 = require("node:util");
|
|
41
|
+
const files_1 = require("./files");
|
|
42
|
+
const migrator_1 = require("./migrator");
|
|
43
|
+
const USAGE = `Usage: glfr-migrate <command> [options]
|
|
44
|
+
|
|
45
|
+
Commands:
|
|
46
|
+
up Apply pending migrations
|
|
47
|
+
down Roll back the latest migration
|
|
48
|
+
status List applied, pending, modified and missing migrations
|
|
49
|
+
create <description> Create a new migration file
|
|
50
|
+
baseline <version> Mark migrations up to <version> as applied without running them
|
|
51
|
+
|
|
52
|
+
Options:
|
|
53
|
+
--dir <path> Migrations directory (default: ./migrations)
|
|
54
|
+
--url <url> Connection string (default: $DATABASE_URL, then libpq PG* variables)
|
|
55
|
+
--table <name> Bookkeeping table, optionally schema-qualified (default: glfr_migrations)
|
|
56
|
+
--env-file <path> Load environment variables from a .env file first
|
|
57
|
+
--step <n> up: apply at most n migrations. down: roll back n migrations (default 1)
|
|
58
|
+
-h, --help Show this help
|
|
59
|
+
-v, --version Show the package version
|
|
60
|
+
`;
|
|
61
|
+
const STATE_ICONS = {
|
|
62
|
+
applied: "✓",
|
|
63
|
+
pending: "○",
|
|
64
|
+
modified: "!",
|
|
65
|
+
missing: "?",
|
|
66
|
+
};
|
|
67
|
+
const parseStep = (value) => {
|
|
68
|
+
if (value === undefined)
|
|
69
|
+
return undefined;
|
|
70
|
+
const step = Number(value);
|
|
71
|
+
if (!Number.isInteger(step) || step < 1)
|
|
72
|
+
throw new Error(`--step must be a positive integer, got "${value}"`);
|
|
73
|
+
return step;
|
|
74
|
+
};
|
|
75
|
+
const resolveConnection = (url, fallback) => {
|
|
76
|
+
if (url)
|
|
77
|
+
return url;
|
|
78
|
+
if (process.env.DATABASE_URL)
|
|
79
|
+
return process.env.DATABASE_URL;
|
|
80
|
+
if (fallback)
|
|
81
|
+
return typeof fallback === "function" ? fallback() : fallback;
|
|
82
|
+
// node-postgres fills in PGHOST, PGPORT, PGDATABASE, PGUSER and PGPASSWORD
|
|
83
|
+
return {};
|
|
84
|
+
};
|
|
85
|
+
const readPackageVersion = () => {
|
|
86
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8"));
|
|
87
|
+
return pkg.version;
|
|
88
|
+
};
|
|
89
|
+
const printStatus = (statuses) => {
|
|
90
|
+
if (statuses.length === 0) {
|
|
91
|
+
console.log("No migrations found");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
for (const s of statuses) {
|
|
95
|
+
const applied = s.appliedAt ? ` ${s.appliedAt.toISOString()}` : "";
|
|
96
|
+
console.log(`${STATE_ICONS[s.state]} ${s.state.padEnd(8)} ${s.filename}${applied}`);
|
|
97
|
+
}
|
|
98
|
+
const modified = statuses.filter((s) => s.state === "modified").length;
|
|
99
|
+
const missing = statuses.filter((s) => s.state === "missing").length;
|
|
100
|
+
if (modified > 0)
|
|
101
|
+
console.warn(`\n${modified} applied migration(s) changed on disk since they ran`);
|
|
102
|
+
if (missing > 0)
|
|
103
|
+
console.warn(`\n${missing} applied migration(s) have no file in the migrations directory`);
|
|
104
|
+
};
|
|
105
|
+
/** Runs the CLI. Returns the process exit code. */
|
|
106
|
+
const runCli = async (argv = process.argv.slice(2), options = {}) => {
|
|
107
|
+
const { values, positionals } = (0, node_util_1.parseArgs)({
|
|
108
|
+
args: argv,
|
|
109
|
+
allowPositionals: true,
|
|
110
|
+
options: {
|
|
111
|
+
dir: { type: "string" },
|
|
112
|
+
url: { type: "string" },
|
|
113
|
+
table: { type: "string" },
|
|
114
|
+
"env-file": { type: "string" },
|
|
115
|
+
step: { type: "string" },
|
|
116
|
+
all: { type: "boolean" },
|
|
117
|
+
help: { type: "boolean", short: "h" },
|
|
118
|
+
version: { type: "boolean", short: "v" },
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
if (values.version) {
|
|
122
|
+
console.log(readPackageVersion());
|
|
123
|
+
return 0;
|
|
124
|
+
}
|
|
125
|
+
const [command, ...rest] = positionals;
|
|
126
|
+
if (values.help || !command) {
|
|
127
|
+
console.log(USAGE);
|
|
128
|
+
return values.help ? 0 : 1;
|
|
129
|
+
}
|
|
130
|
+
if (values["env-file"])
|
|
131
|
+
process.loadEnvFile(values["env-file"]);
|
|
132
|
+
const dir = path.resolve(values.dir ?? options.dir ?? "migrations");
|
|
133
|
+
if (command === "create" || command === "new" || command === "generate") {
|
|
134
|
+
const filePath = (0, files_1.createMigrationFile)(dir, rest.join(" "));
|
|
135
|
+
console.log(`Created ${path.relative(process.cwd(), filePath)}`);
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
138
|
+
const migrator = new migrator_1.Migrator({
|
|
139
|
+
connection: resolveConnection(values.url, options.connection),
|
|
140
|
+
dir,
|
|
141
|
+
table: values.table ?? options.table,
|
|
142
|
+
});
|
|
143
|
+
try {
|
|
144
|
+
switch (command) {
|
|
145
|
+
case "up":
|
|
146
|
+
await migrator.up({ step: parseStep(values.step) });
|
|
147
|
+
return 0;
|
|
148
|
+
case "down":
|
|
149
|
+
await migrator.down({ step: parseStep(values.step) });
|
|
150
|
+
return 0;
|
|
151
|
+
case "status":
|
|
152
|
+
printStatus(await migrator.status());
|
|
153
|
+
return 0;
|
|
154
|
+
case "baseline":
|
|
155
|
+
if (!rest[0])
|
|
156
|
+
throw new Error("Usage: glfr-migrate baseline <version>");
|
|
157
|
+
await migrator.baseline(rest[0]);
|
|
158
|
+
return 0;
|
|
159
|
+
default:
|
|
160
|
+
console.error(`Unknown command "${command}"\n`);
|
|
161
|
+
console.log(USAGE);
|
|
162
|
+
return 1;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
await migrator.close();
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
exports.runCli = runCli;
|
|
170
|
+
if (typeof require !== "undefined" && require.main === module) {
|
|
171
|
+
(0, exports.runCli)().then((code) => {
|
|
172
|
+
process.exitCode = code;
|
|
173
|
+
}, (error) => {
|
|
174
|
+
console.error(error instanceof Error ? `Migration failed: ${error.message}` : error);
|
|
175
|
+
const cause = error instanceof Error ? error.cause : undefined;
|
|
176
|
+
if (cause instanceof Error &&
|
|
177
|
+
!error.message.includes(cause.message))
|
|
178
|
+
console.error(cause);
|
|
179
|
+
process.exitCode = 1;
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=cli.js.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xE,MAAM,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;gBACjC,OAAO,CAAC,CAAC;YACX;gBACE,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,KAAK,CAAC,CAAC;gBAChD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACnB,OAAO,CAAC,CAAC;QACb,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;AACH,CAAC,CAAC;AApEW,QAAA,MAAM,UAoEjB;AAEF,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC9D,IAAA,cAAM,GAAE,CAAC,IAAI,CACX,CAAC,IAAI,EAAE,EAAE;QACP,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC1B,CAAC,EACD,CAAC,KAAc,EAAE,EAAE;QACjB,OAAO,CAAC,KAAK,CACX,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,qBAAqB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CACtE,CAAC;QACF,MAAM,KAAK,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;QAC/D,IACE,KAAK,YAAY,KAAK;YACtB,CAAE,KAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC;YAEjD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACvB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CACF,CAAC;AACJ,CAAC"}
|
package/dist/files.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MigrationFile } from "./types";
|
|
2
|
+
export declare const parseMigrationFilename: (filename: string) => Omit<MigrationFile, "path"> | null;
|
|
3
|
+
/** Lists migration files sorted by version. Throws on malformed names and duplicate versions. */
|
|
4
|
+
export declare const discoverMigrations: (dir: string) => MigrationFile[];
|
|
5
|
+
export declare const checksumFile: (filePath: string) => string;
|
|
6
|
+
export declare const formatVersion: (date: Date) => string;
|
|
7
|
+
export declare const toSnakeCase: (value: string) => string;
|
|
8
|
+
/** Writes a new migration file and returns its path. Bumps the timestamp if the version is taken. */
|
|
9
|
+
export declare const createMigrationFile: (dir: string, description: string, now?: Date) => string;
|
package/dist/files.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createMigrationFile = exports.toSnakeCase = exports.formatVersion = exports.checksumFile = exports.discoverMigrations = exports.parseMigrationFilename = void 0;
|
|
37
|
+
const node_crypto_1 = require("node:crypto");
|
|
38
|
+
const fs = __importStar(require("node:fs"));
|
|
39
|
+
const path = __importStar(require("node:path"));
|
|
40
|
+
const MIGRATION_EXTENSIONS = [".ts", ".mts", ".cts", ".js", ".mjs", ".cjs"];
|
|
41
|
+
const FILENAME_PATTERN = /^(\d{14})_([a-z0-9_]+)\.(?:ts|mts|cts|js|mjs|cjs)$/;
|
|
42
|
+
const isIgnored = (filename) => filename.startsWith(".") ||
|
|
43
|
+
/\.d\.[mc]?ts$/.test(filename) ||
|
|
44
|
+
/\.(test|spec)\.[mc]?[jt]s$/.test(filename) ||
|
|
45
|
+
!MIGRATION_EXTENSIONS.includes(path.extname(filename));
|
|
46
|
+
const parseMigrationFilename = (filename) => {
|
|
47
|
+
const match = FILENAME_PATTERN.exec(filename);
|
|
48
|
+
if (!match)
|
|
49
|
+
return null;
|
|
50
|
+
return { version: match[1], name: match[2].replace(/_/g, " "), filename };
|
|
51
|
+
};
|
|
52
|
+
exports.parseMigrationFilename = parseMigrationFilename;
|
|
53
|
+
/** Lists migration files sorted by version. Throws on malformed names and duplicate versions. */
|
|
54
|
+
const discoverMigrations = (dir) => {
|
|
55
|
+
if (!fs.existsSync(dir))
|
|
56
|
+
return [];
|
|
57
|
+
const migrations = [];
|
|
58
|
+
const seen = new Map();
|
|
59
|
+
for (const filename of fs.readdirSync(dir).sort()) {
|
|
60
|
+
if (isIgnored(filename))
|
|
61
|
+
continue;
|
|
62
|
+
const parsed = (0, exports.parseMigrationFilename)(filename);
|
|
63
|
+
if (!parsed) {
|
|
64
|
+
throw new Error(`Invalid migration filename "${filename}" in ${dir}. Expected YYYYMMDDHHMMSS_snake_case_name.ts`);
|
|
65
|
+
}
|
|
66
|
+
const duplicate = seen.get(parsed.version);
|
|
67
|
+
if (duplicate) {
|
|
68
|
+
throw new Error(`Duplicate migration version ${parsed.version}: ${duplicate} and ${filename}`);
|
|
69
|
+
}
|
|
70
|
+
seen.set(parsed.version, filename);
|
|
71
|
+
migrations.push({ ...parsed, path: path.resolve(dir, filename) });
|
|
72
|
+
}
|
|
73
|
+
return migrations.sort((a, b) => a.version.localeCompare(b.version));
|
|
74
|
+
};
|
|
75
|
+
exports.discoverMigrations = discoverMigrations;
|
|
76
|
+
const checksumFile = (filePath) => (0, node_crypto_1.createHash)("sha256").update(fs.readFileSync(filePath)).digest("hex");
|
|
77
|
+
exports.checksumFile = checksumFile;
|
|
78
|
+
const formatVersion = (date) => date.toISOString().replace(/\D/g, "").slice(0, 14);
|
|
79
|
+
exports.formatVersion = formatVersion;
|
|
80
|
+
const toSnakeCase = (value) => value
|
|
81
|
+
.toLowerCase()
|
|
82
|
+
.replace(/[^a-z0-9]+/g, "_")
|
|
83
|
+
.replace(/^_|_$/g, "");
|
|
84
|
+
exports.toSnakeCase = toSnakeCase;
|
|
85
|
+
const TEMPLATE = `import type { MigrationTask } from "@ingeniumgolf/migrations";
|
|
86
|
+
|
|
87
|
+
export const up = async (t: MigrationTask): Promise<void> => {
|
|
88
|
+
await t.none(\`--sql
|
|
89
|
+
-- TODO
|
|
90
|
+
\`);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const down = async (t: MigrationTask): Promise<void> => {
|
|
94
|
+
await t.none(\`--sql
|
|
95
|
+
-- TODO
|
|
96
|
+
\`);
|
|
97
|
+
};
|
|
98
|
+
`;
|
|
99
|
+
/** Writes a new migration file and returns its path. Bumps the timestamp if the version is taken. */
|
|
100
|
+
const createMigrationFile = (dir, description, now = new Date()) => {
|
|
101
|
+
const name = (0, exports.toSnakeCase)(description);
|
|
102
|
+
if (!name)
|
|
103
|
+
throw new Error("Migration description must contain at least one letter or digit");
|
|
104
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
105
|
+
const taken = new Set((0, exports.discoverMigrations)(dir).map((m) => m.version));
|
|
106
|
+
let timestamp = now.getTime();
|
|
107
|
+
while (taken.has((0, exports.formatVersion)(new Date(timestamp))))
|
|
108
|
+
timestamp += 1000;
|
|
109
|
+
const filePath = path.resolve(dir, `${(0, exports.formatVersion)(new Date(timestamp))}_${name}.ts`);
|
|
110
|
+
fs.writeFileSync(filePath, TEMPLATE, { flag: "wx" });
|
|
111
|
+
return filePath;
|
|
112
|
+
};
|
|
113
|
+
exports.createMigrationFile = createMigrationFile;
|
|
114
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAyC;AACzC,4CAA8B;AAC9B,gDAAkC;AAGlC,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAC5E,MAAM,gBAAgB,GAAG,oDAAoD,CAAC;AAE9E,MAAM,SAAS,GAAG,CAAC,QAAgB,EAAW,EAAE,CAC9C,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC;IACxB,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC;IAC9B,4BAA4B,CAAC,IAAI,CAAC,QAAQ,CAAC;IAC3C,CAAC,oBAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AAElD,MAAM,sBAAsB,GAAG,CACpC,QAAgB,EACoB,EAAE;IACtC,MAAM,KAAK,GAAG,gB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AE,IAAI,EAAE,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,IAAA,0BAAkB,EAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IAErE,IAAI,SAAS,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;IAC9B,OAAO,KAAK,CAAC,GAAG,CAAC,IAAA,qBAAa,EAAC,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;QAAE,SAAS,IAAI,IAAI,CAAC;IAExE,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAC3B,GAAG,EACH,GAAG,IAAA,qBAAa,EAAC,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,IAAI,KAAK,CACnD,CAAC;IACF,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACrD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAvBW,QAAA,mBAAmB,uBAuB9B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Migrator } from "./migrator";
|
|
2
|
+
export { runCli } from "./cli";
|
|
3
|
+
export type { CliOptions } from "./cli";
|
|
4
|
+
export { createMigrationFile, discoverMigrations, parseMigrationFilename, } from "./files";
|
|
5
|
+
export type { AppliedMigration, ConnectionOptions, Logger, MigrationFile, MigrationModule, MigrationState, MigrationStatus, MigrationTask, MigratorOptions, } from "./types";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseMigrationFilename = exports.discoverMigrations = exports.createMigrationFile = exports.runCli = exports.Migrator = void 0;
|
|
4
|
+
var migrator_1 = require("./migrator");
|
|
5
|
+
Object.defineProperty(exports, "Migrator", { enumerable: true, get: function () { return migrator_1.Migrator; } });
|
|
6
|
+
var cli_1 = require("./cli");
|
|
7
|
+
Object.defineProperty(exports, "runCli", { enumerable: true, get: function () { return cli_1.runCli; } });
|
|
8
|
+
var files_1 = require("./files");
|
|
9
|
+
Object.defineProperty(exports, "createMigrationFile", { enumerable: true, get: function () { return files_1.createMigrationFile; } });
|
|
10
|
+
Object.defineProperty(exports, "discoverMigrations", { enumerable: true, get: function () { return files_1.discoverMigrations; } });
|
|
11
|
+
Object.defineProperty(exports, "parseMigrationFilename", { enumerable: true, get: function () { return files_1.parseMigrationFilename; } });
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,6BAA+B;AAAtB,6FAAA,MAAM,OAAA;AAEf,iCAIiB;AAHf,4GAAA,mBAAmB,OAAA;AACnB,2GAAA,kBAAkB,OAAA;AAClB,+GAAA,sBAAsB,OAAA"}
|
package/dist/loader.d.ts
ADDED
package/dist/loader.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadMigration = void 0;
|
|
4
|
+
const node_module_1 = require("node:module");
|
|
5
|
+
const node_url_1 = require("node:url");
|
|
6
|
+
const ESM_FALLBACK_CODES = new Set([
|
|
7
|
+
"ERR_REQUIRE_ESM",
|
|
8
|
+
"ERR_REQUIRE_ASYNC_MODULE",
|
|
9
|
+
"ERR_UNKNOWN_FILE_EXTENSION",
|
|
10
|
+
]);
|
|
11
|
+
// require() parsed ESM/TypeScript syntax as plain CommonJS (no type stripping or loader available)
|
|
12
|
+
const UNPARSED_MODULE_SYNTAX = /Cannot use import statement|Unexpected token 'export'|Unexpected token ':'|Missing initializer/;
|
|
13
|
+
const shouldTryImport = (error) => (error instanceof SyntaxError &&
|
|
14
|
+
UNPARSED_MODULE_SYNTAX.test(error.message)) ||
|
|
15
|
+
ESM_FALLBACK_CODES.has(error?.code ?? "");
|
|
16
|
+
const describeLoadError = (filePath, error) => {
|
|
17
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
18
|
+
const hint = /does not provide an export named/.test(message)
|
|
19
|
+
? " Use `import type` for type-only imports such as MigrationTask."
|
|
20
|
+
: /\.[mc]?ts$/.test(filePath)
|
|
21
|
+
? " TypeScript migrations need Node >= 22.18 (native type stripping) or a TypeScript loader such as tsx or ts-node."
|
|
22
|
+
: "";
|
|
23
|
+
return new Error(`Could not load migration ${filePath}: ${message}.${hint}`, {
|
|
24
|
+
cause: error,
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const importModule = async (filePath) => {
|
|
28
|
+
try {
|
|
29
|
+
// require() first so TypeScript loaders hooked into require (ts-node, tsx) handle .ts files
|
|
30
|
+
return (0, node_module_1.createRequire)(filePath)(filePath);
|
|
31
|
+
}
|
|
32
|
+
catch (requireError) {
|
|
33
|
+
if (!shouldTryImport(requireError))
|
|
34
|
+
throw describeLoadError(filePath, requireError);
|
|
35
|
+
try {
|
|
36
|
+
return (await import((0, node_url_1.pathToFileURL)(filePath).href));
|
|
37
|
+
}
|
|
38
|
+
catch (importError) {
|
|
39
|
+
throw describeLoadError(filePath, importError);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const loadMigration = async (filePath) => {
|
|
44
|
+
const loaded = await importModule(filePath);
|
|
45
|
+
const candidate = (typeof loaded.up === "function" ? loaded : loaded.default);
|
|
46
|
+
if (typeof candidate?.up !== "function") {
|
|
47
|
+
throw new Error(`Migration ${filePath} must export an async up(t) function`);
|
|
48
|
+
}
|
|
49
|
+
if (candidate.down !== undefined && typeof candidate.down !== "function") {
|
|
50
|
+
throw new Error(`Migration ${filePath} exports a down that is not a function`);
|
|
51
|
+
}
|
|
52
|
+
return candidate;
|
|
53
|
+
};
|
|
54
|
+
exports.loadMigration = loadMigration;
|
|
55
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAC5C,uCAAyC;AAGzC,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,iBAAiB;IACjB,0BAA0B;IAC1B,4BAA4B;CAC7B,CAAC,CAAC;AACH,mGAAmG;AACnG,MAAM,sBAAsB,GAC1B,gGAAgG,CAAC;AAEnG,MAAM,eAAe,GAAG,CAAC,KAAc,EAAW,EAAE,CAClD,CAAC,KAAK,YAAY,WAAW;IAC3B,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7C,kBAAkB,CAAC,GAAG,CACnB,KAA2C,EAAE,IAAI,IAAI,EAAE,CACzD,CAAC;AAEJ,MAAM,iBAAiB,GAAG,CAAC,QAAgB,EAAE,KAAc,EAAS,EAAE;IACpE,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,MAAM,IAAI,GAAG,kCAAkC,CAAC,IAAI,CAAC,OAAO,CAAC;QAC3D,CAAC,CAAC,iEAAiE;QACnE,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC;YAC3B,CAAC,CAAC,kHAAkH;YACpH,CAAC,CAAC,EAAE,CAAC;IACT,OAAO,IAAI,KAAK,CAAC,4BAA4B,QAAQ,KAAK,OAAO,IAAI,IAAI,EAAE,EAAE;QAC3E,KAAK,EAAE,KAAK;KACb,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,KAAK,EACxB,QAAgB,EACkB,EAAE;IACpC,IAAI,CAAC;QACH,4FAA4F;QAC5F,OAAO,IAAA,2BAAa,EAAC,QAAQ,CAAC,CAAC,QAAQ,CAA4B,CAAC;IACtE,CAAC;IAAC,OAAO,YAAY,EAAE,CAAC;QACtB,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC;YAChC,MAAM,iBAAiB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAClD,IAAI,CAAC;YACH,OAAO,CAAC,MAAM,MAAM,CAAC,IAAA,wBAAa,EAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAGjD,CAAC;QACJ,CAAC;QAAC,OAAO,WAAW,EAAE,CAAC;YACrB,MAAM,iBAAiB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEK,MAAM,aAAa,GAAG,KAAK,EAChC,QAAgB,EACU,EAAE;IAC5B,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,SAAS,GAAG,CAChB,OAAO,MAAM,CAAC,EAAE,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAClB,CAAC;IAE1C,IAAI,OAAO,SAAS,EAAE,EAAE,KAAK,UAAU,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CACb,aAAa,QAAQ,sCAAsC,CAC5D,CAAC;IACJ,CAAC;IACD,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,SAAS,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACzE,MAAM,IAAI,KAAK,CACb,aAAa,QAAQ,wCAAwC,CAC9D,CAAC;IACJ,CAAC;IAED,OAAO,SAA4B,CAAC;AACtC,CAAC,CAAC;AApBW,QAAA,aAAa,iBAoBxB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AppliedMigration, MigrationFile, MigrationStatus, MigratorOptions } from "./types";
|
|
2
|
+
export declare class Migrator {
|
|
3
|
+
private readonly pgp;
|
|
4
|
+
private readonly db;
|
|
5
|
+
private readonly dir;
|
|
6
|
+
private readonly table;
|
|
7
|
+
private readonly tableSql;
|
|
8
|
+
private readonly logger;
|
|
9
|
+
constructor(options: MigratorOptions);
|
|
10
|
+
/** Read-only: does not create the bookkeeping table or take the lock. */
|
|
11
|
+
status(): Promise<MigrationStatus[]>;
|
|
12
|
+
/** Applies pending migrations in version order. Returns the migrations that were applied. */
|
|
13
|
+
up(options?: {
|
|
14
|
+
step?: number;
|
|
15
|
+
}): Promise<MigrationFile[]>;
|
|
16
|
+
/** Rolls back the most recently applied migrations. Returns the migrations that were rolled back. */
|
|
17
|
+
down(options?: {
|
|
18
|
+
step?: number;
|
|
19
|
+
}): Promise<AppliedMigration[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Records every migration up to and including `version` as applied without running it.
|
|
22
|
+
* Use when adopting the runner on a database whose schema already exists.
|
|
23
|
+
*/
|
|
24
|
+
baseline(version: string): Promise<MigrationFile[]>;
|
|
25
|
+
/** Closes this migrator's connection pool. */
|
|
26
|
+
close(): Promise<void>;
|
|
27
|
+
private withLock;
|
|
28
|
+
private readApplied;
|
|
29
|
+
private recordApplied;
|
|
30
|
+
}
|
package/dist/migrator.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Migrator = void 0;
|
|
7
|
+
const pg_promise_1 = __importDefault(require("pg-promise"));
|
|
8
|
+
const files_1 = require("./files");
|
|
9
|
+
const loader_1 = require("./loader");
|
|
10
|
+
const DEFAULT_TABLE = "glfr_migrations";
|
|
11
|
+
const IDENTIFIER = /^[a-z_][a-z0-9_]*$/;
|
|
12
|
+
const VERSION = /^\d{14}$/;
|
|
13
|
+
const consoleLogger = {
|
|
14
|
+
info: (message) => console.log(message),
|
|
15
|
+
warn: (message) => console.warn(message),
|
|
16
|
+
};
|
|
17
|
+
const toApplied = (row) => ({
|
|
18
|
+
version: row.version,
|
|
19
|
+
name: row.name,
|
|
20
|
+
filename: row.filename,
|
|
21
|
+
checksum: row.checksum,
|
|
22
|
+
appliedAt: row.applied_at,
|
|
23
|
+
});
|
|
24
|
+
class Migrator {
|
|
25
|
+
pgp;
|
|
26
|
+
db;
|
|
27
|
+
dir;
|
|
28
|
+
table;
|
|
29
|
+
tableSql;
|
|
30
|
+
logger;
|
|
31
|
+
constructor(options) {
|
|
32
|
+
this.table = options.table ?? DEFAULT_TABLE;
|
|
33
|
+
const parts = this.table.split(".");
|
|
34
|
+
if (parts.length > 2 || !parts.every((part) => IDENTIFIER.test(part))) {
|
|
35
|
+
throw new Error(`Invalid migrations table name "${this.table}"`);
|
|
36
|
+
}
|
|
37
|
+
this.pgp = (0, pg_promise_1.default)();
|
|
38
|
+
this.tableSql = parts.map((part) => this.pgp.as.name(part)).join(".");
|
|
39
|
+
this.db = this.pgp(options.connection);
|
|
40
|
+
this.dir = options.dir;
|
|
41
|
+
this.logger = options.logger ?? consoleLogger;
|
|
42
|
+
}
|
|
43
|
+
/** Read-only: does not create the bookkeeping table or take the lock. */
|
|
44
|
+
async status() {
|
|
45
|
+
const applied = await this.db.task((t) => this.readApplied(t));
|
|
46
|
+
const appliedByVersion = new Map(applied.map((m) => [m.version, m]));
|
|
47
|
+
const files = (0, files_1.discoverMigrations)(this.dir);
|
|
48
|
+
const fileVersions = new Set(files.map((f) => f.version));
|
|
49
|
+
const statuses = files.map((file) => {
|
|
50
|
+
const row = appliedByVersion.get(file.version);
|
|
51
|
+
if (!row)
|
|
52
|
+
return {
|
|
53
|
+
version: file.version,
|
|
54
|
+
name: file.name,
|
|
55
|
+
filename: file.filename,
|
|
56
|
+
state: "pending",
|
|
57
|
+
};
|
|
58
|
+
const modified = row.checksum !== null && row.checksum !== (0, files_1.checksumFile)(file.path);
|
|
59
|
+
return {
|
|
60
|
+
version: file.version,
|
|
61
|
+
name: file.name,
|
|
62
|
+
filename: file.filename,
|
|
63
|
+
state: modified ? "modified" : "applied",
|
|
64
|
+
appliedAt: row.appliedAt,
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
for (const row of applied) {
|
|
68
|
+
if (!fileVersions.has(row.version)) {
|
|
69
|
+
statuses.push({
|
|
70
|
+
version: row.version,
|
|
71
|
+
name: row.name,
|
|
72
|
+
filename: row.filename,
|
|
73
|
+
state: "missing",
|
|
74
|
+
appliedAt: row.appliedAt,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return statuses.sort((a, b) => a.version.localeCompare(b.version));
|
|
79
|
+
}
|
|
80
|
+
/** Applies pending migrations in version order. Returns the migrations that were applied. */
|
|
81
|
+
async up(options = {}) {
|
|
82
|
+
return this.withLock(async (t) => {
|
|
83
|
+
const applied = await this.readApplied(t);
|
|
84
|
+
const appliedVersions = new Set(applied.map((m) => m.version));
|
|
85
|
+
const latestApplied = applied.at(-1)?.version;
|
|
86
|
+
const pending = (0, files_1.discoverMigrations)(this.dir).filter((m) => !appliedVersions.has(m.version));
|
|
87
|
+
const toRun = options.step === undefined ? pending : pending.slice(0, options.step);
|
|
88
|
+
if (toRun.length === 0) {
|
|
89
|
+
this.logger.info("No pending migrations");
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
for (const migration of toRun) {
|
|
93
|
+
const outOfOrder = latestApplied !== undefined && migration.version < latestApplied;
|
|
94
|
+
this.logger.info(`Applying ${migration.filename}${outOfOrder ? " (out of order)" : ""}`);
|
|
95
|
+
const started = Date.now();
|
|
96
|
+
const module = await (0, loader_1.loadMigration)(migration.path);
|
|
97
|
+
const checksum = (0, files_1.checksumFile)(migration.path);
|
|
98
|
+
const apply = async (task) => {
|
|
99
|
+
await module.up(task);
|
|
100
|
+
await this.recordApplied(task, migration, checksum);
|
|
101
|
+
};
|
|
102
|
+
if (module.transaction === false) {
|
|
103
|
+
await apply(t);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
await t.tx(apply);
|
|
107
|
+
}
|
|
108
|
+
this.logger.info(` ✓ ${migration.filename} (${Date.now() - started} ms)`);
|
|
109
|
+
}
|
|
110
|
+
return toRun;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/** Rolls back the most recently applied migrations. Returns the migrations that were rolled back. */
|
|
114
|
+
async down(options = {}) {
|
|
115
|
+
const step = options.step ?? 1;
|
|
116
|
+
return this.withLock(async (t) => {
|
|
117
|
+
const applied = await this.readApplied(t);
|
|
118
|
+
const toRollback = applied.slice(-step).reverse();
|
|
119
|
+
if (toRollback.length === 0) {
|
|
120
|
+
this.logger.info("No migrations to roll back");
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
const filesByVersion = new Map((0, files_1.discoverMigrations)(this.dir).map((m) => [m.version, m]));
|
|
124
|
+
for (const migration of toRollback) {
|
|
125
|
+
const file = filesByVersion.get(migration.version);
|
|
126
|
+
if (!file)
|
|
127
|
+
throw new Error(`Cannot roll back ${migration.filename}: migration file not found`);
|
|
128
|
+
const module = await (0, loader_1.loadMigration)(file.path);
|
|
129
|
+
const down = module.down;
|
|
130
|
+
if (!down)
|
|
131
|
+
throw new Error(`Cannot roll back ${file.filename}: it does not export down()`);
|
|
132
|
+
this.logger.info(`Rolling back ${file.filename}`);
|
|
133
|
+
const revert = async (task) => {
|
|
134
|
+
await down(task);
|
|
135
|
+
await task.none(`DELETE FROM ${this.tableSql} WHERE version = $1`, [
|
|
136
|
+
migration.version,
|
|
137
|
+
]);
|
|
138
|
+
};
|
|
139
|
+
if (module.transaction === false) {
|
|
140
|
+
await revert(t);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
await t.tx(revert);
|
|
144
|
+
}
|
|
145
|
+
this.logger.info(` ✓ ${file.filename}`);
|
|
146
|
+
}
|
|
147
|
+
return toRollback;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Records every migration up to and including `version` as applied without running it.
|
|
152
|
+
* Use when adopting the runner on a database whose schema already exists.
|
|
153
|
+
*/
|
|
154
|
+
async baseline(version) {
|
|
155
|
+
if (!VERSION.test(version))
|
|
156
|
+
throw new Error(`Invalid version "${version}", expected YYYYMMDDHHMMSS`);
|
|
157
|
+
const files = (0, files_1.discoverMigrations)(this.dir);
|
|
158
|
+
if (!files.some((m) => m.version === version)) {
|
|
159
|
+
throw new Error(`No migration file with version ${version} in ${this.dir}`);
|
|
160
|
+
}
|
|
161
|
+
return this.withLock(async (t) => {
|
|
162
|
+
const appliedVersions = new Set((await this.readApplied(t)).map((m) => m.version));
|
|
163
|
+
const toRecord = files.filter((m) => m.version <= version && !appliedVersions.has(m.version));
|
|
164
|
+
await t.tx(async (tx) => {
|
|
165
|
+
for (const migration of toRecord) {
|
|
166
|
+
await this.recordApplied(tx, migration, (0, files_1.checksumFile)(migration.path));
|
|
167
|
+
this.logger.info(` ✓ Baselined ${migration.filename}`);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
if (toRecord.length === 0)
|
|
171
|
+
this.logger.info("Nothing to baseline");
|
|
172
|
+
return toRecord;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/** Closes this migrator's connection pool. */
|
|
176
|
+
async close() {
|
|
177
|
+
await this.db.$pool.end();
|
|
178
|
+
}
|
|
179
|
+
async withLock(fn) {
|
|
180
|
+
const lockKey = `glfr-migrations:${this.table}`;
|
|
181
|
+
return this.db.task(async (t) => {
|
|
182
|
+
// Session-level lock: concurrent runs (e.g. parallel deploys) wait instead of racing
|
|
183
|
+
await t.one("SELECT pg_advisory_lock(hashtext($1))", [lockKey]);
|
|
184
|
+
try {
|
|
185
|
+
await t.none(`
|
|
186
|
+
CREATE TABLE IF NOT EXISTS ${this.tableSql} (
|
|
187
|
+
version VARCHAR(14) PRIMARY KEY,
|
|
188
|
+
name TEXT NOT NULL,
|
|
189
|
+
filename TEXT NOT NULL,
|
|
190
|
+
checksum CHAR(64),
|
|
191
|
+
applied_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
192
|
+
)
|
|
193
|
+
`);
|
|
194
|
+
return await fn(t);
|
|
195
|
+
}
|
|
196
|
+
finally {
|
|
197
|
+
await t.one("SELECT pg_advisory_unlock(hashtext($1))", [lockKey]);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
async readApplied(t) {
|
|
202
|
+
const exists = await t.one("SELECT to_regclass($1) IS NOT NULL AS exists", [this.tableSql]);
|
|
203
|
+
if (!exists.exists)
|
|
204
|
+
return [];
|
|
205
|
+
const rows = await t.any(`SELECT version, name, filename, checksum, applied_at FROM ${this.tableSql} ORDER BY version`);
|
|
206
|
+
return rows.map(toApplied);
|
|
207
|
+
}
|
|
208
|
+
async recordApplied(t, migration, checksum) {
|
|
209
|
+
await t.none(`INSERT INTO ${this.tableSql} (version, name, filename, checksum) VALUES ($1, $2, $3, $4)`, [migration.version, migration.name, migration.filename, checksum]);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
exports.Migrator = Migrator;
|
|
213
|
+
//# sourceMappingURL=migrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrator.js","sourceRoot":"","sources":["../src/migrator.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAmC;AAEnC,mCAA2D;AAC3D,qCAAyC;AAUzC,MAAM,aAAa,GAAG,iBAAiB,CAAC;AACxC,MAAM,UAAU,GAAG,oBAAoB,CAAC;AACxC,MAAM,OAAO,GAAG,UAAU,CAAC;AAE3B,MAAM,aAAa,GAAW;IAC5B,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;IACvC,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;CACzC,CAAC;AAUF,MAAM,SAAS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a transaction unless the migration opts out. */
|
|
3
|
+
export type MigrationTask = ITask<unknown>;
|
|
4
|
+
export type ConnectionOptions = Parameters<IMain>[0];
|
|
5
|
+
export interface MigrationModule {
|
|
6
|
+
up: (t: MigrationTask) => Promise<void>;
|
|
7
|
+
down?: (t: MigrationTask) => Promise<void>;
|
|
8
|
+
/** Set to `false` for statements that cannot run in a transaction, e.g. `CREATE INDEX CONCURRENTLY`. */
|
|
9
|
+
transaction?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface MigrationFile {
|
|
12
|
+
/** 14-digit UTC timestamp, `YYYYMMDDHHMMSS`. */
|
|
13
|
+
version: string;
|
|
14
|
+
name: string;
|
|
15
|
+
filename: string;
|
|
16
|
+
path: string;
|
|
17
|
+
}
|
|
18
|
+
export interface AppliedMigration {
|
|
19
|
+
version: string;
|
|
20
|
+
name: string;
|
|
21
|
+
filename: string;
|
|
22
|
+
checksum: string | null;
|
|
23
|
+
appliedAt: Date;
|
|
24
|
+
}
|
|
25
|
+
export type MigrationState = "applied" | "pending" | "modified" | "missing";
|
|
26
|
+
export interface MigrationStatus {
|
|
27
|
+
version: string;
|
|
28
|
+
name: string;
|
|
29
|
+
filename: string;
|
|
30
|
+
state: MigrationState;
|
|
31
|
+
appliedAt?: Date;
|
|
32
|
+
}
|
|
33
|
+
export interface Logger {
|
|
34
|
+
info: (message: string) => void;
|
|
35
|
+
warn: (message: string) => void;
|
|
36
|
+
}
|
|
37
|
+
export interface MigratorOptions {
|
|
38
|
+
/** Connection string or pg-promise connection object. */
|
|
39
|
+
connection: ConnectionOptions;
|
|
40
|
+
/** Directory containing the migration files. */
|
|
41
|
+
dir: string;
|
|
42
|
+
/** Bookkeeping table, optionally schema-qualified. Defaults to `glfr_migrations`. */
|
|
43
|
+
table?: string;
|
|
44
|
+
logger?: Logger;
|
|
45
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ingeniumgolf/migrations",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Small, SQL-first PostgreSQL migration runner built on pg-promise",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Ingenium Golf <developer@glfr.com>",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/IngeniumGolf/glfr-migrations.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/IngeniumGolf/glfr-migrations#readme",
|
|
12
|
+
"bugs": "https://github.com/IngeniumGolf/glfr-migrations/issues",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"postgres",
|
|
15
|
+
"postgresql",
|
|
16
|
+
"migrations",
|
|
17
|
+
"pg-promise"
|
|
18
|
+
],
|
|
19
|
+
"main": "dist/index.js",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"bin": {
|
|
22
|
+
"glfr-migrate": "dist/cli.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=22.18"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"packageManager": "pnpm@10.19.0",
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
36
|
+
"typecheck": "tsc --noEmit",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"test:db": "docker compose up -d --wait",
|
|
39
|
+
"prepublishOnly": "pnpm typecheck && pnpm build"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"pg-promise": "^12.7.1"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^22.20.5",
|
|
46
|
+
"typescript": "^5.9.3",
|
|
47
|
+
"vitest": "^5.0.3"
|
|
48
|
+
},
|
|
49
|
+
"pnpm": {
|
|
50
|
+
"onlyBuiltDependencies": [
|
|
51
|
+
"esbuild"
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
}
|