@elysiumjs/mnemosyne-drizzle 0.1.4 → 0.2.0

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 (56) hide show
  1. package/.omc/state/agent-replay-3920b579-6d8e-4f5f-924a-319202936685.jsonl +7 -0
  2. package/.omc/state/sessions/3920b579-6d8e-4f5f-924a-319202936685/last-tool-error-state.json +7 -0
  3. package/.omc/state/sessions/3920b579-6d8e-4f5f-924a-319202936685/mission-state.json +93 -0
  4. package/.omc/state/sessions/3920b579-6d8e-4f5f-924a-319202936685/pre-tool-advisory-throttle.json +18 -0
  5. package/.omc/state/sessions/3920b579-6d8e-4f5f-924a-319202936685/subagent-tracking-state.json +61 -0
  6. package/.turbo/turbo-build.log +3 -9
  7. package/CHANGELOG.md +40 -0
  8. package/README.md +51 -0
  9. package/dist/commands/migration_generate.command.d.ts +11 -0
  10. package/dist/commands/migration_generate.command.js +1 -0
  11. package/dist/commands/migration_run.command.d.ts +13 -0
  12. package/dist/commands/migration_run.command.js +15 -0
  13. package/dist/database.d.ts +9 -1
  14. package/dist/database.js +1 -0
  15. package/dist/drizzle.module.d.ts +40 -0
  16. package/dist/drizzle.module.js +1 -0
  17. package/dist/index.d.ts +2 -1
  18. package/dist/index.js +1 -2
  19. package/dist/migrations.d.ts +33 -0
  20. package/dist/migrations.js +1 -0
  21. package/dist/model.d.ts +5 -5
  22. package/dist/model.js +1 -0
  23. package/dist/repository.js +1 -0
  24. package/dist/table.d.ts +47 -123
  25. package/dist/table.js +1 -0
  26. package/dist/tenancy.d.ts +3 -3
  27. package/dist/tenancy.js +1 -0
  28. package/package.json +11 -9
  29. package/scripts/minify.ts +10 -0
  30. package/src/commands/migration_generate.command.ts +101 -0
  31. package/src/commands/migration_run.command.ts +160 -0
  32. package/src/database.ts +37 -7
  33. package/src/drizzle.module.ts +97 -0
  34. package/src/index.ts +1 -31
  35. package/src/migrations.ts +100 -0
  36. package/src/model.ts +18 -11
  37. package/src/table.ts +4 -4
  38. package/src/tenancy.ts +5 -5
  39. package/tests/drizzle.module.test.ts +201 -0
  40. package/tests/migrations.test.ts +123 -0
  41. package/tests/setup.ts +0 -10
  42. package/tsconfig.json +2 -2
  43. package/.turbo/turbo-typecheck.log +0 -1
  44. package/coverage/.lcov.info.01ffde0d9f956dce.tmp +0 -14
  45. package/coverage/.lcov.info.2f80a4def3a82099.tmp +0 -343
  46. package/coverage/.lcov.info.560a2daaba0934cd.tmp +0 -366
  47. package/coverage/.lcov.info.7162c9b788dc0bc6.tmp +0 -366
  48. package/coverage/.lcov.info.b57c0b452c3901e5.tmp +0 -17
  49. package/coverage/.lcov.info.c47de8626f331696.tmp +0 -17
  50. package/coverage/.lcov.info.c710a42b25b08349.tmp +0 -343
  51. package/coverage/.lcov.info.dbc8f065467fc8a2.tmp +0 -287
  52. package/coverage/.lcov.info.de180a43301f82c0.tmp +0 -35
  53. package/coverage/.lcov.info.df18163ab929ab1b.tmp +0 -357
  54. package/coverage/.lcov.info.febf711c192f5c0c.tmp +0 -17
  55. package/coverage/lcov.info +0 -357
  56. package/tests/database.test.ts +0 -198
