ReviewOS

also looking at this

stacks/bun-query-builder

fix(migrate)!: run the directories executeMigration was given

#1138
Merged glennmichael123 wants to merge fix/execute-migration-dirs into main
7 files +348 -49
packages/bun-query-builder/test/migrations.attribute-change.test.tsmodified+13-13
Changes to packages/bun-query-builder/test/migrations.attribute-change.test.ts
@@ -97,7 +97,7 @@ describe('an attribute added after the table was migrated', () => {
9797 useOriginalDatabase()
9898 writeModel(`name: { validation: { rule: {} } }`)
9999 await generateMigration(modelsDir, { dialect: 'sqlite' })
100 await executeMigration(modelsDir)
100 await executeMigration()
101101 })
102102
103103 it('writes a migration for the change', async () => {
@@ -111,7 +111,7 @@ describe('an attribute added after the table was migrated', () => {
111111 })
112112
113113 it('applies it to the database it was generated on', async () => {
114 await executeMigration(modelsDir)
114 await executeMigration()
115115 expect(columnsOf(dbFile, 'widgets')).toContain('colour')
116116 })
117117
@@ -126,7 +126,7 @@ describe('an attribute added after the table was migrated', () => {
126126 // The point of the whole corpus: a teammate clones, migrates, and gets the
127127 // same table. If the ALTER is not in the files, they get yesterday's table.
128128 const fresh = useFreshDatabase()
129 await executeMigration(modelsDir)
129 await executeMigration()
130130 useOriginalDatabase()
131131
132132 expect(columnsOf(fresh, 'widgets')).toContain('name')
@@ -135,7 +135,7 @@ describe('an attribute added after the table was migrated', () => {
135135
136136 it('does not re-run on the machine that already applied it', async () => {
137137 const before = migrationFiles()
138 await executeMigration(modelsDir)
138 await executeMigration()
139139
140140 // Recorded, so it is not replayed — replaying an ADD COLUMN is the
141141 // `duplicate column name` failure that takes the whole run down.
@@ -157,16 +157,16 @@ describe('a series of changes, each landing its own migration', () => {
157157
158158 writeModel(`name: { validation: { rule: {} } }, colour: { validation: { rule: {} } }, size: { validation: { rule: {} } }`)
159159 await generateMigration(modelsDir, { dialect: 'sqlite' })
160 await executeMigration(modelsDir)
160 await executeMigration()
161161
162162 writeModel(`name: { validation: { rule: {} } }, colour: { validation: { rule: {} } }, size: { validation: { rule: {} } }, weight: { validation: { rule: {} } }`)
163163 await generateMigration(modelsDir, { dialect: 'sqlite' })
164 await executeMigration(modelsDir)
164 await executeMigration()
165165
166166 expect(migrationFiles().length).toBe(start + 2)
167167
168168 const fresh = useFreshDatabase()
169 await executeMigration(modelsDir)
169 await executeMigration()
170170 useOriginalDatabase()
171171
172172 const columns = columnsOf(fresh, 'widgets')
@@ -196,12 +196,12 @@ describe('two changes migrated inside the same second', () => {
196196 })
197197
198198 it('runs both, on this machine and on a fresh one', async () => {
199 await executeMigration(modelsDir)
199 await executeMigration()
200200 expect(columnsOf(dbFile, 'widgets')).toContain('finish')
201201 expect(columnsOf(dbFile, 'widgets')).toContain('grade')
202202
203203 const fresh = useFreshDatabase()
204 await executeMigration(modelsDir)
204 await executeMigration()
205205 useOriginalDatabase()
206206
207207 const columns = columnsOf(fresh, 'widgets')
@@ -230,7 +230,7 @@ describe('a migration applied but never recorded', () => {
230230 writeFileSync(orphan, `-- qb:generated\nALTER TABLE widgets ADD COLUMN colour TEXT;\n`)
231231
232232 // `colour` is already on the table, so this SQL cannot succeed.
233 await executeMigration(modelsDir)
233 await executeMigration()
234234
235235 expect(existsSync(orphan)).toBe(true)
236236 expect(columnsOf(dbFile, 'widgets')).toContain('colour')
@@ -244,7 +244,7 @@ describe('a migration applied but never recorded', () => {
244244 // recorded away. Only an unambiguous "already exists" is forgiven, and
245245 // only for a migration the generator wrote.
246246 let threw = false
247 try { await executeMigration(modelsDir) }
247 try { await executeMigration() }
248248 catch { threw = true }
249249 finally { rmSync(broken, { force: true }) }
250250
@@ -267,11 +267,11 @@ describe('the snapshot going missing does not duplicate work', () => {
267267 })
268268
269269 it('leaves the database untouched and still replayable afterwards', async () => {
270 await executeMigration(modelsDir)
270 await executeMigration()
271271 expect(columnsOf(dbFile, 'widgets')).toContain('weight')
272272
273273 const fresh = useFreshDatabase()
274 await executeMigration(modelsDir)
274 await executeMigration()
275275 useOriginalDatabase()
276276 expect(columnsOf(fresh, 'widgets')).toContain('weight')
277277 })