@dxos/migrations 0.4.10-main.4c7b3fa → 0.4.10-main.4d26ea7
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/package.json +5 -5
- package/src/migrations.test.ts +14 -13
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.4d26ea7",
|
|
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/echo-schema": "0.4.10-main.
|
|
24
|
-
"@dxos/client": "0.4.10-main.
|
|
25
|
-
"@dxos/
|
|
26
|
-
"@dxos/
|
|
23
|
+
"@dxos/echo-schema": "0.4.10-main.4d26ea7",
|
|
24
|
+
"@dxos/client": "0.4.10-main.4d26ea7",
|
|
25
|
+
"@dxos/invariant": "0.4.10-main.4d26ea7",
|
|
26
|
+
"@dxos/util": "0.4.10-main.4d26ea7"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {},
|
|
29
29
|
"publishConfig": {
|
package/src/migrations.test.ts
CHANGED
|
@@ -19,7 +19,7 @@ Migrations.define('test', [
|
|
|
19
19
|
space.db.add(create(Expando, { namespace: 'test', count: 1 }));
|
|
20
20
|
},
|
|
21
21
|
down: async ({ space }) => {
|
|
22
|
-
const { objects } = space.db.query({ namespace: 'test' });
|
|
22
|
+
const { objects } = await space.db.query({ namespace: 'test' }).run();
|
|
23
23
|
for (const object of objects) {
|
|
24
24
|
space.db.remove(object);
|
|
25
25
|
}
|
|
@@ -28,7 +28,7 @@ Migrations.define('test', [
|
|
|
28
28
|
{
|
|
29
29
|
version: 2,
|
|
30
30
|
up: async ({ space }) => {
|
|
31
|
-
const { objects } = space.db.query({ namespace: 'test' });
|
|
31
|
+
const { objects } = await space.db.query({ namespace: 'test' }).run();
|
|
32
32
|
for (const object of objects) {
|
|
33
33
|
object.count = 2;
|
|
34
34
|
}
|
|
@@ -40,13 +40,13 @@ Migrations.define('test', [
|
|
|
40
40
|
{
|
|
41
41
|
version: 3,
|
|
42
42
|
up: async ({ space }) => {
|
|
43
|
-
const { objects } = space.db.query({ namespace: 'test' });
|
|
43
|
+
const { objects } = await space.db.query({ namespace: 'test' }).run();
|
|
44
44
|
for (const object of objects) {
|
|
45
45
|
object.count *= 3;
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
down: async ({ space }) => {
|
|
49
|
-
const { objects } = space.db.query({ namespace: 'test' });
|
|
49
|
+
const { objects } = await space.db.query({ namespace: 'test' }).run();
|
|
50
50
|
for (const object of objects) {
|
|
51
51
|
object.count /= 3;
|
|
52
52
|
}
|
|
@@ -75,7 +75,7 @@ describe('Migrations', () => {
|
|
|
75
75
|
|
|
76
76
|
test('if no migrations have been run before, runs all migrations', async () => {
|
|
77
77
|
await Migrations.migrate(space);
|
|
78
|
-
const { objects } = space.db.query({ namespace: 'test' });
|
|
78
|
+
const { objects } = await space.db.query({ namespace: 'test' }).run();
|
|
79
79
|
expect(objects).to.have.length(1);
|
|
80
80
|
expect(objects[0].count).to.equal(6);
|
|
81
81
|
expect(space.properties['test.version']).to.equal(3);
|
|
@@ -85,7 +85,7 @@ describe('Migrations', () => {
|
|
|
85
85
|
space.properties['test.version'] = 2;
|
|
86
86
|
space.db.add(create(Expando, { namespace: 'test', count: 5 }));
|
|
87
87
|
await Migrations.migrate(space);
|
|
88
|
-
const { objects } = space.db.query({ namespace: 'test' });
|
|
88
|
+
const { objects } = await space.db.query({ namespace: 'test' }).run();
|
|
89
89
|
expect(objects).to.have.length(1);
|
|
90
90
|
expect(objects[0].count).to.equal(15);
|
|
91
91
|
expect(space.properties['test.version']).to.equal(3);
|
|
@@ -94,27 +94,28 @@ describe('Migrations', () => {
|
|
|
94
94
|
test('if all migrations have been run before, does nothing', async () => {
|
|
95
95
|
space.properties['test.version'] = 3;
|
|
96
96
|
await Migrations.migrate(space);
|
|
97
|
-
const { objects } = space.db.query({ namespace: 'test' });
|
|
97
|
+
const { objects } = await space.db.query({ namespace: 'test' }).run();
|
|
98
98
|
expect(objects).to.have.length(0);
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
test('if target version is specified, runs only the migrations up to that version', async () => {
|
|
102
102
|
await Migrations.migrate(space, 2);
|
|
103
|
-
const { objects } = space.db.query({ namespace: 'test' });
|
|
103
|
+
const { objects } = await space.db.query({ namespace: 'test' }).run();
|
|
104
104
|
expect(objects).to.have.length(1);
|
|
105
105
|
expect(objects[0].count).to.equal(2);
|
|
106
106
|
expect(space.properties['test.version']).to.equal(2);
|
|
107
107
|
});
|
|
108
108
|
|
|
109
109
|
test('if target version is specified and is lower than current version, runs the down migrations', async () => {
|
|
110
|
-
const query = space.db.query({ namespace: 'test' });
|
|
111
110
|
await Migrations.migrate(space);
|
|
112
|
-
|
|
113
|
-
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);
|
|
114
114
|
expect(space.properties['test.version']).to.equal(3);
|
|
115
115
|
await Migrations.migrate(space, 1);
|
|
116
|
-
|
|
117
|
-
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);
|
|
118
119
|
expect(space.properties['test.version']).to.equal(1);
|
|
119
120
|
});
|
|
120
121
|
});
|