@kronor/dtv 9.4.0 → 9.4.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.
|
@@ -207,9 +207,12 @@ export function toLiteral(value, indent = '') {
|
|
|
207
207
|
}
|
|
208
208
|
throw new Error(`Cannot write ${typeof value} into a snapshot`);
|
|
209
209
|
}
|
|
210
|
-
export const snapshotName = (revision) => `
|
|
211
|
-
export const snapshotFile = (revision) => `
|
|
212
|
-
|
|
210
|
+
export const snapshotName = (revision) => `rev${revision}`;
|
|
211
|
+
export const snapshotFile = (revision) => `rev${revision}.snapshot.ts`;
|
|
212
|
+
/** The migration into `revision`, from the revision before it. */
|
|
213
|
+
export const migrationFile = (revision) => `rev${revision}.migration.ts`;
|
|
214
|
+
/** Matches `migrationFile`; its group is the revision. */
|
|
215
|
+
export const MIGRATION_FILE = /^rev(\d+)\.migration\.ts$/;
|
|
213
216
|
export function renderSnapshot(projection, dtvImport) {
|
|
214
217
|
return [
|
|
215
218
|
`${GENERATED} Do not edit: the definition "${projection.definition}" at revision ${projection.revision}.`,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
|
-
import { deepEqual, generateOps, migrationFile, renderIndex, renderMigration, renderSnapshot, snapshotFile } from './generate.js';
|
|
3
|
+
import { deepEqual, generateOps, migrationFile, MIGRATION_FILE, renderIndex, renderMigration, renderSnapshot, snapshotFile } from './generate.js';
|
|
4
4
|
import { renameMigrationsImport, wireMigrations } from './wire.js';
|
|
5
5
|
import { MIGRATIONS_FOLDER } from './types.js';
|
|
6
6
|
async function loadChains(project) {
|
|
@@ -33,7 +33,7 @@ function sameDefinition(live, latest) {
|
|
|
33
33
|
async function migrationRevisions(folder) {
|
|
34
34
|
const files = await fs.readdir(folder).catch(() => []);
|
|
35
35
|
return files
|
|
36
|
-
.map(file =>
|
|
36
|
+
.map(file => MIGRATION_FILE.exec(file))
|
|
37
37
|
.flatMap(match => match === null ? [] : [Number(match[1])])
|
|
38
38
|
.sort((left, right) => left - right);
|
|
39
39
|
}
|
package/docs/view-migrations.md
CHANGED
|
@@ -24,7 +24,7 @@ factories that is all it takes.
|
|
|
24
24
|
npx dtv definitions snapshot
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
This writes a `dtv-migrations/<definition>/` folder (`
|
|
27
|
+
This writes a `dtv-migrations/<definition>/` folder (`rev1.snapshot.ts`, `index.ts`) next to each
|
|
28
28
|
view's module, and wires the view up with it:
|
|
29
29
|
|
|
30
30
|
```ts
|
|
@@ -86,10 +86,11 @@ whose module is not found, such as JSON views; default `dtv-migrations`). Option
|
|
|
86
86
|
## Changing a view
|
|
87
87
|
|
|
88
88
|
Change the definition, then run `npx dtv definitions snapshot`. For each changed view it writes the next
|
|
89
|
-
snapshot and
|
|
89
|
+
snapshot and the migration into it (`rev4.snapshot.ts` and `rev4.migration.ts`), and adds the migration
|
|
90
|
+
to `index.ts`:
|
|
90
91
|
|
|
91
92
|
```ts
|
|
92
|
-
export default DSL.defineMigration(
|
|
93
|
+
export default DSL.defineMigration(rev3, rev4, m => [
|
|
93
94
|
// "amt" was removed and "amount" added, with the same definition.
|
|
94
95
|
// If "amount" is another filter that only looks the same: m.drop('amt')
|
|
95
96
|
m.renameFilter('amt', 'amount'),
|
|
@@ -133,7 +134,7 @@ writes `m.todo(…)` with the candidates in comments. **A `todo` does not type-c
|
|
|
133
134
|
| `m.custom(from, to, state => … \| RESET)` | Anything else; `state` is typed by both snapshots. |
|
|
134
135
|
| `m.renameColumn(from, to)`, `m.dropColumn(id)`, `m.resetSort(id)` | Columns. A stored sort by what a dropped column, or one given `resetSort`, sorted by is reset. |
|
|
135
136
|
|
|
136
|
-
Ids are checked against the snapshots: `m.reset('amount')` does not compile if
|
|
137
|
+
Ids are checked against the snapshots: `m.reset('amount')` does not compile if rev3 has no `amount`.
|
|
137
138
|
|
|
138
139
|
### Changes the snapshots cannot see
|
|
139
140
|
|