Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch won't apply #41

Open
Dynom opened this issue Oct 11, 2016 · 1 comment
Open

Patch won't apply #41

Dynom opened this issue Oct 11, 2016 · 1 comment

Comments

@Dynom
Copy link

Dynom commented Oct 11, 2016

Hi.

We've got a weird situation. The following happens for every developer in my team, except for me. The patches work fine on my installation.

This patch or anything really, doesn't really matter, won't apply, but the down statement will execute (even though the file isn't in the gorp_migrations table [1])

Background info

  • Postgres backend
  • Latest sql-migrate release
  • The sql-migrate binary is distributed as part of the repository all migrations are in. People simply re-use the bundled (stand-alone) binary
  • We have multiple migrations directories.
  • Everything works fine when creating a new database, all patches work as intended.

The patch

It can be anything really, doesn't really matter. Single lines, no lines, without statement start/end tags, doesn't make a difference.

-- +migrate Up
-- +migrate StatementBegin

CREATE TABLE foo (
  bar varchar(50)
);

-- +migrate StatementEnd

-- +migrate Down
-- +migrate StatementBegin

DROP TABLE foo;

-- +migrate StatementEnd

The sql-migrate up dtruss output

Command: sudo dtruss ../sql-migrate up

Applied 0 migrations
SYSCALL(args)        = return
thread_selfid(0x0, 0x0, 0x0)         = 513675 0
open(".\0", 0x0, 0x1)        = 3 0
fstat64(0x3, 0x7FFF5FBFE590, 0x1)        = 0 0
fcntl(0x3, 0x32, 0x7FFF5FBFE830)         = 0 0
close(0x3)       = 0 0
stat64("/Users/x/y/DBMigrate/content\0", 0x7FFF5FBFE500, 0x7FFF5FBFE830)         = 0 0
[..]
read(0x5, "N\0", 0x1000)         = 141 0
open("migrations/\0", 0x1000000, 0x0)        = 7 0
getdirentries64(0x7, 0xC4201E8000, 0x1000)       = 200 0
getdirentries64(0x7, 0xC4201E8000, 0x1000)       = 0 0
lstat64("migrations//0_initial-content.sql\0", 0xC420068788, 0x1000)         = 0 0
[..]
lstat64("migrations//2_test.sql\0", 0xC420068928, 0x1000)        = 0 0
[..]
open("migrations/2_test.sql\0", 0x1000000, 0x0)      = 10 0
lseek(0xA, 0x0, 0x0)         = 0 0
read(0xA, "-- +migrate Up\n\nCREATE TABLE foo (\n\t  bar varchar(50)\n);\n\n-- +migrate Down\n\nDROP TABLE foo;\n\n\0", 0x1000)      = 93 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
read(0xA, "\0", 0xFA3)       = 0 0
lseek(0xA, 0x0, 0x0)         = 0 0
read(0xA, "-- +migrate Up\n\nCREATE TABLE foo (\n\t  bar varchar(50)\n);\n\n-- +migrate Down\n\nDROP TABLE foo;\n\n\0", 0x1000)      = 93 0
read(0xA, "\0", 0xFA3)       = 0 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
write(0x5, "Q\0", 0x23)      = 35 0
read(0x5, "\0", 0x1000)      = -1 Err#35
kevent(0x6, 0x0, 0x0)        = 1 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
kevent(0x6, 0x0, 0x0)        = 1 0
read(0x5, "T\0", 0x1000)         = 475 0
write(0x1, "Applied 0 migrations\0", 0x14)       = 20 0
write(0x1, "\n\0", 0x1)      = 1 0

The sql-migrate down dtruss output

Migration failed: pq: table "foo" does not exist handling 2_test.sql
SYSCALL(args)        = return
thread_selfid(0x0, 0x0, 0x0)         = 514159 0
open(".\0", 0x0, 0x1)        = 3 0
fstat64(0x3, 0x7FFF5FBFE580, 0x1)        = 0 0
fcntl(0x3, 0x32, 0x7FFF5FBFE820)         = 0 0
close(0x3)       = 0 0
stat64("/Users/x/y/DBMigrate/content\0", 0x7FFF5FBFE4F0, 0x7FFF5FBFE820)         = 0 0
[..]
open("dbconfig.yml\0", 0x1000000, 0x0)       = 3 0
fstat64(0x3, 0xC42007C2A8, 0x0)      = 0 0
read(0x3, "development:\n    dialect: postgres\n    datasource: host=localhost user=postgres dbname=content sslmode=disable connect_timeout=10\n    dir: migrations/\n    table: gorp_migrations\n\nstaging:\n    dialect: pos", 0x45F)      = 607 0
read(0x3, "\0", 0x200)       = 0 0
close(0x3)       = 0 0
[..]
open("migrations/\0", 0x1000000, 0x0)        = 7 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
getdirentries64(0x7, 0xC420206000, 0x1000)       = 200 0
getdirentries64(0x7, 0xC420206000, 0x1000)       = 0 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
lstat64("migrations//0_initial-content.sql\0", 0xC42007C6B8, 0x1000)         = 0 0
[..]
lstat64("migrations//2_test.sql\0", 0xC42007C928, 0x1000)        = 0 0
[..]
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
read(0x9, "\0", 0xF52)       = 0 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
open("migrations/2_test.sql\0", 0x1000000, 0x0)      = 10 0
lseek(0xA, 0x0, 0x0)         = 0 0
read(0xA, "-- +migrate Up\n\nCREATE TABLE foo (\n\t  bar varchar(50)\n);\n\n-- +migrate Down\n\nDROP TABLE foo;\n\n\0", 0x1000)      = 93 0
read(0xA, "\0", 0xFA3)       = 0 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
lseek(0xA, 0x0, 0x0)         = 0 0
read(0xA, "-- +migrate Up\n\nCREATE TABLE foo (\n\t  bar varchar(50)\n);\n\n-- +migrate Down\n\nDROP TABLE foo;\n\n\0", 0x1000)      = 93 0
read(0xA, "\0", 0xFA3)       = 0 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
write(0x5, "Q\0", 0x23)      = 35 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
read(0x5, "\0", 0x1000)      = -1 Err#35
kevent(0x6, 0x0, 0x0)        = 1 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
kevent(0x6, 0x0, 0x0)        = 1 0
read(0x5, "T\0", 0x1000)         = 475 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
write(0x5, "Q\0", 0xB)       = 11 0
read(0x5, "\0", 0x1000)      = -1 Err#35
kevent(0x6, 0x0, 0x0)        = 1 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
kevent(0x6, 0x0, 0x0)        = 1 0
read(0x5, "C\0", 0x1000)         = 17 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
write(0x5, "Q\0", 0x28)      = 40 0
read(0x5, "\0", 0x1000)      = -1 Err#35
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
kevent(0x6, 0x0, 0x0)        = 1 0
kevent(0x6, 0x0, 0x0)        = 1 0
read(0x5, "E\0", 0x1000)         = 97 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
write(0x5, "Q\0", 0xE)       = 14 0
read(0x5, "\0", 0x1000)      = -1 Err#35
kevent(0x6, 0x0, 0x0)        = 1 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
kevent(0x6, 0x0, 0x0)        = 1 0
read(0x5, "C\0", 0x1000)         = 20 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
write(0x1, "Migration failed: pq: table \"foo\" does not exist handling 2_test.sql\0", 0x44)         = 68 0
write(0x1, "\n\0", 0x1)      = 1 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = 0 0
select(0x0, 0x0, 0x0, 0x0, 0x700000080DC8)       = -1 Err#4

Questions:

  1. Why is a down statement issued when the file isn't applied in the first place.
  2. Why doesn't the up statement apply..
@Dynom
Copy link
Author

Dynom commented Oct 12, 2016

For now we've solved it by using a different table for each scheme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant