jackc / tern

The SQL Fan's Migrator
MIT License
925 stars 68 forks source link

Migrations not actually run in a transaction? #44

Closed Preetam closed 2 years ago

Preetam commented 2 years ago

Reading the code for migration, it looks like a transaction is started here:

https://github.com/jackc/tern/blob/ebefbe44196db4180c0ce4ef4244e95d01dc48a8/migrate/migrate.go#L339

but tx is not actually used to execute the SQL, so the migration is not actually run within a transaction.

https://github.com/jackc/tern/blob/ebefbe44196db4180c0ce4ef4244e95d01dc48a8/migrate/migrate.go#L352

@jackc: Am I reading that wrong or is there a bug here?

Preetam commented 2 years ago

Oh, is it because there is no connection pooling so everything's happening in the same connection?

jackc commented 2 years ago

Yes. Since it is a single connection it will be correctly executed even though the code does look suspicious. That code could be made clearer. But I'm also hoping to eliminate explicit transaction handling altogether. See #43.

Preetam commented 2 years ago

Thanks!