@venturekit/data 0.0.0-dev.20260427222834 → 0.0.0-dev.20260429113801
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 +9 -5
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/migrations/dispatcher.d.ts +35 -0
- package/dist/migrations/dispatcher.d.ts.map +1 -0
- package/dist/migrations/dispatcher.js +71 -0
- package/dist/migrations/dispatcher.js.map +1 -0
- package/dist/migrations/env.d.ts +12 -0
- package/dist/migrations/env.d.ts.map +1 -0
- package/dist/migrations/env.js +12 -0
- package/dist/migrations/env.js.map +1 -0
- package/dist/migrations/errors.d.ts +33 -0
- package/dist/migrations/errors.d.ts.map +1 -0
- package/dist/migrations/errors.js +48 -0
- package/dist/migrations/errors.js.map +1 -0
- package/dist/migrations/index.d.ts +31 -10
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +33 -11
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/runners/custom.d.ts +72 -0
- package/dist/migrations/runners/custom.d.ts.map +1 -0
- package/dist/migrations/runners/custom.js +167 -0
- package/dist/migrations/runners/custom.js.map +1 -0
- package/dist/migrations/runners/drizzle.d.ts +12 -0
- package/dist/migrations/runners/drizzle.d.ts.map +1 -0
- package/dist/migrations/runners/drizzle.js +17 -0
- package/dist/migrations/runners/drizzle.js.map +1 -0
- package/dist/migrations/runners/flyway.d.ts +14 -0
- package/dist/migrations/runners/flyway.d.ts.map +1 -0
- package/dist/migrations/runners/flyway.js +20 -0
- package/dist/migrations/runners/flyway.js.map +1 -0
- package/dist/migrations/runners/golang-migrate.d.ts +8 -0
- package/dist/migrations/runners/golang-migrate.d.ts.map +1 -0
- package/dist/migrations/runners/golang-migrate.js +13 -0
- package/dist/migrations/runners/golang-migrate.js.map +1 -0
- package/dist/migrations/runners/prisma.d.ts +10 -0
- package/dist/migrations/runners/prisma.d.ts.map +1 -0
- package/dist/migrations/runners/prisma.js +15 -0
- package/dist/migrations/runners/prisma.js.map +1 -0
- package/dist/migrations/seeds.d.ts +39 -0
- package/dist/migrations/seeds.d.ts.map +1 -0
- package/dist/migrations/seeds.js +50 -0
- package/dist/migrations/seeds.js.map +1 -0
- package/dist/migrations/types.d.ts +48 -0
- package/dist/migrations/types.d.ts.map +1 -0
- package/dist/migrations/types.js +9 -0
- package/dist/migrations/types.js.map +1 -0
- package/dist/query/index.d.ts +6 -4
- package/dist/query/index.d.ts.map +1 -1
- package/dist/query/index.js +4 -4
- package/dist/query/index.js.map +1 -1
- package/dist/query/mapper.d.ts +63 -11
- package/dist/query/mapper.d.ts.map +1 -1
- package/dist/query/mapper.js +76 -16
- package/dist/query/mapper.js.map +1 -1
- package/dist/query/pool.d.ts +15 -2
- package/dist/query/pool.d.ts.map +1 -1
- package/dist/query/pool.js +52 -2
- package/dist/query/pool.js.map +1 -1
- package/dist/query/transaction.d.ts +17 -1
- package/dist/query/transaction.d.ts.map +1 -1
- package/dist/query/transaction.js +2 -2
- package/dist/query/transaction.js.map +1 -1
- package/dist/types/migration.d.ts +11 -6
- package/dist/types/migration.d.ts.map +1 -1
- package/dist/types/migration.js +11 -6
- package/dist/types/migration.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -89,15 +89,19 @@ const rdsConfig = createRdsConfig({
|
|
|
89
89
|
|
|
90
90
|
## Migrations
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
`@venturekit/data` ships a pure-SQL migration runner. Drop `.sql` files
|
|
93
|
+
into `db/migrations/` and apply them with the CLI:
|
|
93
94
|
|
|
94
95
|
```bash
|
|
95
|
-
vk migrate
|
|
96
|
-
vk migrate
|
|
97
|
-
vk migrate status #
|
|
98
|
-
vk migrate studio # Open Drizzle Studio GUI
|
|
96
|
+
vk migrate # Apply pending schema migrations
|
|
97
|
+
vk migrate --seed # Apply migrations, then seeds from db/seeds/
|
|
98
|
+
vk migrate status # Show which migrations and seeds have been applied
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
+
Applied files are tracked in `__vk_migrations` / `__vk_seeds`. The
|
|
102
|
+
file-content hash is locked once recorded — editing an applied file
|
|
103
|
+
hard-fails on the next run; write a new migration instead.
|
|
104
|
+
|
|
101
105
|
## API Reference
|
|
102
106
|
|
|
103
107
|
See the [API reference](https://venturekit.dev/api-reference/data) for full documentation.
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
export * from './types/index.js';
|
|
7
7
|
export { createRdsConfig, DEFAULT_RDS_CONFIG, buildRdsConfig, } from './rds/index.js';
|
|
8
8
|
export type { RdsOutputs, RdsInfraConfig } from './rds/index.js';
|
|
9
|
-
export { createMigrationConfig, DEFAULT_MIGRATION_CONFIG, getFlywayEnv, } from './migrations/index.js';
|
|
10
|
-
export {
|
|
11
|
-
export
|
|
9
|
+
export { createMigrationConfig, DEFAULT_MIGRATION_CONFIG, getFlywayEnv, runMigrations, getMigrationStatus, runSeeds, getSeedStatus, MIGRATIONS_TRACKING_TABLE, SEEDS_TRACKING_TABLE, MigrationToolNotImplementedError, MigrationHashMismatchError, applyDatabaseUrlToEnv, } from './migrations/index.js';
|
|
10
|
+
export type { RunResult, StatusEntry, RunOptions, SeedRunOptions, } from './migrations/index.js';
|
|
11
|
+
export { query, getPool, mapResults, mapRow, configureMapper, getMapperConfig, beginTransaction, withTransaction, buildTransaction, } from './query/index.js';
|
|
12
|
+
export type { Transaction, ResultsMapper, Querier, MapperOptions, } from './query/index.js';
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAKjE,OAAO,EAEL,qBAAqB,EACrB,wBAAwB,EACxB,YAAY,EAEZ,aAAa,EACb,kBAAkB,EAClB,QAAQ,EACR,aAAa,EACb,yBAAyB,EACzB,oBAAoB,EAEpB,gCAAgC,EAChC,0BAA0B,EAG1B,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,cAAc,GACf,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,KAAK,EACL,OAAO,EACP,UAAU,EACV,MAAM,EACN,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,WAAW,EACX,aAAa,EACb,OAAO,EACP,aAAa,GACd,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7,8 +7,19 @@
|
|
|
7
7
|
export * from './types/index.js';
|
|
8
8
|
// RDS
|
|
9
9
|
export { createRdsConfig, DEFAULT_RDS_CONFIG, buildRdsConfig, } from './rds/index.js';
|
|
10
|
-
// Migrations
|
|
11
|
-
|
|
10
|
+
// Migrations + seeds — bundled pure-SQL runner (`tool: 'custom'`) plus
|
|
11
|
+
// config helpers for integrating Flyway / Drizzle Kit / Prisma /
|
|
12
|
+
// golang-migrate from your own deploy pipeline.
|
|
13
|
+
export {
|
|
14
|
+
// config helpers (existing)
|
|
15
|
+
createMigrationConfig, DEFAULT_MIGRATION_CONFIG, getFlywayEnv,
|
|
16
|
+
// built-in runner — pure SQL, tracked in __vk_migrations / __vk_seeds
|
|
17
|
+
runMigrations, getMigrationStatus, runSeeds, getSeedStatus, MIGRATIONS_TRACKING_TABLE, SEEDS_TRACKING_TABLE,
|
|
18
|
+
// errors
|
|
19
|
+
MigrationToolNotImplementedError, MigrationHashMismatchError,
|
|
20
|
+
// env-var bridge: parses DATABASE_URL into the granular DB_* vars used
|
|
21
|
+
// by getPool(). Auto-applied at the top of runMigrations / runSeeds.
|
|
22
|
+
applyDatabaseUrlToEnv, } from './migrations/index.js';
|
|
12
23
|
// Query utility, result mapping, and transactions
|
|
13
|
-
export { query, getPool, mapResults, mapRow, beginTransaction, withTransaction, buildTransaction, } from './query/index.js';
|
|
24
|
+
export { query, getPool, mapResults, mapRow, configureMapper, getMapperConfig, beginTransaction, withTransaction, buildTransaction, } from './query/index.js';
|
|
14
25
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,QAAQ;AACR,cAAc,kBAAkB,CAAC;AAEjC,MAAM;AACN,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,cAAc,GACf,MAAM,gBAAgB,CAAC;AAGxB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,QAAQ;AACR,cAAc,kBAAkB,CAAC;AAEjC,MAAM;AACN,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,cAAc,GACf,MAAM,gBAAgB,CAAC;AAGxB,uEAAuE;AACvE,iEAAiE;AACjE,gDAAgD;AAChD,OAAO;AACL,4BAA4B;AAC5B,qBAAqB,EACrB,wBAAwB,EACxB,YAAY;AACZ,sEAAsE;AACtE,aAAa,EACb,kBAAkB,EAClB,QAAQ,EACR,aAAa,EACb,yBAAyB,EACzB,oBAAoB;AACpB,SAAS;AACT,gCAAgC,EAChC,0BAA0B;AAC1B,uEAAuE;AACvE,qEAAqE;AACrE,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAQ/B,kDAAkD;AAClD,OAAO,EACL,KAAK,EACL,OAAO,EACP,UAAU,EACV,MAAM,EACN,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,gBAAgB,GACjB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration runner dispatcher.
|
|
3
|
+
*
|
|
4
|
+
* Reads `MigrationConfig.tool` and routes to the matching runner. Only the
|
|
5
|
+
* `'custom'` runner (pure-SQL files, tracked in `__vk_migrations`) is
|
|
6
|
+
* implemented in this package today; the others throw a clear
|
|
7
|
+
* `MigrationToolNotImplementedError` pointing at the workaround.
|
|
8
|
+
*
|
|
9
|
+
* Kept in its own file so `migrations/index.ts` stays focused on its
|
|
10
|
+
* existing public-config helpers (`createMigrationConfig`, `getFlywayEnv`).
|
|
11
|
+
*/
|
|
12
|
+
import type { MigrationConfig } from '../types/migration.js';
|
|
13
|
+
import type { RunOptions, RunResult, StatusEntry } from './types.js';
|
|
14
|
+
/** Tracking-table name for migrations. Mirrors `__vk_seeds` for seeds. */
|
|
15
|
+
export declare const MIGRATIONS_TRACKING_TABLE = "__vk_migrations";
|
|
16
|
+
/**
|
|
17
|
+
* Apply pending schema migrations using the runner selected by
|
|
18
|
+
* `config.tool`.
|
|
19
|
+
*
|
|
20
|
+
* For `tool: 'custom'`, reads `*.sql` files from `config.migrationsDir`,
|
|
21
|
+
* applies the pending ones inside transactions, and tracks them in the
|
|
22
|
+
* `__vk_migrations` table.
|
|
23
|
+
*
|
|
24
|
+
* For other tools (`'drizzle'`, `'flyway'`, `'golang-migrate'`,
|
|
25
|
+
* `'prisma'`), throws `MigrationToolNotImplementedError` with a hint
|
|
26
|
+
* pointing at the workaround.
|
|
27
|
+
*/
|
|
28
|
+
export declare function runMigrations(config: MigrationConfig, opts?: RunOptions): Promise<RunResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Read-only counterpart of `runMigrations`. Returns one `StatusEntry` per
|
|
31
|
+
* `.sql` file in `config.migrationsDir`. Same dispatch rules as
|
|
32
|
+
* `runMigrations`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function getMigrationStatus(config: MigrationConfig): Promise<StatusEntry[]>;
|
|
35
|
+
//# sourceMappingURL=dispatcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/migrations/dispatcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAM7D,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAErE,0EAA0E;AAC1E,eAAO,MAAM,yBAAyB,oBAAoB,CAAC;AAE3D;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,eAAe,EACvB,IAAI,GAAE,UAAe,GACpB,OAAO,CAAC,SAAS,CAAC,CAiBpB;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,WAAW,EAAE,CAAC,CAgBxB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration runner dispatcher.
|
|
3
|
+
*
|
|
4
|
+
* Reads `MigrationConfig.tool` and routes to the matching runner. Only the
|
|
5
|
+
* `'custom'` runner (pure-SQL files, tracked in `__vk_migrations`) is
|
|
6
|
+
* implemented in this package today; the others throw a clear
|
|
7
|
+
* `MigrationToolNotImplementedError` pointing at the workaround.
|
|
8
|
+
*
|
|
9
|
+
* Kept in its own file so `migrations/index.ts` stays focused on its
|
|
10
|
+
* existing public-config helpers (`createMigrationConfig`, `getFlywayEnv`).
|
|
11
|
+
*/
|
|
12
|
+
import { runSqlFiles, getSqlFilesStatus } from './runners/custom.js';
|
|
13
|
+
import { drizzleNotImplemented } from './runners/drizzle.js';
|
|
14
|
+
import { flywayNotImplemented } from './runners/flyway.js';
|
|
15
|
+
import { golangMigrateNotImplemented } from './runners/golang-migrate.js';
|
|
16
|
+
import { prismaNotImplemented } from './runners/prisma.js';
|
|
17
|
+
/** Tracking-table name for migrations. Mirrors `__vk_seeds` for seeds. */
|
|
18
|
+
export const MIGRATIONS_TRACKING_TABLE = '__vk_migrations';
|
|
19
|
+
/**
|
|
20
|
+
* Apply pending schema migrations using the runner selected by
|
|
21
|
+
* `config.tool`.
|
|
22
|
+
*
|
|
23
|
+
* For `tool: 'custom'`, reads `*.sql` files from `config.migrationsDir`,
|
|
24
|
+
* applies the pending ones inside transactions, and tracks them in the
|
|
25
|
+
* `__vk_migrations` table.
|
|
26
|
+
*
|
|
27
|
+
* For other tools (`'drizzle'`, `'flyway'`, `'golang-migrate'`,
|
|
28
|
+
* `'prisma'`), throws `MigrationToolNotImplementedError` with a hint
|
|
29
|
+
* pointing at the workaround.
|
|
30
|
+
*/
|
|
31
|
+
export async function runMigrations(config, opts = {}) {
|
|
32
|
+
switch (config.tool) {
|
|
33
|
+
case 'custom':
|
|
34
|
+
return runSqlFiles({
|
|
35
|
+
dir: config.migrationsDir,
|
|
36
|
+
trackingTable: MIGRATIONS_TRACKING_TABLE,
|
|
37
|
+
onApply: opts.onApply,
|
|
38
|
+
});
|
|
39
|
+
case 'drizzle':
|
|
40
|
+
return drizzleNotImplemented();
|
|
41
|
+
case 'flyway':
|
|
42
|
+
return flywayNotImplemented();
|
|
43
|
+
case 'golang-migrate':
|
|
44
|
+
return golangMigrateNotImplemented();
|
|
45
|
+
case 'prisma':
|
|
46
|
+
return prismaNotImplemented();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Read-only counterpart of `runMigrations`. Returns one `StatusEntry` per
|
|
51
|
+
* `.sql` file in `config.migrationsDir`. Same dispatch rules as
|
|
52
|
+
* `runMigrations`.
|
|
53
|
+
*/
|
|
54
|
+
export async function getMigrationStatus(config) {
|
|
55
|
+
switch (config.tool) {
|
|
56
|
+
case 'custom':
|
|
57
|
+
return getSqlFilesStatus({
|
|
58
|
+
dir: config.migrationsDir,
|
|
59
|
+
trackingTable: MIGRATIONS_TRACKING_TABLE,
|
|
60
|
+
});
|
|
61
|
+
case 'drizzle':
|
|
62
|
+
return drizzleNotImplemented();
|
|
63
|
+
case 'flyway':
|
|
64
|
+
return flywayNotImplemented();
|
|
65
|
+
case 'golang-migrate':
|
|
66
|
+
return golangMigrateNotImplemented();
|
|
67
|
+
case 'prisma':
|
|
68
|
+
return prismaNotImplemented();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=dispatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../../src/migrations/dispatcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAG3D,0EAA0E;AAC1E,MAAM,CAAC,MAAM,yBAAyB,GAAG,iBAAiB,CAAC;AAE3D;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAuB,EACvB,OAAmB,EAAE;IAErB,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,QAAQ;YACX,OAAO,WAAW,CAAC;gBACjB,GAAG,EAAE,MAAM,CAAC,aAAa;gBACzB,aAAa,EAAE,yBAAyB;gBACxC,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAC,CAAC;QACL,KAAK,SAAS;YACZ,OAAO,qBAAqB,EAAE,CAAC;QACjC,KAAK,QAAQ;YACX,OAAO,oBAAoB,EAAE,CAAC;QAChC,KAAK,gBAAgB;YACnB,OAAO,2BAA2B,EAAE,CAAC;QACvC,KAAK,QAAQ;YACX,OAAO,oBAAoB,EAAE,CAAC;IAClC,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAuB;IAEvB,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,QAAQ;YACX,OAAO,iBAAiB,CAAC;gBACvB,GAAG,EAAE,MAAM,CAAC,aAAa;gBACzB,aAAa,EAAE,yBAAyB;aACzC,CAAC,CAAC;QACL,KAAK,SAAS;YACZ,OAAO,qBAAqB,EAAE,CAAC;QACjC,KAAK,QAAQ;YACX,OAAO,oBAAoB,EAAE,CAAC;QAChC,KAAK,gBAAgB;YACnB,OAAO,2BAA2B,EAAE,CAAC;QACvC,KAAK,QAAQ;YACX,OAAO,oBAAoB,EAAE,CAAC;IAClC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `DATABASE_URL` → `DB_*` env-var bridge used by the migration runner.
|
|
3
|
+
*
|
|
4
|
+
* The implementation lives in `query/pool.ts` so a single function fills
|
|
5
|
+
* the granular slots that `getPool()` reads — and so `getPool()` itself
|
|
6
|
+
* can call it on first connection (covers consumers that boot via
|
|
7
|
+
* `query()` / `withTransaction()` without ever touching the migration
|
|
8
|
+
* runner). This file re-exports for backward compatibility with code
|
|
9
|
+
* that imports from `@venturekit/data`'s `migrations/env` path.
|
|
10
|
+
*/
|
|
11
|
+
export { applyDatabaseUrlToEnv } from '../query/pool.js';
|
|
12
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/migrations/env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `DATABASE_URL` → `DB_*` env-var bridge used by the migration runner.
|
|
3
|
+
*
|
|
4
|
+
* The implementation lives in `query/pool.ts` so a single function fills
|
|
5
|
+
* the granular slots that `getPool()` reads — and so `getPool()` itself
|
|
6
|
+
* can call it on first connection (covers consumers that boot via
|
|
7
|
+
* `query()` / `withTransaction()` without ever touching the migration
|
|
8
|
+
* runner). This file re-exports for backward compatibility with code
|
|
9
|
+
* that imports from `@venturekit/data`'s `migrations/env` path.
|
|
10
|
+
*/
|
|
11
|
+
export { applyDatabaseUrlToEnv } from '../query/pool.js';
|
|
12
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/migrations/env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error classes thrown by the migration / seed runners.
|
|
3
|
+
*
|
|
4
|
+
* Exposed as named exports so callers (e.g. the `vk migrate` CLI) can
|
|
5
|
+
* `instanceof`-check them and surface friendlier UX than a generic
|
|
6
|
+
* `Error.message`.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Thrown by `runMigrations` / `getMigrationStatus` when `MigrationConfig.tool`
|
|
10
|
+
* points at a runner that hasn't been wired up yet (drizzle, flyway,
|
|
11
|
+
* golang-migrate, prisma). The bundled `'custom'` runner is the only one
|
|
12
|
+
* implemented today — the rest exist for future opt-in.
|
|
13
|
+
*/
|
|
14
|
+
export declare class MigrationToolNotImplementedError extends Error {
|
|
15
|
+
readonly tool: string;
|
|
16
|
+
readonly hint: string;
|
|
17
|
+
constructor(tool: string, hint: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Thrown when a `.sql` file's contents have changed AFTER the runner already
|
|
21
|
+
* recorded an `applied` row for it. Migrations and seeds are immutable once
|
|
22
|
+
* applied; editing them is a real footgun (different DBs end up with
|
|
23
|
+
* different schemas / data while both think they're up-to-date), so we hard-
|
|
24
|
+
* fail instead of silently skipping or re-running.
|
|
25
|
+
*/
|
|
26
|
+
export declare class MigrationHashMismatchError extends Error {
|
|
27
|
+
readonly version: string;
|
|
28
|
+
readonly storedHash: string;
|
|
29
|
+
readonly currentHash: string;
|
|
30
|
+
readonly trackingTable: string;
|
|
31
|
+
constructor(version: string, storedHash: string, currentHash: string, trackingTable: string);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/migrations/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;GAKG;AACH,qBAAa,gCAAiC,SAAQ,KAAK;IACzD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAQvC;AAED;;;;;;GAMG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;gBAG7B,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM;CAcxB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error classes thrown by the migration / seed runners.
|
|
3
|
+
*
|
|
4
|
+
* Exposed as named exports so callers (e.g. the `vk migrate` CLI) can
|
|
5
|
+
* `instanceof`-check them and surface friendlier UX than a generic
|
|
6
|
+
* `Error.message`.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Thrown by `runMigrations` / `getMigrationStatus` when `MigrationConfig.tool`
|
|
10
|
+
* points at a runner that hasn't been wired up yet (drizzle, flyway,
|
|
11
|
+
* golang-migrate, prisma). The bundled `'custom'` runner is the only one
|
|
12
|
+
* implemented today — the rest exist for future opt-in.
|
|
13
|
+
*/
|
|
14
|
+
export class MigrationToolNotImplementedError extends Error {
|
|
15
|
+
tool;
|
|
16
|
+
hint;
|
|
17
|
+
constructor(tool, hint) {
|
|
18
|
+
super(`Migration runner for tool '${tool}' is not implemented in @venturekit/data. ${hint}`);
|
|
19
|
+
this.name = 'MigrationToolNotImplementedError';
|
|
20
|
+
this.tool = tool;
|
|
21
|
+
this.hint = hint;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Thrown when a `.sql` file's contents have changed AFTER the runner already
|
|
26
|
+
* recorded an `applied` row for it. Migrations and seeds are immutable once
|
|
27
|
+
* applied; editing them is a real footgun (different DBs end up with
|
|
28
|
+
* different schemas / data while both think they're up-to-date), so we hard-
|
|
29
|
+
* fail instead of silently skipping or re-running.
|
|
30
|
+
*/
|
|
31
|
+
export class MigrationHashMismatchError extends Error {
|
|
32
|
+
version;
|
|
33
|
+
storedHash;
|
|
34
|
+
currentHash;
|
|
35
|
+
trackingTable;
|
|
36
|
+
constructor(version, storedHash, currentHash, trackingTable) {
|
|
37
|
+
super(`[migrate] file '${version}.sql' was edited after it was already applied. ` +
|
|
38
|
+
`Stored hash=${storedHash.slice(0, 12)}..., current hash=${currentHash.slice(0, 12)}.... ` +
|
|
39
|
+
`Migrations and seeds are immutable once applied. Either revert your edits, ` +
|
|
40
|
+
`drop the row from ${trackingTable}, or write a new ${trackingTable === '__vk_seeds' ? 'seed' : 'migration'} to make the desired change.`);
|
|
41
|
+
this.name = 'MigrationHashMismatchError';
|
|
42
|
+
this.version = version;
|
|
43
|
+
this.storedHash = storedHash;
|
|
44
|
+
this.currentHash = currentHash;
|
|
45
|
+
this.trackingTable = trackingTable;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/migrations/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;GAKG;AACH,MAAM,OAAO,gCAAiC,SAAQ,KAAK;IAChD,IAAI,CAAS;IACb,IAAI,CAAS;IAEtB,YAAY,IAAY,EAAE,IAAY;QACpC,KAAK,CACH,8BAA8B,IAAI,6CAA6C,IAAI,EAAE,CACtF,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,kCAAkC,CAAC;QAC/C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAC1C,OAAO,CAAS;IAChB,UAAU,CAAS;IACnB,WAAW,CAAS;IACpB,aAAa,CAAS;IAE/B,YACE,OAAe,EACf,UAAkB,EAClB,WAAmB,EACnB,aAAqB;QAErB,KAAK,CACH,mBAAmB,OAAO,iDAAiD;YACzE,eAAe,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,qBAAqB,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO;YAC1F,6EAA6E;YAC7E,qBAAqB,aAAa,oBAAoB,aAAa,KAAK,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,8BAA8B,CAC5I,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;CACF"}
|
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Migrations
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* This module provides configuration helpers for integrating with popular tools.
|
|
4
|
+
* Two surfaces exposed from this module:
|
|
6
5
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* -
|
|
6
|
+
* 1. **Config helpers** (`createMigrationConfig`, `DEFAULT_MIGRATION_CONFIG`,
|
|
7
|
+
* `getFlywayEnv`) — for projects that want to integrate with an
|
|
8
|
+
* established migration tool from their own deploy pipeline.
|
|
9
|
+
*
|
|
10
|
+
* 2. **Built-in runner** (`runMigrations`, `getMigrationStatus`,
|
|
11
|
+
* `runSeeds`, `getSeedStatus`) — applies pure-SQL files from
|
|
12
|
+
* `db/migrations/` and `db/seeds/`, tracked in `__vk_migrations` and
|
|
13
|
+
* `__vk_seeds` respectively. Selected by `MigrationConfig.tool ===
|
|
14
|
+
* 'custom'`. This is what `vk migrate` calls under the hood.
|
|
15
|
+
*
|
|
16
|
+
* The `'custom'` runner is the only one bundled today. Setting `tool` to
|
|
17
|
+
* `'drizzle'` / `'flyway'` / `'golang-migrate'` / `'prisma'` throws
|
|
18
|
+
* `MigrationToolNotImplementedError` — those are kept in the type union as
|
|
19
|
+
* opt-in points for future runners; for now use the established tool's CLI
|
|
20
|
+
* directly.
|
|
12
21
|
*/
|
|
13
22
|
import type { MigrationConfig, MigrationConfigInput } from '../types/index.js';
|
|
14
23
|
/**
|
|
15
|
-
* Default migration configuration
|
|
24
|
+
* Default migration configuration. Defaults to the bundled pure-SQL runner
|
|
25
|
+
* (`tool: 'custom'`) so `vk migrate` works in any project that drops `.sql`
|
|
26
|
+
* files into `db/migrations/` — no Java install (Flyway) or external CLI
|
|
27
|
+
* required.
|
|
16
28
|
*/
|
|
17
29
|
export declare const DEFAULT_MIGRATION_CONFIG: MigrationConfig;
|
|
18
30
|
/**
|
|
@@ -20,9 +32,18 @@ export declare const DEFAULT_MIGRATION_CONFIG: MigrationConfig;
|
|
|
20
32
|
*/
|
|
21
33
|
export declare function createMigrationConfig(input?: MigrationConfigInput): MigrationConfig;
|
|
22
34
|
/**
|
|
23
|
-
* Get Flyway configuration for deployment
|
|
35
|
+
* Get Flyway configuration for deployment.
|
|
24
36
|
*
|
|
25
|
-
* Returns environment variables to pass to Flyway container/Lambda
|
|
37
|
+
* Returns environment variables to pass to a Flyway container / Lambda /
|
|
38
|
+
* CLI invocation. Use this when you've set `MigrationConfig.tool: 'flyway'`
|
|
39
|
+
* and want to shell out to the `flyway` binary yourself — `runMigrations`
|
|
40
|
+
* with `tool: 'flyway'` currently throws `MigrationToolNotImplementedError`
|
|
41
|
+
* and points at this helper.
|
|
26
42
|
*/
|
|
27
43
|
export declare function getFlywayEnv(config: MigrationConfig, dbUrl: string): Record<string, string>;
|
|
44
|
+
export { runMigrations, getMigrationStatus, MIGRATIONS_TRACKING_TABLE, } from './dispatcher.js';
|
|
45
|
+
export { runSeeds, getSeedStatus, SEEDS_TRACKING_TABLE, } from './seeds.js';
|
|
46
|
+
export { MigrationToolNotImplementedError, MigrationHashMismatchError, } from './errors.js';
|
|
47
|
+
export { applyDatabaseUrlToEnv } from './env.js';
|
|
48
|
+
export type { RunResult, StatusEntry, RunOptions, SeedRunOptions, } from './types.js';
|
|
28
49
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAI/E;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,EAAE,eAGtC,CAAC;AAEF;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,CAAC,EAAE,oBAAoB,GAAG,eAAe,CAOnF;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAO3F;AAID,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,QAAQ,EACR,aAAa,EACb,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,gCAAgC,EAChC,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEjD,YAAY,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,cAAc,GACf,MAAM,YAAY,CAAC"}
|
package/dist/migrations/index.js
CHANGED
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Migrations
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* This module provides configuration helpers for integrating with popular tools.
|
|
4
|
+
* Two surfaces exposed from this module:
|
|
6
5
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* -
|
|
6
|
+
* 1. **Config helpers** (`createMigrationConfig`, `DEFAULT_MIGRATION_CONFIG`,
|
|
7
|
+
* `getFlywayEnv`) — for projects that want to integrate with an
|
|
8
|
+
* established migration tool from their own deploy pipeline.
|
|
9
|
+
*
|
|
10
|
+
* 2. **Built-in runner** (`runMigrations`, `getMigrationStatus`,
|
|
11
|
+
* `runSeeds`, `getSeedStatus`) — applies pure-SQL files from
|
|
12
|
+
* `db/migrations/` and `db/seeds/`, tracked in `__vk_migrations` and
|
|
13
|
+
* `__vk_seeds` respectively. Selected by `MigrationConfig.tool ===
|
|
14
|
+
* 'custom'`. This is what `vk migrate` calls under the hood.
|
|
15
|
+
*
|
|
16
|
+
* The `'custom'` runner is the only one bundled today. Setting `tool` to
|
|
17
|
+
* `'drizzle'` / `'flyway'` / `'golang-migrate'` / `'prisma'` throws
|
|
18
|
+
* `MigrationToolNotImplementedError` — those are kept in the type union as
|
|
19
|
+
* opt-in points for future runners; for now use the established tool's CLI
|
|
20
|
+
* directly.
|
|
12
21
|
*/
|
|
22
|
+
// ─── Config helpers (existing public API) ───────────────────────────────
|
|
13
23
|
/**
|
|
14
|
-
* Default migration configuration
|
|
24
|
+
* Default migration configuration. Defaults to the bundled pure-SQL runner
|
|
25
|
+
* (`tool: 'custom'`) so `vk migrate` works in any project that drops `.sql`
|
|
26
|
+
* files into `db/migrations/` — no Java install (Flyway) or external CLI
|
|
27
|
+
* required.
|
|
15
28
|
*/
|
|
16
29
|
export const DEFAULT_MIGRATION_CONFIG = {
|
|
17
|
-
tool: '
|
|
30
|
+
tool: 'custom',
|
|
18
31
|
migrationsDir: 'db/migrations',
|
|
19
32
|
};
|
|
20
33
|
/**
|
|
@@ -29,9 +42,13 @@ export function createMigrationConfig(input) {
|
|
|
29
42
|
};
|
|
30
43
|
}
|
|
31
44
|
/**
|
|
32
|
-
* Get Flyway configuration for deployment
|
|
45
|
+
* Get Flyway configuration for deployment.
|
|
33
46
|
*
|
|
34
|
-
* Returns environment variables to pass to Flyway container/Lambda
|
|
47
|
+
* Returns environment variables to pass to a Flyway container / Lambda /
|
|
48
|
+
* CLI invocation. Use this when you've set `MigrationConfig.tool: 'flyway'`
|
|
49
|
+
* and want to shell out to the `flyway` binary yourself — `runMigrations`
|
|
50
|
+
* with `tool: 'flyway'` currently throws `MigrationToolNotImplementedError`
|
|
51
|
+
* and points at this helper.
|
|
35
52
|
*/
|
|
36
53
|
export function getFlywayEnv(config, dbUrl) {
|
|
37
54
|
return {
|
|
@@ -41,4 +58,9 @@ export function getFlywayEnv(config, dbUrl) {
|
|
|
41
58
|
...(config.baselineVersion && { FLYWAY_BASELINE_VERSION: config.baselineVersion }),
|
|
42
59
|
};
|
|
43
60
|
}
|
|
61
|
+
// ─── Built-in runner (new public API) ────────────────────────────────────
|
|
62
|
+
export { runMigrations, getMigrationStatus, MIGRATIONS_TRACKING_TABLE, } from './dispatcher.js';
|
|
63
|
+
export { runSeeds, getSeedStatus, SEEDS_TRACKING_TABLE, } from './seeds.js';
|
|
64
|
+
export { MigrationToolNotImplementedError, MigrationHashMismatchError, } from './errors.js';
|
|
65
|
+
export { applyDatabaseUrlToEnv } from './env.js';
|
|
44
66
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,2EAA2E;AAE3E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAoB;IACvD,IAAI,EAAE,QAAQ;IACd,aAAa,EAAE,eAAe;CAC/B,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAA4B;IAChE,IAAI,CAAC,KAAK;QAAE,OAAO,wBAAwB,CAAC;IAE5C,OAAO;QACL,GAAG,wBAAwB;QAC3B,GAAG,KAAK;KACT,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,MAAuB,EAAE,KAAa;IACjE,OAAO;QACL,UAAU,EAAE,KAAK;QACjB,gBAAgB,EAAE,cAAc,MAAM,CAAC,aAAa,EAAE;QACtD,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;QACvD,GAAG,CAAC,MAAM,CAAC,eAAe,IAAI,EAAE,uBAAuB,EAAE,MAAM,CAAC,eAAe,EAAE,CAAC;KACnF,CAAC;AACJ,CAAC;AAED,4EAA4E;AAE5E,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,QAAQ,EACR,aAAa,EACb,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,gCAAgC,EAChC,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in pure-SQL migration / seed runner.
|
|
3
|
+
*
|
|
4
|
+
* Used by both `runMigrations` (when `MigrationConfig.tool === 'custom'`)
|
|
5
|
+
* and `runSeeds` (always). The only difference between the two callers is
|
|
6
|
+
* the source directory and the tracking-table name; the apply / skip /
|
|
7
|
+
* hash-check logic is identical.
|
|
8
|
+
*
|
|
9
|
+
* ### Tracking table
|
|
10
|
+
*
|
|
11
|
+
* Auto-created on first run with this shape:
|
|
12
|
+
*
|
|
13
|
+
* CREATE TABLE IF NOT EXISTS <table> (
|
|
14
|
+
* version text PRIMARY KEY,
|
|
15
|
+
* hash text NOT NULL,
|
|
16
|
+
* applied_at timestamptz NOT NULL DEFAULT now()
|
|
17
|
+
* )
|
|
18
|
+
*
|
|
19
|
+
* `version` is the file basename without the `.sql` extension. `hash` is a
|
|
20
|
+
* sha-256 of the file contents at apply time; on subsequent runs we
|
|
21
|
+
* compare the stored hash to the current file hash and hard-fail (via
|
|
22
|
+
* `MigrationHashMismatchError`) if they differ — migrations and seeds are
|
|
23
|
+
* immutable once applied.
|
|
24
|
+
*
|
|
25
|
+
* ### Atomicity
|
|
26
|
+
*
|
|
27
|
+
* Each pending file runs inside its own transaction with
|
|
28
|
+
* `statement_timeout = 0` (migrations / seeds can legitimately take
|
|
29
|
+
* minutes — e.g. building large indexes — and we don't want the data-
|
|
30
|
+
* package's default 10-second cap killing them mid-flight). On any
|
|
31
|
+
* exception the transaction rolls back, the tracking-row is NOT inserted,
|
|
32
|
+
* and the runner re-throws so the operator sees the failing file.
|
|
33
|
+
*/
|
|
34
|
+
import type { RunResult, RunOptions, StatusEntry } from '../types.js';
|
|
35
|
+
/**
|
|
36
|
+
* Options for the shared SQL-file runner. Both `runMigrations(config)` and
|
|
37
|
+
* `runSeeds(opts)` shape themselves into this struct.
|
|
38
|
+
*/
|
|
39
|
+
export interface RunSqlFilesOptions extends RunOptions {
|
|
40
|
+
/** Absolute or cwd-relative path to a directory of `*.sql` files. */
|
|
41
|
+
dir: string;
|
|
42
|
+
/**
|
|
43
|
+
* Name of the tracking table to use. Must match
|
|
44
|
+
* `/^[A-Za-z_][A-Za-z0-9_]*$/` (this name is interpolated into raw SQL —
|
|
45
|
+
* Postgres doesn't allow parameterized identifiers — so we restrict it
|
|
46
|
+
* to a conservative whitelist that makes injection structurally
|
|
47
|
+
* impossible).
|
|
48
|
+
*/
|
|
49
|
+
trackingTable: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Apply pending `.sql` files in `opts.dir`, tracked in `opts.trackingTable`.
|
|
53
|
+
*
|
|
54
|
+
* Returns `{ applied, skipped }` — both arrays of file basenames, in
|
|
55
|
+
* filesystem order. A file lands in `skipped` when its tracking row
|
|
56
|
+
* already exists AND its current hash matches the stored hash.
|
|
57
|
+
*
|
|
58
|
+
* Throws `MigrationHashMismatchError` if any already-applied file has
|
|
59
|
+
* been edited.
|
|
60
|
+
*/
|
|
61
|
+
export declare function runSqlFiles(opts: RunSqlFilesOptions): Promise<RunResult>;
|
|
62
|
+
/**
|
|
63
|
+
* Read-only counterpart of `runSqlFiles`. Returns one entry per `.sql` file
|
|
64
|
+
* in `opts.dir`, with `applied` true for files that have a matching
|
|
65
|
+
* tracking row.
|
|
66
|
+
*
|
|
67
|
+
* Files whose tracking row is hash-mismatched are reported with
|
|
68
|
+
* `applied: false` (so the operator sees them as "pending again") — this
|
|
69
|
+
* is a status query and shouldn't throw.
|
|
70
|
+
*/
|
|
71
|
+
export declare function getSqlFilesStatus(opts: RunSqlFilesOptions): Promise<StatusEntry[]>;
|
|
72
|
+
//# sourceMappingURL=custom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../../src/migrations/runners/custom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AASH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEtE;;;GAGG;AACH,MAAM,WAAW,kBAAmB,SAAQ,UAAU;IACpD,qEAAqE;IACrE,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,CAAC;CACvB;AAgBD;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,SAAS,CAAC,CA8B9E;AAED;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,WAAW,EAAE,CAAC,CAcxB"}
|