Skip to content

Error: ENOENT: no such file or directory, caused by non-atomic timestamp handling #475

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

Closed
inadarei opened this issue Apr 27, 2017 · 4 comments

Comments

@inadarei
Copy link

inadarei commented Apr 27, 2017

Using:

  1. "db-migrate": "^0.10.0-beta.20",
  2. "db-migrate-mysql": "^1.1.10",

Every once in a while, after creating a migration with something like:

node_modules/db-migrate/bin/db-migrate create --sql-file

entering the desired SQL and then trying to execute it with node_modules/db-migrate/bin/db-migrate up I get an error such as:

> node_modules/db-migrate/bin/db-migrate up

[ERROR] Error: ENOENT: no such file or directory, open '/opt/app/migrations/sqls/20170426175647-[redacted].sql'
    at Error (native)
From previous event:
    at Class.exports.up (/opt/app/migrations/20170426175647-[redacted].js:23:10)
    at Class.<anonymous> (/opt/app/node_modules/db-migrate/lib/skeleton.js:81:41)
From previous event:
    at Class._up (/opt/app/node_modules/db-migrate/lib/skeleton.js:65:12)
    at Class.up (/opt/app/node_modules/db-migrate/lib/skeleton.js:149:17)
    at Object.up (/opt/app/node_modules/db-migrate/lib/migrator.js:112:14)
    at /opt/app/node_modules/db-migrate/lib/migrator.js:178:25
From previous event:
    at /opt/app/node_modules/db-migrate/lib/migrator.js:171:12
    at runCallback (timers.js:651:20)
    at tryOnImmediate (timers.js:624:5)
    at processImmediate [as _immediateCallback] (timers.js:596:5)
From previous event:
    at /opt/app/node_modules/db-migrate/lib/migrator.js:166:39
    at Query._callback (/opt/app/node_modules/db-migrate/lib/migration.js:373:7)
    at Query.Sequence.end (/opt/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:86:24)
    at Query._handleFinalResultPacket (/opt/app/node_modules/mysql/lib/protocol/sequences/Query.js:137:8)
    at Query.EofPacket (/opt/app/node_modules/mysql/lib/protocol/sequences/Query.js:121:8)
    at Protocol._parsePacket (/opt/app/node_modules/mysql/lib/protocol/Protocol.js:280:23)
    at Parser.write (/opt/app/node_modules/mysql/lib/protocol/Parser.js:75:12)
    at Protocol.write (/opt/app/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/opt/app/node_modules/mysql/lib/Connection.js:103:28)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:548:20)

So, the .js file cannot find the SQL file. Ironically, the SQL file is actually there but it is named 20170426175648-[redacted].sql (please note how the last digit differs).

Basically, it's obvious that the timestamp for JS and the SQL are created in two different parts of the code and if enough time lapses for the two timestamps to be different - things break. #sadcatemoji

MANUAL FIX: when this happens I usually just edit the name of -up and -down .sql files to make them the same as the name of the .js file, but obviously a proper fix would be preferrable/desired to prevent such occurrences in the first place.

@gmanriqueUy
Copy link

@wzrdtales whould you like a PR to fix this?

@wzrdtales
Copy link
Member

@gmanriqueUy I always welcome any PR :)

@gmanriqueUy
Copy link

@wzrdtales Awesome. I'll work on this. 😄

@inadarei
Copy link
Author

Thank you!

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

No branches or pull requests

3 participants