@@ -0,0 +1,123 @@
1
+ // Copyright (c) 2025-present Workbud Technologies Inc. All rights reserved.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ import { describe, expect, it } from 'bun:test';
16
+
17
+ import { getMigrationName, planMigrations } from '../src/migrations';
18
+
19
+ const dir = '/app/src/database/migrations';
20
+
21
+ // Records applied after every migration in these tests was generated.
22
+ const applied = (...names: string[]) =>
23
+ names.map((name) => ({ name, appliedAt: new Date('2027-01-01T00:00:00Z') }));
24
+
25
+ describe('getMigrationName', () => {
26
+ it('should use the file name of a flat migration', () => {
27
+ expect(getMigrationName(`${dir}/0000_users.sql`)).toBe('0000_users.sql');
28
+ });
29
+
30
+ it('should use the folder name of a Drizzle Kit 1.0 migration', () => {
31
+ expect(getMigrationName(`${dir}/20260101120000_users/migration.sql`)).toBe(
32
+ '20260101120000_users'
33
+ );
34
+ });
35
+ });
36
+
37
+ describe('planMigrations', () => {
38
+ it('should run every migration on an empty database, in order', () => {
39
+ const files = [
40
+ `${dir}/20260102000000_posts/migration.sql`,
41
+ `${dir}/20260101000000_users/migration.sql`
42
+ ];
43
+
44
+ expect(planMigrations(files, applied())).toEqual({
45
+ pending: [
46
+ `${dir}/20260101000000_users/migration.sql`,
47
+ `${dir}/20260102000000_posts/migration.sql`
48
+ ],
49
+ renames: []
50
+ });
51
+ });
52
+
53
+ it('should skip migrations already applied under their current name', () => {
54
+ const files = [`${dir}/0000_users.sql`, `${dir}/20260101000000_posts/migration.sql`];
55
+
56
+ expect(planMigrations(files, applied('0000_users.sql', '20260101000000_posts'))).toEqual({
57
+ pending: [],
58
+ renames: []
59
+ });
60
+ });
61
+
62
+ it('should recognise flat migrations that drizzle-kit up moved into folders', () => {
63
+ const files = [
64
+ `${dir}/20250301101500_users/migration.sql`,
65
+ `${dir}/20250302090000_posts/migration.sql`,
66
+ `${dir}/20260101000000_comments/migration.sql`
67
+ ];
68
+
69
+ expect(planMigrations(files, applied('0000_users.sql', '0001_posts.sql'))).toEqual({
70
+ pending: [`${dir}/20260101000000_comments/migration.sql`],
71
+ renames: [
72
+ { from: '0000_users.sql', to: '20250301101500_users' },
73
+ { from: '0001_posts.sql', to: '20250302090000_posts' }
74
+ ]
75
+ });
76
+ });
77
+
78
+ it('should match timestamp-prefixed flat migrations whose prefix differs from the folder', () => {
79
+ const files = [`${dir}/20250301101501_add_users_table/migration.sql`];
80
+
81
+ expect(planMigrations(files, applied('20250301101459_add_users_table.sql'))).toEqual({
82
+ pending: [],
83
+ renames: [
84
+ { from: '20250301101459_add_users_table.sql', to: '20250301101501_add_users_table' }
85
+ ]
86
+ });
87
+ });
88
+
89
+ it('should pair repeated names in order', () => {
90
+ const files = [
91
+ `${dir}/20250301000000_update/migration.sql`,
92
+ `${dir}/20250302000000_update/migration.sql`,
93
+ `${dir}/20250303000000_update/migration.sql`
94
+ ];
95
+
96
+ expect(planMigrations(files, applied('0000_update.sql', '0001_update.sql'))).toEqual({
97
+ pending: [`${dir}/20250303000000_update/migration.sql`],
98
+ renames: [
99
+ { from: '0000_update.sql', to: '20250301000000_update' },
100
+ { from: '0001_update.sql', to: '20250302000000_update' }
101
+ ]
102
+ });
103
+ });
104
+
105
+ it('should not move a record whose flat file is still there', () => {
106
+ const files = [`${dir}/0000_users.sql`, `${dir}/20260101000000_users/migration.sql`];
107
+
108
+ expect(planMigrations(files, applied('0000_users.sql'))).toEqual({
109
+ pending: [`${dir}/20260101000000_users/migration.sql`],
110
+ renames: []
111
+ });
112
+ });
113
+
114
+ it('should run a new migration that reuses the name of a deleted one', () => {
115
+ const files = [`${dir}/20260101000000_update/migration.sql`];
116
+ const records = [{ name: '0003_update.sql', appliedAt: new Date('2025-06-01T00:00:00Z') }];
117
+
118
+ expect(planMigrations(files, records)).toEqual({
119
+ pending: [`${dir}/20260101000000_update/migration.sql`],
120
+ renames: []
121
+ });
122
+ });
123
+ });
package/tests/setup.ts CHANGED
@@ -1,10 +0,0 @@
1
- import 'reflect-metadata';
2
-
3
- import { mock } from 'bun:test';
4
-
5
- mock.module('node:async_hooks', () => ({
6
- AsyncLocalStorage: class {
7
- public run = mock((_map, callback) => callback());
8
- public disable = mock();
9
- }
10
- }));
package/tsconfig.json CHANGED
@@ -3,10 +3,10 @@
3
3
  "compilerOptions": {
4
4
  "outDir": "dist",
5
5
  "declaration": true,
6
- "emitDeclarationOnly": true,
7
6
  "declarationMap": false,
8
7
  "declarationDir": "dist",
9
- "rootDir": "src"
8
+ "rootDir": "src",
9
+ "allowImportingTsExtensions": false
10
10
  },
