@dxos/migrations 0.4.10-main.3e0c8a5 → 0.4.10-main.3f5e2d2
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/lib/browser/index.mjs +2 -2
- package/dist/lib/browser/index.mjs.map +2 -2
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +2 -2
- package/dist/lib/node/index.cjs.map +2 -2
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/migrations.d.ts +1 -1
- package/dist/types/src/migrations.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/migrations.test.ts +17 -17
- package/src/migrations.ts +3 -1
|
@@ -20,7 +20,7 @@ var Migrations = class {
|
|
|
20
20
|
static async migrate(space, targetVersion) {
|
|
21
21
|
invariant(this.versionProperty, "Migrations namespace not set", {
|
|
22
22
|
F: __dxlog_file,
|
|
23
|
-
L:
|
|
23
|
+
L: 40,
|
|
24
24
|
S: this,
|
|
25
25
|
A: [
|
|
26
26
|
"this.versionProperty",
|
|
@@ -29,7 +29,7 @@ var Migrations = class {
|
|
|
29
29
|
});
|
|
30
30
|
invariant(space.state.get() === SpaceState.READY, "Space not ready", {
|
|
31
31
|
F: __dxlog_file,
|
|
32
|
-
L:
|
|
32
|
+
L: 41,
|
|
33
33
|
S: this,
|
|
34
34
|
A: [
|
|
35
35
|
"space.state.get() === SpaceState.READY",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/migrations.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { invariant } from '@dxos/invariant';\nimport type
|
|
5
|
-
"mappings": ";AAIA,SAAqBA,kBAAkB;AACvC,SAASC,iBAAiB;;
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { invariant } from '@dxos/invariant';\nimport { type MaybePromise } from '@dxos/util';\n\n// TODO(burdon): Merge with successor to serialization mechanism in braneframe/types.\n\nexport type MigrationContext = {\n space: Space;\n};\n\nexport type Migration = {\n version: string | number;\n up: (context: MigrationContext) => MaybePromise<void>;\n down: (context: MigrationContext) => MaybePromise<void>;\n};\n\nexport class Migrations {\n static namespace?: string;\n static migrations: Migration[] = [];\n\n static get versionProperty() {\n return this.namespace && `${this.namespace}.version`;\n }\n\n static get targetVersion() {\n return this.migrations[this.migrations.length - 1].version;\n }\n\n static define(namespace: string, migrations: Migration[]) {\n this.namespace = namespace;\n this.migrations = migrations;\n }\n\n // TODO(wittjosiah): Multi-space migrations.\n static async migrate(space: Space, targetVersion?: string | number) {\n invariant(this.versionProperty, 'Migrations namespace not set');\n invariant(space.state.get() === SpaceState.READY, 'Space not ready');\n const currentVersion = space.properties[this.versionProperty];\n const currentIndex = this.migrations.findIndex((m) => m.version === currentVersion) + 1;\n const i = this.migrations.findIndex((m) => m.version === targetVersion);\n const targetIndex = i === -1 ? this.migrations.length : i + 1;\n if (currentIndex === targetIndex) {\n return false;\n }\n\n if (targetIndex > currentIndex) {\n const migrations = this.migrations.slice(currentIndex, targetIndex);\n for (const migration of migrations) {\n await migration.up({ space });\n space.properties[this.versionProperty] = migration.version;\n }\n } else {\n const migrations = this.migrations.slice(targetIndex, currentIndex);\n migrations.reverse();\n for (const migration of migrations) {\n await migration.down({ space });\n const index = this.migrations.indexOf(migration);\n space.properties[this.versionProperty] = this.migrations[index - 1]?.version;\n }\n }\n\n return true;\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,SAAqBA,kBAAkB;AACvC,SAASC,iBAAiB;;AAenB,IAAMC,aAAN,MAAMA;EAEX;SAAOC,aAA0B,CAAA;;EAEjC,WAAWC,kBAAkB;AAC3B,WAAO,KAAKC,aAAa,GAAG,KAAKA,SAAS;EAC5C;EAEA,WAAWC,gBAAgB;AACzB,WAAO,KAAKH,WAAW,KAAKA,WAAWI,SAAS,CAAA,EAAGC;EACrD;EAEA,OAAOC,OAAOJ,WAAmBF,YAAyB;AACxD,SAAKE,YAAYA;AACjB,SAAKF,aAAaA;EACpB;;EAGA,aAAaO,QAAQC,OAAcL,eAAiC;AAClEL,cAAU,KAAKG,iBAAiB,gCAAA;;;;;;;;;AAChCH,cAAUU,MAAMC,MAAMC,IAAG,MAAOb,WAAWc,OAAO,mBAAA;;;;;;;;;AAClD,UAAMC,iBAAiBJ,MAAMK,WAAW,KAAKZ,eAAe;AAC5D,UAAMa,eAAe,KAAKd,WAAWe,UAAU,CAACC,MAAMA,EAAEX,YAAYO,cAAAA,IAAkB;AACtF,UAAMK,IAAI,KAAKjB,WAAWe,UAAU,CAACC,MAAMA,EAAEX,YAAYF,aAAAA;AACzD,UAAMe,cAAcD,MAAM,KAAK,KAAKjB,WAAWI,SAASa,IAAI;AAC5D,QAAIH,iBAAiBI,aAAa;AAChC,aAAO;IACT;AAEA,QAAIA,cAAcJ,cAAc;AAC9B,YAAMd,aAAa,KAAKA,WAAWmB,MAAML,cAAcI,WAAAA;AACvD,iBAAWE,aAAapB,YAAY;AAClC,cAAMoB,UAAUC,GAAG;UAAEb;QAAM,CAAA;AAC3BA,cAAMK,WAAW,KAAKZ,eAAe,IAAImB,UAAUf;MACrD;IACF,OAAO;AACL,YAAML,aAAa,KAAKA,WAAWmB,MAAMD,aAAaJ,YAAAA;AACtDd,iBAAWsB,QAAO;AAClB,iBAAWF,aAAapB,YAAY;AAClC,cAAMoB,UAAUG,KAAK;UAAEf;QAAM,CAAA;AAC7B,cAAMgB,QAAQ,KAAKxB,WAAWyB,QAAQL,SAAAA;AACtCZ,cAAMK,WAAW,KAAKZ,eAAe,IAAI,KAAKD,WAAWwB,QAAQ,CAAA,GAAInB;MACvE;IACF;AAEA,WAAO;EACT;AACF;",
|
|
6
6
|
"names": ["SpaceState", "invariant", "Migrations", "migrations", "versionProperty", "namespace", "targetVersion", "length", "version", "define", "migrate", "space", "state", "get", "READY", "currentVersion", "properties", "currentIndex", "findIndex", "m", "i", "targetIndex", "slice", "migration", "up", "reverse", "down", "index", "indexOf"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/sdk/migrations/src/migrations.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/sdk/migrations/src/migrations.ts":{"bytes":8124,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/migrations/src/index.ts":{"bytes":469,"imports":[{"path":"packages/sdk/migrations/src/migrations.ts","kind":"import-statement","original":"./migrations"}],"format":"esm"}},"outputs":{"packages/sdk/migrations/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":3895},"packages/sdk/migrations/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"exports":["Migrations"],"entryPoint":"packages/sdk/migrations/src/index.ts","inputs":{"packages/sdk/migrations/src/migrations.ts":{"bytesInOutput":2163},"packages/sdk/migrations/src/index.ts":{"bytesInOutput":0}},"bytes":2268}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -42,7 +42,7 @@ var Migrations = class {
|
|
|
42
42
|
static async migrate(space, targetVersion) {
|
|
43
43
|
(0, import_invariant.invariant)(this.versionProperty, "Migrations namespace not set", {
|
|
44
44
|
F: __dxlog_file,
|
|
45
|
-
L:
|
|
45
|
+
L: 40,
|
|
46
46
|
S: this,
|
|
47
47
|
A: [
|
|
48
48
|
"this.versionProperty",
|
|
@@ -51,7 +51,7 @@ var Migrations = class {
|
|
|
51
51
|
});
|
|
52
52
|
(0, import_invariant.invariant)(space.state.get() === import_echo.SpaceState.READY, "Space not ready", {
|
|
53
53
|
F: __dxlog_file,
|
|
54
|
-
L:
|
|
54
|
+
L: 41,
|
|
55
55
|
S: this,
|
|
56
56
|
A: [
|
|
57
57
|
"space.state.get() === SpaceState.READY",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/migrations.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { invariant } from '@dxos/invariant';\nimport type
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAIA,kBAAuC;AACvC,uBAA0B;;
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { invariant } from '@dxos/invariant';\nimport { type MaybePromise } from '@dxos/util';\n\n// TODO(burdon): Merge with successor to serialization mechanism in braneframe/types.\n\nexport type MigrationContext = {\n space: Space;\n};\n\nexport type Migration = {\n version: string | number;\n up: (context: MigrationContext) => MaybePromise<void>;\n down: (context: MigrationContext) => MaybePromise<void>;\n};\n\nexport class Migrations {\n static namespace?: string;\n static migrations: Migration[] = [];\n\n static get versionProperty() {\n return this.namespace && `${this.namespace}.version`;\n }\n\n static get targetVersion() {\n return this.migrations[this.migrations.length - 1].version;\n }\n\n static define(namespace: string, migrations: Migration[]) {\n this.namespace = namespace;\n this.migrations = migrations;\n }\n\n // TODO(wittjosiah): Multi-space migrations.\n static async migrate(space: Space, targetVersion?: string | number) {\n invariant(this.versionProperty, 'Migrations namespace not set');\n invariant(space.state.get() === SpaceState.READY, 'Space not ready');\n const currentVersion = space.properties[this.versionProperty];\n const currentIndex = this.migrations.findIndex((m) => m.version === currentVersion) + 1;\n const i = this.migrations.findIndex((m) => m.version === targetVersion);\n const targetIndex = i === -1 ? this.migrations.length : i + 1;\n if (currentIndex === targetIndex) {\n return false;\n }\n\n if (targetIndex > currentIndex) {\n const migrations = this.migrations.slice(currentIndex, targetIndex);\n for (const migration of migrations) {\n await migration.up({ space });\n space.properties[this.versionProperty] = migration.version;\n }\n } else {\n const migrations = this.migrations.slice(targetIndex, currentIndex);\n migrations.reverse();\n for (const migration of migrations) {\n await migration.down({ space });\n const index = this.migrations.indexOf(migration);\n space.properties[this.versionProperty] = this.migrations[index - 1]?.version;\n }\n }\n\n return true;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAIA,kBAAuC;AACvC,uBAA0B;;AAenB,IAAMA,aAAN,MAAMA;EAEX,OAAA;SAAOC,aAA0B,CAAA;;EAEjC,WAAWC,kBAAkB;AAC3B,WAAO,KAAKC,aAAa,GAAG,KAAKA,SAAS;EAC5C;EAEA,WAAWC,gBAAgB;AACzB,WAAO,KAAKH,WAAW,KAAKA,WAAWI,SAAS,CAAA,EAAGC;EACrD;EAEA,OAAOC,OAAOJ,WAAmBF,YAAyB;AACxD,SAAKE,YAAYA;AACjB,SAAKF,aAAaA;EACpB;;EAGA,aAAaO,QAAQC,OAAcL,eAAiC;AAClEM,oCAAU,KAAKR,iBAAiB,gCAAA;;;;;;;;;AAChCQ,oCAAUD,MAAME,MAAMC,IAAG,MAAOC,uBAAWC,OAAO,mBAAA;;;;;;;;;AAClD,UAAMC,iBAAiBN,MAAMO,WAAW,KAAKd,eAAe;AAC5D,UAAMe,eAAe,KAAKhB,WAAWiB,UAAU,CAACC,MAAMA,EAAEb,YAAYS,cAAAA,IAAkB;AACtF,UAAMK,IAAI,KAAKnB,WAAWiB,UAAU,CAACC,MAAMA,EAAEb,YAAYF,aAAAA;AACzD,UAAMiB,cAAcD,MAAM,KAAK,KAAKnB,WAAWI,SAASe,IAAI;AAC5D,QAAIH,iBAAiBI,aAAa;AAChC,aAAO;IACT;AAEA,QAAIA,cAAcJ,cAAc;AAC9B,YAAMhB,aAAa,KAAKA,WAAWqB,MAAML,cAAcI,WAAAA;AACvD,iBAAWE,aAAatB,YAAY;AAClC,cAAMsB,UAAUC,GAAG;UAAEf;QAAM,CAAA;AAC3BA,cAAMO,WAAW,KAAKd,eAAe,IAAIqB,UAAUjB;MACrD;IACF,OAAO;AACL,YAAML,aAAa,KAAKA,WAAWqB,MAAMD,aAAaJ,YAAAA;AACtDhB,iBAAWwB,QAAO;AAClB,iBAAWF,aAAatB,YAAY;AAClC,cAAMsB,UAAUG,KAAK;UAAEjB;QAAM,CAAA;AAC7B,cAAMkB,QAAQ,KAAK1B,WAAW2B,QAAQL,SAAAA;AACtCd,cAAMO,WAAW,KAAKd,eAAe,IAAI,KAAKD,WAAW0B,QAAQ,CAAA,GAAIrB;MACvE;IACF;AAEA,WAAO;EACT;AACF;",
|
|
6
6
|
"names": ["Migrations", "migrations", "versionProperty", "namespace", "targetVersion", "length", "version", "define", "migrate", "space", "invariant", "state", "get", "SpaceState", "READY", "currentVersion", "properties", "currentIndex", "findIndex", "m", "i", "targetIndex", "slice", "migration", "up", "reverse", "down", "index", "indexOf"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/sdk/migrations/src/migrations.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/sdk/migrations/src/migrations.ts":{"bytes":8124,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/migrations/src/index.ts":{"bytes":469,"imports":[{"path":"packages/sdk/migrations/src/migrations.ts","kind":"import-statement","original":"./migrations"}],"format":"esm"}},"outputs":{"packages/sdk/migrations/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":3895},"packages/sdk/migrations/dist/lib/node/index.cjs":{"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"exports":["Migrations"],"entryPoint":"packages/sdk/migrations/src/index.ts","inputs":{"packages/sdk/migrations/src/migrations.ts":{"bytesInOutput":2163},"packages/sdk/migrations/src/index.ts":{"bytesInOutput":0}},"bytes":2268}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../../src/migrations.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,KAAK,EAAc,MAAM,mBAAmB,CAAC;AAE3D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../../src/migrations.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,KAAK,EAAc,MAAM,mBAAmB,CAAC;AAE3D,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAI/C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,EAAE,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;IACtD,IAAI,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;CACzD,CAAC;AAEF,qBAAa,UAAU;IACrB,MAAM,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,UAAU,EAAE,SAAS,EAAE,CAAM;IAEpC,MAAM,KAAK,eAAe,uBAEzB;IAED,MAAM,KAAK,aAAa,oBAEvB;IAED,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE;WAM3C,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM;CA6BnE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/migrations",
|
|
3
|
-
"version": "0.4.10-main.
|
|
3
|
+
"version": "0.4.10-main.3f5e2d2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"src"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@dxos/client": "0.4.10-main.
|
|
24
|
-
"@dxos/
|
|
25
|
-
"@dxos/
|
|
26
|
-
"@dxos/
|
|
23
|
+
"@dxos/client": "0.4.10-main.3f5e2d2",
|
|
24
|
+
"@dxos/util": "0.4.10-main.3f5e2d2",
|
|
25
|
+
"@dxos/echo-schema": "0.4.10-main.3f5e2d2",
|
|
26
|
+
"@dxos/invariant": "0.4.10-main.3f5e2d2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {},
|
|
29
29
|
"publishConfig": {
|
package/src/migrations.test.ts
CHANGED
|
@@ -7,8 +7,7 @@ import { expect } from 'chai';
|
|
|
7
7
|
import { Client } from '@dxos/client';
|
|
8
8
|
import { type Space } from '@dxos/client/echo';
|
|
9
9
|
import { TestBuilder } from '@dxos/client/testing';
|
|
10
|
-
import
|
|
11
|
-
import { ExpandoType } from '@dxos/echo-schema';
|
|
10
|
+
import { Expando, create } from '@dxos/echo-schema';
|
|
12
11
|
import { describe, test, beforeEach, beforeAll, afterAll } from '@dxos/test';
|
|
13
12
|
|
|
14
13
|
import { Migrations } from './migrations';
|
|
@@ -17,10 +16,10 @@ Migrations.define('test', [
|
|
|
17
16
|
{
|
|
18
17
|
version: 1,
|
|
19
18
|
up: async ({ space }) => {
|
|
20
|
-
space.db.add(
|
|
19
|
+
space.db.add(create(Expando, { namespace: 'test', count: 1 }));
|
|
21
20
|
},
|
|
22
21
|
down: async ({ space }) => {
|
|
23
|
-
const { objects } = space.db.query({ namespace: 'test' });
|
|
22
|
+
const { objects } = await space.db.query({ namespace: 'test' }).run();
|
|
24
23
|
for (const object of objects) {
|
|
25
24
|
space.db.remove(object);
|
|
26
25
|
}
|
|
@@ -29,7 +28,7 @@ Migrations.define('test', [
|
|
|
29
28
|
{
|
|
30
29
|
version: 2,
|
|
31
30
|
up: async ({ space }) => {
|
|
32
|
-
const { objects } = space.db.query({ namespace: 'test' });
|
|
31
|
+
const { objects } = await space.db.query({ namespace: 'test' }).run();
|
|
33
32
|
for (const object of objects) {
|
|
34
33
|
object.count = 2;
|
|
35
34
|
}
|
|
@@ -41,13 +40,13 @@ Migrations.define('test', [
|
|
|
41
40
|
{
|
|
42
41
|
version: 3,
|
|
43
42
|
up: async ({ space }) => {
|
|
44
|
-
const { objects } = space.db.query({ namespace: 'test' });
|
|
43
|
+
const { objects } = await space.db.query({ namespace: 'test' }).run();
|
|
45
44
|
for (const object of objects) {
|
|
46
45
|
object.count *= 3;
|
|
47
46
|
}
|
|
48
47
|
},
|
|
49
48
|
down: async ({ space }) => {
|
|
50
|
-
const { objects } = space.db.query({ namespace: 'test' });
|
|
49
|
+
const { objects } = await space.db.query({ namespace: 'test' }).run();
|
|
51
50
|
for (const object of objects) {
|
|
52
51
|
object.count /= 3;
|
|
53
52
|
}
|
|
@@ -76,7 +75,7 @@ describe('Migrations', () => {
|
|
|
76
75
|
|
|
77
76
|
test('if no migrations have been run before, runs all migrations', async () => {
|
|
78
77
|
await Migrations.migrate(space);
|
|
79
|
-
const { objects } = space.db.query({ namespace: 'test' });
|
|
78
|
+
const { objects } = await space.db.query({ namespace: 'test' }).run();
|
|
80
79
|
expect(objects).to.have.length(1);
|
|
81
80
|
expect(objects[0].count).to.equal(6);
|
|
82
81
|
expect(space.properties['test.version']).to.equal(3);
|
|
@@ -84,9 +83,9 @@ describe('Migrations', () => {
|
|
|
84
83
|
|
|
85
84
|
test('if some migrations have been run before, runs only the remaining migrations', async () => {
|
|
86
85
|
space.properties['test.version'] = 2;
|
|
87
|
-
space.db.add(
|
|
86
|
+
space.db.add(create(Expando, { namespace: 'test', count: 5 }));
|
|
88
87
|
await Migrations.migrate(space);
|
|
89
|
-
const { objects } = space.db.query({ namespace: 'test' });
|
|
88
|
+
const { objects } = await space.db.query({ namespace: 'test' }).run();
|
|
90
89
|
expect(objects).to.have.length(1);
|
|
91
90
|
expect(objects[0].count).to.equal(15);
|
|
92
91
|
expect(space.properties['test.version']).to.equal(3);
|
|
@@ -95,27 +94,28 @@ describe('Migrations', () => {
|
|
|
95
94
|
test('if all migrations have been run before, does nothing', async () => {
|
|
96
95
|
space.properties['test.version'] = 3;
|
|
97
96
|
await Migrations.migrate(space);
|
|
98
|
-
const { objects } = space.db.query({ namespace: 'test' });
|
|
97
|
+
const { objects } = await space.db.query({ namespace: 'test' }).run();
|
|
99
98
|
expect(objects).to.have.length(0);
|
|
100
99
|
});
|
|
101
100
|
|
|
102
101
|
test('if target version is specified, runs only the migrations up to that version', async () => {
|
|
103
102
|
await Migrations.migrate(space, 2);
|
|
104
|
-
const { objects } = space.db.query({ namespace: 'test' });
|
|
103
|
+
const { objects } = await space.db.query({ namespace: 'test' }).run();
|
|
105
104
|
expect(objects).to.have.length(1);
|
|
106
105
|
expect(objects[0].count).to.equal(2);
|
|
107
106
|
expect(space.properties['test.version']).to.equal(2);
|
|
108
107
|
});
|
|
109
108
|
|
|
110
109
|
test('if target version is specified and is lower than current version, runs the down migrations', async () => {
|
|
111
|
-
const query = space.db.query({ namespace: 'test' });
|
|
112
110
|
await Migrations.migrate(space);
|
|
113
|
-
|
|
114
|
-
expect(
|
|
111
|
+
const beforeDowngrade = await space.db.query({ namespace: 'test' }).run();
|
|
112
|
+
expect(beforeDowngrade.objects).to.have.length(1);
|
|
113
|
+
expect(beforeDowngrade.objects[0].count).to.equal(6);
|
|
115
114
|
expect(space.properties['test.version']).to.equal(3);
|
|
116
115
|
await Migrations.migrate(space, 1);
|
|
117
|
-
|
|
118
|
-
expect(
|
|
116
|
+
const afterDowngrade = await space.db.query({ namespace: 'test' }).run();
|
|
117
|
+
expect(afterDowngrade.objects).to.have.length(1);
|
|
118
|
+
expect(afterDowngrade.objects[0].count).to.equal(2);
|
|
119
119
|
expect(space.properties['test.version']).to.equal(1);
|
|
120
120
|
});
|
|
121
121
|
});
|
package/src/migrations.ts
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Space, SpaceState } from '@dxos/client/echo';
|
|
6
6
|
import { invariant } from '@dxos/invariant';
|
|
7
|
-
import type
|
|
7
|
+
import { type MaybePromise } from '@dxos/util';
|
|
8
|
+
|
|
9
|
+
// TODO(burdon): Merge with successor to serialization mechanism in braneframe/types.
|
|
8
10
|
|
|
9
11
|
export type MigrationContext = {
|
|
10
12
|
space: Space;
|