Patch won't apply
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 3.4k
- Forks
- 292
- PR merge metrics
- No merged PRs in 30d
Description
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
migrationsdirectories. - 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:
- Why is a
downstatement issued when the file isn't applied in the first place. - Why doesn't the
upstatement apply..
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the bundled sql-migrate binary using the PostgreSQL configuration in dbconfig.yml and migrations/2_test.sql. Compare the up and down commands with the gorp_migrations table and the reported dtruss output. Done means explaining why up reports zero migrations while down executes, then adding a regression test if the relevant test entry point is identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100