11
11
  "include": ["src"]
12
12
  }
@@ -1 +0,0 @@
1
- $ tsc --noEmit
@@ -1,14 +0,0 @@
1
- TN:
2
- SF:tests/setup.ts
3
- FNF:1
4
- FNH:0
5
- DA:1,25
6
- DA:3,32
7
- DA:5,0
8
- DA:6,0
9
- DA:7,0
10
- DA:8,0
11
- DA:10,2
12
- LF:7
13
- LH:3
14
- end_of_record
@@ -1,343 +0,0 @@
1
- TN:
2
- SF:../core/dist/index.js
3
- FNF:225
4
- FNH:28
5
- DA:1,0
6
- DA:2,0
7
- DA:3,0
8
- DA:4,0
9
- DA:5,0
10
- DA:6,0
11
- DA:7,0
12
- DA:8,0
13
- DA:9,0
14
- DA:10,0
15
- DA:11,0
16
- DA:12,0
17
- DA:13,0
18
- DA:14,0
19
- DA:15,0
20
- DA:16,0
21
- DA:17,0
22
- DA:18,0
23
- DA:19,1221
24
- LF:19
25
- LH:1
26
- end_of_record
27
- TN:
28
- SF:src/database.ts
29
- FNF:9
30
- FNH:1
31
- DA:20,130
32
- DA:21,108
33
- DA:22,92
34
- DA:23,126
35
- DA:63,114
36
- DA:64,18
37
- DA:65,47
38
- DA:67,0
39
- DA:68,0
40
- DA:69,0
41
- DA:70,0
42
- DA:71,0
43
- DA:72,0
44
- DA:73,75
45
- DA:76,0
46
- DA:77,0
47
- DA:78,0
48
- DA:79,0
49
- DA:80,0
50
- DA:81,0
51
- DA:82,0
52
- DA:83,0
53
- DA:84,0
54
- DA:85,0
55
- DA:86,0
56
- DA:87,0
57
- DA:88,0
58
- DA:89,0
59
- DA:90,0
60
- DA:91,0
61
- DA:92,0
62
- DA:93,0
63
- DA:94,0
64
- DA:95,0
65
- DA:96,0
66
- DA:97,0
67
- DA:98,0
68
- DA:99,0
69
- DA:100,0
70
- DA:101,0
71
- DA:102,0
72
- DA:103,0
73
- DA:104,0
74
- DA:105,0
75
- DA:106,0
76
- DA:107,0
77
- DA:108,0
78
- DA:109,0
79
- DA:110,0
80
- DA:111,0
81
- DA:112,0
82
- DA:113,0
83
- DA:114,0
84
- DA:115,0
85
- DA:116,0
86
- DA:117,0
87
- DA:118,0
88
- DA:119,0
89
- DA:120,0
90
- DA:121,0
91
- DA:122,0
92
- DA:123,0
93
- DA:124,0
94
- DA:125,0
95
- DA:126,0
96
- DA:127,6
97
- DA:129,2
98
- DA:143,98
99
- DA:144,27
100
- DA:145,48
101
- DA:146,28
102
- DA:147,57
103
- DA:148,21
104
- DA:149,24
105
- DA:150,27
106
- DA:151,33
107
- DA:152,25
108
- DA:153,23
109
- DA:154,18
110
- DA:155,20
111
- DA:156,4
112
- DA:157,22
113
- DA:158,87
114
- DA:161,0
115
- DA:162,66
116
- DA:165,0
117
- DA:166,35
118
- DA:168,6
119
- DA:169,2
120
- DA:175,87
121
- LF:90
122
- LH:31
123
- end_of_record
124
- TN:
125
- SF:src/model.ts
126
- FNF:10
127
- FNH:9
128
- DA:18,76
129
- DA:19,62
130
- DA:21,45
131
- DA:35,42
132
- DA:42,42
133
- DA:43,7
134
- DA:44,12
135
- DA:45,3
136
- DA:46,45
137
- DA:54,37
138
- DA:55,10
139
- DA:56,3
140
- DA:57,41
141
- DA:69,37
142
- DA:70,50
143
- DA:71,31
144
- DA:72,15
145
- DA:73,20
146
- DA:74,15
147
- DA:75,20
148
- DA:76,16
149
- DA:77,16
150
- DA:78,0
151
- DA:79,0
152
- DA:80,0
153
- DA:81,0
154
- DA:82,0
155
- DA:83,0
156
- DA:84,0
157
- DA:85,0
158
- DA:86,0
159
- DA:87,0
160
- DA:89,2
161
- DA:105,31
162
- DA:106,13
163
- DA:107,35
164
- DA:110,13
165
- DA:111,41
166
- DA:112,42
167
- DA:113,21
168
- DA:114,40
169
- DA:115,29
170
- DA:116,33
171
- DA:117,14
172
- DA:118,43
173
- DA:119,4
174
- DA:122,21
175
- DA:123,51
176
- DA:124,21
177
- DA:125,16
178
- DA:126,99
179
- DA:128,1
180
- DA:129,4
181
- DA:130,41
182
- DA:131,55
183
- DA:133,2
184
- DA:150,38
185
- DA:151,7
186
- DA:152,9
187
- DA:153,3
188
- DA:154,70
189
- DA:173,27
190
- DA:174,11
191
- DA:175,9
192
- DA:176,16
193
- DA:177,3
194
- DA:178,61
195
- DA:180,50
196
- DA:186,76
197
- DA:187,12
198
- LF:70
199
- LH:60
200
- end_of_record
201
- TN:
202
- SF:src/tenancy.ts
203
- FNF:14
204
- FNH:10
205
- DA:19,112
206
- DA:20,68
207
- DA:21,164
208
- DA:23,76
209
- DA:24,98
210
- DA:30,60
211
- DA:31,62
212
- DA:43,89
213
- DA:44,136
214
- DA:53,99
215
- DA:54,73
216
- DA:55,69
217
- DA:56,5
218
- DA:57,80
219
- DA:58,86
220
- DA:59,44
221
- DA:74,63
222
- DA:78,16
223
- DA:79,22
224
- DA:80,24
225
- DA:81,6
226
- DA:82,59
227
- DA:83,71
228
- DA:84,5
229
- DA:86,98
230
- DA:87,85
231
- DA:88,81
232
- DA:89,5
233
- DA:91,94
234
- DA:92,122
235
- DA:93,96
236
- DA:95,42
237
- DA:110,0
238
- DA:111,0
239
- DA:112,0
240
- DA:113,0
241
- DA:114,0
242
- DA:115,0
243
- DA:116,0
244
- DA:117,0
245
- DA:118,0
246
- DA:119,0
247
- DA:120,0
248
- DA:121,0
249
- DA:122,0
250
- DA:123,7
251
- DA:132,0
252
- DA:133,0
253
- DA:134,0
254
- DA:135,0
255
- DA:136,0
256
- DA:137,0
257
- DA:138,0
258
- DA:139,0
259
- DA:140,0
260
- DA:141,75
261
- DA:150,0
262
- DA:151,0
263
- DA:152,0
264
- DA:153,0
265
- DA:154,0
266
- DA:155,0
267
- DA:156,0
268
- DA:157,0
269
- DA:158,46
270
- DA:169,143
271
- DA:170,72
272
- DA:171,140
273
- DA:172,144
274
- DA:173,122
275
- DA:175,54
276
- DA:176,30
277
- DA:177,34
278
- DA:178,168
279
- DA:179,170
280
- DA:180,9
281
- DA:195,57
282
- DA:196,35
283
- DA:198,54
284
- DA:199,102
285
- DA:200,36
286
- DA:201,16
287
- DA:202,99
288
- DA:204,6
289
- DA:205,9
290
- DA:206,82
291
- DA:207,120
292
- DA:210,16
293
- DA:211,26
294
- DA:212,18
295
- DA:213,20
296
- DA:214,10
297
- DA:216,40
298
- DA:218,2
299
- DA:228,66
300
- DA:229,29
301
- DA:231,56
302
- DA:233,36
303
- DA:236,16
304
- DA:237,24
305
- DA:238,16
306
- DA:239,20
307
- DA:240,10
308
- DA:241,76
309
- DA:242,144
310
- DA:244,94
311
- DA:245,152
312
- DA:246,41
313
- DA:247,8
314
- DA:249,2
315
- LF:110
316
- LH:80
317
- end_of_record
318
- TN:
319
- SF:tests/setup.ts
320
- FNF:3
321
- FNH:1
322
- DA:1,0
323
- DA:2,0
324
- DA:3,0
325
- DA:4,0
326
- DA:5,0
327
- DA:6,30
328
- DA:7,47
329
- DA:8,19
330
- DA:9,2
331
- DA:10,2
332
- LF:10
333
- LH:5
334
- end_of_record
335
- TN:
336
- SF:../mnemosyne/dist/index.js
337
- FNF:53
338
- FNH:12
339
- DA:1,0
340
- DA:2,3197
341
- LF:2
342
- LH:1
343
- end_of_record