Comments (15)
You have to explicitly separate multiple statements using the --;;
notation as described here.
from migratus.
I am using the separator as specified in the docs, e.g.:
create table users (
id serial primary key not null,
created_on timestamp not null default now(),
full_name text not null,
email text not null,
is_active boolean not null default true
)
--;;
create table identities (
id serial primary key not null,
created_on timestamp not null default now(),
user_id int references users(id) not null,
provider text not null,
username text not null,
password_hash text null,
password_salt text null,
is_active boolean not null default true
)
--;;
create table sessions (
id serial primary key not null,
user_id int references users(id) not null,
created_on timestamp not null default now(),
expires_on timestamp not null,
is_active boolean not null default true
)
from migratus.
What version of the library are you using. There was a fix to rethrow the exception in this commit 29c4753 and running up/down should be transaction. So, if you're on a version before 0.8.15
you'd see this issue.
from migratus.
I'm on 0.8.16
.
from migratus.
Hmm another question is what db you're running against.
from migratus.
I'm seeing this problem too, using migratus 0.8.25
with postgresql version 9.4.8
, jdbc driver version 9.4-1206-jdbc4
. Here's a pretty minimal script that fails:
create table users (
id serial primary key
);
--;;
create table adults (
id integer references users primary key,
email text not null unique
);
--;;
create table students (
create table students (
id integer references users primary key,
email text unique,
grade smallint not null
);
Running this generates the expected sql syntax error, but rather than rollback a transaction it leaves the adults
and users
tables in the database.
from migratus.
@yogthos, I'm running Postgres 9.5.0.0
.
from migratus.
From skimming the code, it seems that the only code that runs in a transaction, is each individual up/down statement:
migratus/src/migratus/database.clj
Line 68 in 7aedc8b
You probably want to wrap the entire sequence of migrations in a transaction, like here:
migratus/src/migratus/core.clj
Line 53 in 7aedc8b
from migratus.
The core is data store agnostic, so it wouldn't be the place to wrap JDBC specific transactions. However, each transaction is meant to be independent in any case. It might make sense to stop and as soon as an up statement returns false though, since at that point it wouldn't make sense to apply the rest of transactions.
from migratus.
This would be my proposed solution here. The migrations will stop being applied as soon as any migration fails.
from migratus.
Ah yes, multiple statements in a migration should run in a transaction - not all migrations (as I badly suggested earlier). And if any statement fails, the transaction for that migration should be rolled back.
from migratus.
So, that should be the current behavior. I do think it makes sense to stop further when migration does fail. That's the purpose of the new update.
from migratus.
We've also seen this behaviour: a migration script where the second statement fails (causing an exception which propagates back out of migratus
to our calling code) somehow commits the effect of the first statement to the database (but with no entry in schema_migrations
for the partially-applied migration).
We're running migratus 0.8.20
, on Postgres 9.5, with version 9.4.1208 of the Postgres JDBC driver, and clojure.java.jdbc 0.5.8
.
from migratus.
Found the error: it was incorrect use of sql/with-db-transaction
(opening the transaction, but then proceeding to use the db-spec itself as the DB connection parameter, instead of the transaction), which was fixed (for up migrations at least) by this commit: f24349a. Ie for up migrations, at least, this is fixed in 0.8.28.
Down migrations still incorrectly use db
instead of t-con
as the DB connection parameter. PR incoming.
from migratus.
Thanks for the pr, just pushed out a new version with the fix.
from migratus.
Related Issues (20)
- Censor password in logs when database is configured with a connection URI HOT 1
- Can't compile migratus v1.3.0 or v1.2.9 HOT 1
- Property substitution support HOT 13
- Update `migratus.core/rollback` behavior to roll back last applied migration when no arguments are provided HOT 3
- Add a function to rollback to a target migration similar to migrate-until-just-before for ups HOT 3
- Database locked when attempting to run coded migration HOT 24
- `:migration-dir` paths seem to follow undocumented rules HOT 2
- Migratus running migrations already marked as ran HOT 5
- Migration fails if a comment is present on line with semicolon HOT 5
- Improve Circle CI setup HOT 2
- No method in multimethod 'make-store' for dispatch value: null when passing a hikari connection pool HOT 2
- When error happens, db password information is shown HOT 5
- next.jdbc does not support :connection-uri style :db (yet) HOT 4
- How to know current db tables state/fields? HOT 8
- Paths with "+" characters result in NoSuchFileException HOT 2
- Custom args to migration functions HOT 3
- Sanitation of migration-table-name breaks existing migrations HOT 2
- Tests failing
- Return new file name from migratus/create instead of nil HOT 6
- [BUG] up / down don't appear to be working with code-based migrations HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from migratus.