Skip to content

Commit

Permalink
don’t prepare all queries before running
Browse files Browse the repository at this point in the history
If you add a table and then create a trigger (or whatever), preparing the dependent query throws an error
  • Loading branch information
ryanflorence committed Dec 8, 2024
1 parent c5cd970 commit 76d83f4
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/lib/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,10 @@ export class Migrator {
.map(stmt => stmt.trim())
.filter(stmt => stmt.length > 0);

// Validate all statements first
let queries = [];
try {
for (let statement of statements) {
queries.push(db.prepare(statement));
}
} catch (error) {
console.error(`Error preparing sql for migration: ${fileName}`);
throw error;
}

if (!this.options.dry) {
db.transaction(() => {
for (let query of queries) {
query.run();
for (let statement of statements) {
db.prepare(statement).run();
}

// Track migration in _migralite table
Expand Down

0 comments on commit 76d83f4

Please sign in to comment.