@dxos/migrations 0.4.10-main.bf8d896 → 0.4.10-main.c16d37b

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/migrations",
3
- "version": "0.4.10-main.bf8d896",
3
+ "version": "0.4.10-main.c16d37b",
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.bf8d896",
24
- "@dxos/echo-schema": "0.4.10-main.bf8d896",
25
- "@dxos/invariant": "0.4.10-main.bf8d896",
26
- "@dxos/util": "0.4.10-main.bf8d896"
23
+ "@dxos/client": "0.4.10-main.c16d37b",
24
+ "@dxos/echo-schema": "0.4.10-main.c16d37b",
25
+ "@dxos/invariant": "0.4.10-main.c16d37b",
26
+ "@dxos/util": "0.4.10-main.c16d37b"
27
27
  },
28
28
  "devDependencies": {},
29
29
  "publishConfig": {
@@ -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 * as E from '@dxos/echo-schema';
11
- import { Expando } 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(E.object(E.Expando, { namespace: 'test', count: 1 }));
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(E.object(Expando, { namespace: 'test', count: 5 }));
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
- expect(query.objects).to.have.length(1);
114
- expect(query.objects[0].count).to.equal(6);
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
- expect(query.objects).to.have.length(1);
118
- expect(query.objects[0].count).to.equal(2);
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
  });