masterrecord 1.0.2 → 1.0.4

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.
Files changed (39) hide show
  1. package/Migrations/cli.js +155 -23
  2. package/QueryLanguage/queryMethods.js +8 -0
  3. package/SQLLiteEngine.js +6 -1
  4. package/package.json +1 -1
  5. package/postgresEngine.js +15 -0
  6. package/test/broad-audit.test.js +256 -0
  7. package/test/count-no-from-audit.test.js +124 -0
  8. package/test/edge-cases-audit.test.js +180 -0
  9. package/test/fixtures/broad-audit/config/environments/env.audit.json +1 -0
  10. package/test/fixtures/broad-audit/db/auditctx.sqlite +0 -0
  11. package/test/fixtures/count-no-from/config/environments/env.countfrom.json +1 -0
  12. package/test/fixtures/count-no-from/db/countfromctx.sqlite +0 -0
  13. package/test/fixtures/edge-cases-audit/config/environments/env.edgeaudit.json +1 -0
  14. package/test/fixtures/edge-cases-audit/db/edgectx.sqlite +0 -0
  15. package/test/fixtures/multi-migration-3Rsgm3/app/models/db/migrations/1700000001000_CreateAuthor_migration.js +14 -0
  16. package/test/fixtures/multi-migration-3Rsgm3/app/models/db/migrations/1700000002000_CreateBook_migration.js +14 -0
  17. package/test/fixtures/multi-migration-3Rsgm3/app/models/db/migrations/1700000003000_CreateReview_migration.js +14 -0
  18. package/test/fixtures/multi-migration-3Rsgm3/app/models/db/migrations/multimigctx_contextSnapShot.json +104 -0
  19. package/test/fixtures/multi-migration-3Rsgm3/app/models/multimigctx.js +26 -0
  20. package/test/fixtures/multi-migration-3Rsgm3/config/environments/env.multimig.json +1 -0
  21. package/test/fixtures/multi-migration-3Rsgm3/db/multimigctx.sqlite +0 -0
  22. package/test/fixtures/multi-migration-3Rsgm3/package.json +1 -0
  23. package/test/fixtures/multi-migration-GAf8bq/app/models/db/migrations/1700000001000_CreateAuthor_migration.js +14 -0
  24. package/test/fixtures/multi-migration-GAf8bq/app/models/db/migrations/1700000002000_CreateBook_migration.js +14 -0
  25. package/test/fixtures/multi-migration-GAf8bq/app/models/db/migrations/1700000003000_CreateReview_migration.js +14 -0
  26. package/test/fixtures/multi-migration-GAf8bq/app/models/db/migrations/multimigctx_contextSnapShot.json +96 -0
  27. package/test/fixtures/multi-migration-GAf8bq/app/models/multimigctx.js +26 -0
  28. package/test/fixtures/multi-migration-GAf8bq/config/environments/env.multimig.json +1 -0
  29. package/test/fixtures/multi-migration-GAf8bq/db/multimigctx.sqlite +0 -0
  30. package/test/fixtures/multi-migration-GAf8bq/package.json +1 -0
  31. package/test/fixtures/multi-migration-QZg3WH/app/models/db/migrations/1700000001000_CreateAuthor_migration.js +14 -0
  32. package/test/fixtures/multi-migration-QZg3WH/app/models/db/migrations/1700000002000_CreateBook_migration.js +14 -0
  33. package/test/fixtures/multi-migration-QZg3WH/app/models/db/migrations/1700000003000_CreateReview_migration.js +14 -0
  34. package/test/fixtures/multi-migration-QZg3WH/app/models/db/migrations/multimigctx_contextSnapShot.json +96 -0
  35. package/test/fixtures/multi-migration-QZg3WH/app/models/multimigctx.js +26 -0
  36. package/test/fixtures/multi-migration-QZg3WH/config/environments/env.multimig.json +1 -0
  37. package/test/fixtures/multi-migration-QZg3WH/db/multimigctx.sqlite +0 -0
  38. package/test/fixtures/multi-migration-QZg3WH/package.json +1 -0
  39. package/test/update-database-multi.test.js +239 -0
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Verifies the `.count()` without-prior-`.where()` bug is resolved on
3
+ * all three engines. The SQLite bug manifested because SQLite's getEntity
4
+ * returned "" on fallthrough (MySQL/Postgres returned the name), plus
5
+ * queryMethods.count() didn't bootstrap the entityMap like single()/toList()
6
+ * did. Both fixes are engine-agnostic; this test verifies no engine
7
+ * regresses.
8
+ *
9
+ * Strategy: build a query state via the real fluent API, then feed it to
10
+ * each engine's COUNT path. Assert the generated SQL has a FROM clause
11
+ * and includes COUNT(*).
12
+ */
13
+
14
+ import { test } from 'node:test';
15
+ import assert from 'node:assert/strict';
16
+ import fs from 'node:fs';
17
+ import path from 'node:path';
18
+ import { fileURLToPath } from 'node:url';
19
+
20
+ process.env.master = 'countfrom';
21
+
22
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
23
+ const fixturesDir = path.join(__dirname, 'fixtures', 'count-no-from');
24
+ const envDir = path.join(fixturesDir, 'config', 'environments');
25
+ const dbDir = path.join(fixturesDir, 'db');
26
+ const dbFile = path.join(dbDir, 'countctx.sqlite');
27
+
28
+ fs.mkdirSync(envDir, { recursive: true });
29
+ fs.mkdirSync(dbDir, { recursive: true });
30
+ if (fs.existsSync(dbFile)) fs.rmSync(dbFile);
31
+
32
+ fs.writeFileSync(
33
+ path.join(envDir, 'env.countfrom.json'),
34
+ JSON.stringify({
35
+ CountFromCtx: {
36
+ type: 'better-sqlite3',
37
+ connection: dbDir + path.sep,
38
+ },
39
+ })
40
+ );
41
+
42
+ const { default: context } = await import('../context.js');
43
+ const { default: SQLiteEngine } = await import('../SQLLiteEngine.js');
44
+ const { default: MySQLEngine } = await import('../mySQLEngine.js');
45
+ const { default: PostgresEngine } = await import('../postgresEngine.js');
46
+
47
+ class Thing {
48
+ id(db) { db.integer().primary().auto(); }
49
+ label(db) { db.string(); }
50
+ }
51
+
52
+ class CountFromCtx extends context {
53
+ constructor() {
54
+ super();
55
+ this.env(envDir);
56
+ this.dbset(Thing);
57
+ }
58
+ }
59
+
60
+ {
61
+ const ctx = new CountFromCtx();
62
+ ctx._SQLEngine.db.exec(`
63
+ CREATE TABLE IF NOT EXISTS Thing (
64
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
65
+ label TEXT
66
+ );
67
+ `);
68
+ const insert = ctx._SQLEngine.db.prepare('INSERT INTO Thing (label) VALUES (?)');
69
+ insert.run('a'); insert.run('b'); insert.run('c'); insert.run('d');
70
+ await ctx.close();
71
+ }
72
+
73
+ // End-to-end SQLite test — the only engine we can actually run.
74
+ test('SQLite: .count() with no prior .where() returns the correct row count (not 1)', async () => {
75
+ const db = new CountFromCtx();
76
+ const n = await db.Thing.count();
77
+ assert.equal(n, 4, 'count() must reflect actual row count, not silently return 1');
78
+ await db.close();
79
+ });
80
+
81
+ // For MySQL and Postgres, we snapshot the SQL that getCount would build.
82
+ // We can't run them without a connection, but the string output is enough
83
+ // to prove the FROM clause and COUNT(*) are present.
84
+ function snapshotFluentState() {
85
+ const ctx = new CountFromCtx();
86
+ // Mirror what `.count()` does internally: bootstrap entityMap via skipClause
87
+ // when the user calls count() without a prior .where().
88
+ const builder = ctx.Thing;
89
+ if (builder.__queryObject.script.entityMap.length === 0) {
90
+ builder.__queryObject.skipClause(ctx.Thing.__entity.__name);
91
+ }
92
+ const script = builder.__queryObject.script;
93
+ script.count = 'none'; // matches what getCount sets when count is undefined
94
+ const entity = ctx.Thing.__entity;
95
+ ctx.close();
96
+ return { script, entity };
97
+ }
98
+
99
+ test('MySQL: COUNT SQL has a FROM clause even with no prior .where()', () => {
100
+ const { script, entity } = snapshotFluentState();
101
+ const engine = new MySQLEngine();
102
+ const sql = `SELECT ${engine.buildCount(script, entity)} ${engine.buildFrom(script, entity)} ${engine.buildWhere(script, entity)} ${engine.buildAnd(script, entity)}`;
103
+ assert.match(sql, /SELECT\s+COUNT\(\*\)/, 'emits COUNT(*)');
104
+ assert.match(sql, /FROM\s+`Thing`/, 'has FROM clause with backtick-quoted table');
105
+ });
106
+
107
+ test('Postgres: COUNT SQL has a FROM clause even with no prior .where()', () => {
108
+ const { script, entity } = snapshotFluentState();
109
+ const engine = new PostgresEngine();
110
+ const sql = `SELECT ${engine.buildCount(script, entity)} ${engine.buildFrom(script, entity)} ${engine.buildWhere(script, entity)} ${engine.buildAnd(script, entity)}`;
111
+ // Postgres buildCount emits COUNT(alias.*) when count is 'none' — we
112
+ // accept either shape here since the bug under test is about FROM, not
113
+ // the exact COUNT expression.
114
+ assert.match(sql, /SELECT\s+COUNT\(/, 'emits SELECT COUNT(...)');
115
+ assert.match(sql, /FROM\s+Thing/, 'has FROM clause naming the table');
116
+ });
117
+
118
+ test('SQLite engine directly: buildFrom on empty entityMap now produces a valid FROM', () => {
119
+ const engine = new SQLiteEngine();
120
+ const fakeScript = { entityMap: [], parentName: '' };
121
+ const fakeEntity = { __name: 'Thing' };
122
+ const from = engine.buildFrom(fakeScript, fakeEntity);
123
+ assert.match(from, /^FROM\s+Thing\b/, `empty entityMap should now produce a FROM clause; got "${from}"`);
124
+ });
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Second-pass audit: edge cases and less-common API surfaces.
3
+ */
4
+
5
+ import { test } from 'node:test';
6
+ import assert from 'node:assert/strict';
7
+ import fs from 'node:fs';
8
+ import path from 'node:path';
9
+ import { fileURLToPath } from 'node:url';
10
+
11
+ process.env.master = 'edgeaudit';
12
+
13
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
14
+ const fixturesDir = path.join(__dirname, 'fixtures', 'edge-cases-audit');
15
+ const envDir = path.join(fixturesDir, 'config', 'environments');
16
+ const dbDir = path.join(fixturesDir, 'db');
17
+ const dbFile = path.join(dbDir, 'edgectx.sqlite');
18
+
19
+ fs.mkdirSync(envDir, { recursive: true });
20
+ fs.mkdirSync(dbDir, { recursive: true });
21
+ if (fs.existsSync(dbFile)) fs.rmSync(dbFile);
22
+
23
+ fs.writeFileSync(
24
+ path.join(envDir, 'env.edgeaudit.json'),
25
+ JSON.stringify({
26
+ EdgeCtx: {
27
+ type: 'better-sqlite3',
28
+ connection: dbDir + path.sep,
29
+ },
30
+ })
31
+ );
32
+
33
+ const { default: context } = await import('../context.js');
34
+
35
+ class Widget {
36
+ id(db) { db.integer().primary().auto(); }
37
+ sku(db) { db.string(); }
38
+ price(db) { db.integer(); }
39
+ tags(db) {
40
+ db.text().transform({
41
+ toDatabase: v => (typeof v === 'string' ? v : JSON.stringify(v)),
42
+ fromDatabase: v => { try { return JSON.parse(v); } catch { return v; } },
43
+ });
44
+ }
45
+ }
46
+
47
+ class EdgeCtx extends context {
48
+ constructor() {
49
+ super();
50
+ this.env(envDir);
51
+ this.dbset(Widget);
52
+ }
53
+ }
54
+
55
+ {
56
+ const ctx = new EdgeCtx();
57
+ ctx._SQLEngine.db.exec(`
58
+ CREATE TABLE IF NOT EXISTS Widget (
59
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
60
+ sku TEXT,
61
+ price INTEGER,
62
+ tags TEXT
63
+ );
64
+ `);
65
+ const insert = ctx._SQLEngine.db.prepare('INSERT INTO Widget (sku, price, tags) VALUES (?, ?, ?)');
66
+ insert.run('A-1', 10, '["red"]');
67
+ insert.run('A-2', 20, '["red","blue"]');
68
+ insert.run('B-1', 30, '["green"]');
69
+ insert.run('B-2', 40, '[]');
70
+ insert.run('C-1', 50, null);
71
+ await ctx.close();
72
+ }
73
+
74
+ test('count with specific field: .count(w => w.id)', async () => {
75
+ const db = new EdgeCtx();
76
+ const n = await db.Widget.count('w => w.id');
77
+ assert.equal(n, 5);
78
+ await db.close();
79
+ });
80
+
81
+ test('first() returns a single row', async () => {
82
+ const db = new EdgeCtx();
83
+ const row = await db.Widget.first();
84
+ assert.ok(row, 'first() should return a row');
85
+ assert.equal(row.id, 1, 'first() should return the first by primary key');
86
+ await db.close();
87
+ });
88
+
89
+ test('first() on empty result returns null/undefined without throwing', async () => {
90
+ const db = new EdgeCtx();
91
+ const row = await db.Widget.where('w => w.sku == $$', '__nonexistent__').first();
92
+ assert.ok(row == null, 'first() on empty result should return null');
93
+ await db.close();
94
+ });
95
+
96
+ test('.select() narrows returned columns', async () => {
97
+ const db = new EdgeCtx();
98
+ const rows = await db.Widget.select('w => w.sku').orderBy('w => w.id').toList();
99
+ assert.ok(rows.length > 0);
100
+ // .select() is a projection — `price` should not be set on returned rows
101
+ // (though whether it's strictly absent vs undefined depends on the ORM).
102
+ // At minimum sku should be present.
103
+ for (const r of rows) {
104
+ assert.ok(r.sku, 'sku should be present in selected rows');
105
+ }
106
+ await db.close();
107
+ });
108
+
109
+ test('NULL handling in WHERE: == null should match null rows', async () => {
110
+ const db = new EdgeCtx();
111
+ const rows = await db.Widget.where('w => w.tags == null').toList();
112
+ // C-1 has tags=null
113
+ assert.equal(rows.length, 1, `expected exactly 1 row with tags=null, got ${rows.length}`);
114
+ assert.equal(rows[0].sku, 'C-1');
115
+ await db.close();
116
+ });
117
+
118
+ test('NULL handling in WHERE: != null should match non-null rows', async () => {
119
+ const db = new EdgeCtx();
120
+ const rows = await db.Widget.where('w => w.tags != null').toList();
121
+ // A-1, A-2, B-1, B-2 have non-null tags
122
+ assert.equal(rows.length, 4, `expected 4 rows with tags != null, got ${rows.length}`);
123
+ await db.close();
124
+ });
125
+
126
+ test('transformer roundtrip: array saved as JSON and parsed back', async () => {
127
+ const db = new EdgeCtx();
128
+ const a1 = await db.Widget.where('w => w.sku == $$', 'A-1').single();
129
+ assert.ok(Array.isArray(a1.tags), `tags should be parsed to array, got ${typeof a1.tags}`);
130
+ assert.deepEqual(a1.tags, ['red']);
131
+ await db.close();
132
+ });
133
+
134
+ test('update with transformer: modify array, save, reload, array shape preserved', async () => {
135
+ const db = new EdgeCtx();
136
+ const a2 = await db.Widget.where('w => w.sku == $$', 'A-2').single();
137
+ a2.tags = ['yellow', 'purple'];
138
+ await a2.save();
139
+
140
+ const reloaded = await db.Widget.where('w => w.sku == $$', 'A-2').single();
141
+ assert.ok(Array.isArray(reloaded.tags));
142
+ assert.deepEqual(reloaded.tags, ['yellow', 'purple']);
143
+ await db.close();
144
+ });
145
+
146
+ test('chained queries do not leak parameters across calls on the same context', async () => {
147
+ const db = new EdgeCtx();
148
+ const a = await db.Widget.where('w => w.price > $$', 25).toList();
149
+ assert.equal(a.length, 3, 'price > 25 → B-1, B-2, C-1');
150
+
151
+ // Issue a second unrelated query — parameters from the first must not leak
152
+ const b = await db.Widget.where('w => w.price < $$', 15).toList();
153
+ assert.equal(b.length, 1, 'price < 15 → A-1 only; parameters from prev call must not leak');
154
+ await db.close();
155
+ });
156
+
157
+ test('raw() produces the expected rows', async () => {
158
+ const db = new EdgeCtx();
159
+ const rows = await db.Widget.raw('SELECT id, sku FROM Widget WHERE price > 20 ORDER BY id').toList();
160
+ assert.ok(rows.length >= 3);
161
+ await db.close();
162
+ });
163
+
164
+ test('save() on tracked entity that was already deleted does not throw obscure error', async () => {
165
+ const db = new EdgeCtx();
166
+ const w = await db.Widget.where('w => w.sku == $$', 'A-1').single();
167
+ // Manually delete the row behind MasterRecord's back
168
+ db._SQLEngine.db.prepare('DELETE FROM Widget WHERE id = ?').run(w.id);
169
+
170
+ // Attempt to save a modification — expected: either a clean error or a no-op (0 rows affected)
171
+ w.price = 11;
172
+ try {
173
+ await w.save();
174
+ // No error — that's fine, SQLite UPDATE on nonexistent row affects 0 rows silently
175
+ } catch (err) {
176
+ // Also fine, as long as it's a clear error
177
+ assert.ok(err instanceof Error, 'if thrown, must be an Error');
178
+ }
179
+ await db.close();
180
+ });
@@ -0,0 +1 @@
1
+ {"AuditCtx":{"type":"better-sqlite3","connection":"/Users/alexanderrich/Documents/development/opensourceHQ/MasterRecord/test/fixtures/broad-audit/db/"}}
@@ -0,0 +1 @@
1
+ {"CountFromCtx":{"type":"better-sqlite3","connection":"/Users/alexanderrich/Documents/development/opensourceHQ/MasterRecord/test/fixtures/count-no-from/db/"}}
@@ -0,0 +1 @@
1
+ {"EdgeCtx":{"type":"better-sqlite3","connection":"/Users/alexanderrich/Documents/development/opensourceHQ/MasterRecord/test/fixtures/edge-cases-audit/db/"}}
@@ -0,0 +1,14 @@
1
+
2
+ import masterrecord from "file:///Users/alexanderrich/Documents/development/opensourceHQ/MasterRecord/MasterRecord.js";
3
+ class CreateAuthor extends masterrecord.schema {
4
+ constructor(context){ super(context); }
5
+ async up(table){
6
+ await this.init(table);
7
+ await this.createTable(table.Author);
8
+ }
9
+ async down(table){
10
+ await this.init(table);
11
+ await this.dropTable(table.Author);
12
+ }
13
+ }
14
+ export default CreateAuthor;
@@ -0,0 +1,14 @@
1
+
2
+ import masterrecord from "file:///Users/alexanderrich/Documents/development/opensourceHQ/MasterRecord/MasterRecord.js";
3
+ class CreateBook extends masterrecord.schema {
4
+ constructor(context){ super(context); }
5
+ async up(table){
6
+ await this.init(table);
7
+ await this.createTable(table.Book);
8
+ }
9
+ async down(table){
10
+ await this.init(table);
11
+ await this.dropTable(table.Book);
12
+ }
13
+ }
14
+ export default CreateBook;
@@ -0,0 +1,14 @@
1
+
2
+ import masterrecord from "file:///Users/alexanderrich/Documents/development/opensourceHQ/MasterRecord/MasterRecord.js";
3
+ class CreateReview extends masterrecord.schema {
4
+ constructor(context){ super(context); }
5
+ async up(table){
6
+ await this.init(table);
7
+ await this.createTable(table.Review);
8
+ }
9
+ async down(table){
10
+ await this.init(table);
11
+ await this.dropTable(table.Review);
12
+ }
13
+ }
14
+ export default CreateReview;
@@ -0,0 +1,104 @@
1
+ {
2
+ "contextLocation": "../../multimigctx.js",
3
+ "migrationFolder": ".",
4
+ "snapShotLocation": "multimigctx_contextSnapShot.json",
5
+ "schema": [
6
+ {
7
+ "id": {
8
+ "name": "id",
9
+ "type": "integer",
10
+ "primary": true,
11
+ "nullable": false,
12
+ "unique": true,
13
+ "auto": true,
14
+ "cascadeOnDelete": true,
15
+ "lazyLoading": true,
16
+ "isNavigational": false,
17
+ "skipGetFunction": false,
18
+ "valueConversion": true
19
+ },
20
+ "name": {
21
+ "name": "name",
22
+ "type": "string",
23
+ "nullable": true,
24
+ "unique": false,
25
+ "auto": false,
26
+ "cascadeOnDelete": true,
27
+ "lazyLoading": true,
28
+ "isNavigational": false,
29
+ "skipGetFunction": false,
30
+ "valueConversion": true
31
+ },
32
+ "__compositeIndexes": [],
33
+ "__name": "Author"
34
+ },
35
+ {
36
+ "id": {
37
+ "name": "id",
38
+ "type": "integer",
39
+ "primary": true,
40
+ "nullable": false,
41
+ "unique": true,
42
+ "auto": true,
43
+ "cascadeOnDelete": true,
44
+ "lazyLoading": true,
45
+ "isNavigational": false,
46
+ "skipGetFunction": false,
47
+ "valueConversion": true
48
+ },
49
+ "title": {
50
+ "name": "title",
51
+ "type": "string",
52
+ "nullable": true,
53
+ "unique": false,
54
+ "auto": false,
55
+ "cascadeOnDelete": true,
56
+ "lazyLoading": true,
57
+ "isNavigational": false,
58
+ "skipGetFunction": false,
59
+ "valueConversion": true
60
+ },
61
+ "__compositeIndexes": [],
62
+ "__name": "Book"
63
+ },
64
+ {
65
+ "id": {
66
+ "name": "id",
67
+ "type": "integer",
68
+ "primary": true,
69
+ "nullable": false,
70
+ "unique": true,
71
+ "auto": true,
72
+ "cascadeOnDelete": true,
73
+ "lazyLoading": true,
74
+ "isNavigational": false,
75
+ "skipGetFunction": false,
76
+ "valueConversion": true
77
+ },
78
+ "body": {
79
+ "name": "body",
80
+ "type": "string",
81
+ "nullable": true,
82
+ "unique": false,
83
+ "auto": false,
84
+ "cascadeOnDelete": true,
85
+ "lazyLoading": true,
86
+ "isNavigational": false,
87
+ "skipGetFunction": false,
88
+ "valueConversion": true
89
+ },
90
+ "__compositeIndexes": [],
91
+ "__name": "Review"
92
+ }
93
+ ],
94
+ "seedData": {},
95
+ "seedConfig": {
96
+ "generateDownMigrations": false,
97
+ "downStrategy": "delete",
98
+ "deleteByPrimaryKey": true,
99
+ "onRollbackError": "warn",
100
+ "detectCircularDependencies": true,
101
+ "circularStrategy": "warn",
102
+ "defaultStrategy": "insert"
103
+ }
104
+ }
@@ -0,0 +1,26 @@
1
+
2
+ import context from "file:///Users/alexanderrich/Documents/development/opensourceHQ/MasterRecord/context.js";
3
+
4
+ class Author {
5
+ id(db) { db.integer().primary().auto(); }
6
+ name(db) { db.string(); }
7
+ }
8
+ class Book {
9
+ id(db) { db.integer().primary().auto(); }
10
+ title(db) { db.string(); }
11
+ }
12
+ class Review {
13
+ id(db) { db.integer().primary().auto(); }
14
+ body(db) { db.string(); }
15
+ }
16
+
17
+ class multimigctx extends context {
18
+ constructor() {
19
+ super();
20
+ this.env("/Users/alexanderrich/Documents/development/opensourceHQ/MasterRecord/test/fixtures/multi-migration-3Rsgm3/config/environments");
21
+ this.dbset(Author);
22
+ this.dbset(Book);
23
+ this.dbset(Review);
24
+ }
25
+ }
26
+ export default multimigctx;
@@ -0,0 +1 @@
1
+ {"multimigctx":{"type":"better-sqlite3","connection":"/Users/alexanderrich/Documents/development/opensourceHQ/MasterRecord/test/fixtures/multi-migration-3Rsgm3/db/"}}
@@ -0,0 +1 @@
1
+ {"name":"multi-migration-fixture","type":"module"}
@@ -0,0 +1,14 @@
1
+
2
+ import masterrecord from "file:///Users/alexanderrich/Documents/development/opensourceHQ/MasterRecord/MasterRecord.js";
3
+ class CreateAuthor extends masterrecord.schema {
4
+ constructor(context){ super(context); }
5
+ async up(table){
6
+ await this.init(table);
7
+ await this.createTable(table.Author);
8
+ }
9
+ async down(table){
10
+ await this.init(table);
11
+ await this.dropTable(table.Author);
12
+ }
13
+ }
14
+ export default CreateAuthor;
@@ -0,0 +1,14 @@
1
+
2
+ import masterrecord from "file:///Users/alexanderrich/Documents/development/opensourceHQ/MasterRecord/MasterRecord.js";
3
+ class CreateBook extends masterrecord.schema {
4
+ constructor(context){ super(context); }
5
+ async up(table){
6
+ await this.init(table);
7
+ await this.createTable(table.Book);
8
+ }
9
+ async down(table){
10
+ await this.init(table);
11
+ await this.dropTable(table.Book);
12
+ }
13
+ }
14
+ export default CreateBook;
@@ -0,0 +1,14 @@
1
+
2
+ import masterrecord from "file:///Users/alexanderrich/Documents/development/opensourceHQ/MasterRecord/MasterRecord.js";
3
+ class CreateReview extends masterrecord.schema {
4
+ constructor(context){ super(context); }
5
+ async up(table){
6
+ await this.init(table);
7
+ await this.createTable(table.Review);
8
+ }
9
+ async down(table){
10
+ await this.init(table);
11
+ await this.dropTable(table.Review);
12
+ }
13
+ }
14
+ export default CreateReview;
@@ -0,0 +1,96 @@
1
+ {
2
+ "contextLocation": "../../multimigctx.js",
3
+ "migrationFolder": ".",
4
+ "snapShotLocation": "multimigctx_contextSnapShot.json",
5
+ "schema": [
6
+ {
7
+ "id": {
8
+ "name": "id",
9
+ "type": "integer",
10
+ "primary": true,
11
+ "nullable": false,
12
+ "unique": true,
13
+ "auto": true,
14
+ "cascadeOnDelete": true,
15
+ "lazyLoading": true,
16
+ "isNavigational": false,
17
+ "skipGetFunction": false,
18
+ "valueConversion": true
19
+ },
20
+ "name": {
21
+ "name": "name",
22
+ "type": "string",
23
+ "nullable": true,
24
+ "unique": false,
25
+ "auto": false,
26
+ "cascadeOnDelete": true,
27
+ "lazyLoading": true,
28
+ "isNavigational": false,
29
+ "skipGetFunction": false,
30
+ "valueConversion": true
31
+ },
32
+ "__compositeIndexes": [],
33
+ "__name": "Author"
34
+ },
35
+ {
36
+ "id": {
37
+ "name": "id",
38
+ "type": "integer",
39
+ "primary": true,
40
+ "nullable": false,
41
+ "unique": true,
42
+ "auto": true,
43
+ "cascadeOnDelete": true,
44
+ "lazyLoading": true,
45
+ "isNavigational": false,
46
+ "skipGetFunction": false,
47
+ "valueConversion": true
48
+ },
49
+ "title": {
50
+ "name": "title",
51
+ "type": "string",
52
+ "nullable": true,
53
+ "unique": false,
54
+ "auto": false,
55
+ "cascadeOnDelete": true,
56
+ "lazyLoading": true,
57
+ "isNavigational": false,
58
+ "skipGetFunction": false,
59
+ "valueConversion": true
60
+ },
61
+ "__compositeIndexes": [],
62
+ "__name": "Book"
63
+ },
64
+ {
65
+ "id": {
66
+ "name": "id",
67
+ "type": "integer",
68
+ "primary": true,
69
+ "nullable": false,
70
+ "unique": true,
71
+ "auto": true,
72
+ "cascadeOnDelete": true,
73
+ "lazyLoading": true,
74
+ "isNavigational": false,
75
+ "skipGetFunction": false,
76
+ "valueConversion": true
77
+ },
78
+ "body": {
79
+ "name": "body",
80
+ "type": "string",
81
+ "nullable": true,
82
+ "unique": false,
83
+ "auto": false,
84
+ "cascadeOnDelete": true,
85
+ "lazyLoading": true,
86
+ "isNavigational": false,
87
+ "skipGetFunction": false,
88
+ "valueConversion": true
89
+ },
90
+ "__compositeIndexes": [],
91
+ "__name": "Review"
92
+ }
93
+ ],
94
+ "seedData": {},
95
+ "seedConfig": {}
96
+ }
@@ -0,0 +1,26 @@
1
+
2
+ import context from "file:///Users/alexanderrich/Documents/development/opensourceHQ/MasterRecord/context.js";
3
+
4
+ class Author {
5
+ id(db) { db.integer().primary().auto(); }
6
+ name(db) { db.string(); }
7
+ }
8
+ class Book {
9
+ id(db) { db.integer().primary().auto(); }
10
+ title(db) { db.string(); }
11
+ }
12
+ class Review {
13
+ id(db) { db.integer().primary().auto(); }
14
+ body(db) { db.string(); }
15
+ }
16
+
17
+ class multimigctx extends context {
18
+ constructor() {
19
+ super();
20
+ this.env("/Users/alexanderrich/Documents/development/opensourceHQ/MasterRecord/test/fixtures/multi-migration-GAf8bq/config/environments");
21
+ this.dbset(Author);
22
+ this.dbset(Book);
23
+ this.dbset(Review);
24
+ }
25
+ }
26
+ export default multimigctx;