shutro 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/migrate/apply.d.ts +5 -1
- package/dist/migrate/apply.js +20 -2
- package/package.json +1 -1
package/dist/migrate/apply.d.ts
CHANGED
|
@@ -11,11 +11,15 @@ export interface MigrationPlan {
|
|
|
11
11
|
readonly destructive: boolean;
|
|
12
12
|
}[];
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Compares the registry with the live database and plans the changes. Tables in `ignore` belong to the
|
|
16
|
+
* application, not to the models (a framework's own tables, e.g. `kosh_*`): they are never altered or dropped.
|
|
17
|
+
*/
|
|
15
18
|
export declare function planMigration(options: {
|
|
16
19
|
readonly driver: Driver;
|
|
17
20
|
readonly registry: Registry;
|
|
18
21
|
readonly schema?: string;
|
|
22
|
+
readonly ignore?: readonly (string | RegExp)[];
|
|
19
23
|
}): Promise<MigrationPlan>;
|
|
20
24
|
/** A migration file on disk. */
|
|
21
25
|
export interface MigrationFile {
|
package/dist/migrate/apply.js
CHANGED
|
@@ -11,9 +11,27 @@ import { diffSchema } from './diff.js';
|
|
|
11
11
|
import { DestructiveMigrationError, MigrationChecksumError, MigrationFileError } from './errors.js';
|
|
12
12
|
import { renderOperation } from './render.js';
|
|
13
13
|
import { desiredSchema } from './schema.js';
|
|
14
|
-
/**
|
|
14
|
+
/** True when `ignore` names the table: an exact name, a `prefix*`, or a regular expression. */
|
|
15
|
+
function ignored(name, ignore) {
|
|
16
|
+
return ignore.some((p) => typeof p === 'string'
|
|
17
|
+
? p.endsWith('*')
|
|
18
|
+
? name.startsWith(p.slice(0, -1))
|
|
19
|
+
: name === p
|
|
20
|
+
: p.test(name));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Compares the registry with the live database and plans the changes. Tables in `ignore` belong to the
|
|
24
|
+
* application, not to the models (a framework's own tables, e.g. `kosh_*`): they are never altered or dropped.
|
|
25
|
+
*/
|
|
15
26
|
export async function planMigration(options) {
|
|
16
|
-
const
|
|
27
|
+
const read = await readLiveSchema(options.driver, options.schema ?? 'public');
|
|
28
|
+
const ignore = options.ignore ?? [];
|
|
29
|
+
const live = ignore.length === 0
|
|
30
|
+
? read
|
|
31
|
+
: {
|
|
32
|
+
...read,
|
|
33
|
+
tables: Object.fromEntries(Object.entries(read.tables).filter(([name]) => !ignored(name, ignore))),
|
|
34
|
+
};
|
|
17
35
|
const operations = diffSchema(desiredSchema(options.registry), live);
|
|
18
36
|
return {
|
|
19
37
|
operations,
|
package/package.json
CHANGED