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

Can't migrate on Windows #83

Closed
maksnester opened this issue Nov 3, 2017 · 16 comments
Closed

Can't migrate on Windows #83

maksnester opened this issue Nov 3, 2017 · 16 comments

Comments

@maksnester
Copy link

I have set of migrations which works perfectly on linux systems, but when I try to run migrations on Windows machine I get the following:

{ProjectPath}>yarn run migrate
yarn run v1.2.1
$ node -r dotenv/config node_modules/.bin/migrate --state-file runtime/.migrate
{ProjectPath}\node_modules\.bin\migrate:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:588:28)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Function.Module.runMain (module.js:665:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

This is migrate script command:

"migrate": "node -r dotenv/config node_modules/.bin/migrate --state-file runtime/.migrate",

@wesleytodd
Copy link
Collaborator

Hey @alendorff. I was actually going to release the 1.0.0 version this week. Do you think you could try that? You can install it now with npm i migrate@next or whatever the compatible yarn command is (sorry I dont use yarn).

@maksnester
Copy link
Author

Alas, but situation with 1.0.0-2 is exactly the same.

@wesleytodd
Copy link
Collaborator

Interesting. Have you tried with npm? Also what node version?

@maksnester
Copy link
Author

Yes, it's the same with npm.


>npm -v
5.4.2

>yarn -v
1.2.1

>node -v
v8.7.0

@wesleytodd
Copy link
Collaborator

Ok, found it. npm creates a node_modules/.bin/migrate.cmd for use on windows. In my windows vm I tried adding a package.json script like this:

{
  "scripts": {
    "migrate": "migrate"
  }
}

Then ran:

> npm run migrate init
> npm run migrate

And that seemed to work. Hope that helps.

@maksnester
Copy link
Author

maksnester commented Nov 3, 2017

Yes, thank you, it seems like simple migrate works fine. But in my script I wanted to preload environment variables by executing dotenv/config (node -r dotenv/config) module. Because I use some configs in migrations like db url, etc... But, unfortunately, it doesn't work on windows.
However, it's not library issue itself.
Hints about how to resolve that issue are welcomed anyway.

@LinusU
Copy link
Collaborator

LinusU commented Nov 3, 2017

Not really a solution, but db-migrate loads .env automatically (using dotenv) and I would personally like it if this module did the same. It's quite convenient, for exactly the use case you are using it for, and I believe it to be somewhat of a standard to have .env files...

@wesleytodd
Copy link
Collaborator

I think maybe since I don't use windows I don't understand the use case. Can you not just do:

$ MY_DB_PASS=foo npm run migrate

Or any other method of setting env variables?

Would love to get input on how people want this to work.

@maksnester
Copy link
Author

@wesleytodd yes, of course it will work, but it's a bit inconvenient.

@wesleytodd
Copy link
Collaborator

Could you suggest what you would rather have?

@maksnester
Copy link
Author

@wesleytodd I would rather have .env file :)

@wesleytodd
Copy link
Collaborator

Can you elaborate? Should it be loaded in with an --env flag? Like --env path/to/file. Where the file is like:

FOO=bar
BAZ=foz

I always used the system I am on to manage my environment variables, or just a small bash script wrapper during development if I need it. I have never felt the need for a tool to support them directly, so I need more info on how you would want it to work.

@wesleytodd
Copy link
Collaborator

@LinusU mentioned this module: https://www.npmjs.com/package/dotenv

Is this what you are talking about?

@maksnester
Copy link
Author

Yes, --env flag could be a pretty usable for that case, I think.
If we're talking about dotenv library, then default path for .env file is a project root, but it's not mandatory, so, it's better to have an option to specify custom path. But should those .env files work by default - I don't know, it's up to you :) It would be convenient for me personally, but I can't say for everyone.

@maksnester
Copy link
Author

@wesleytodd yes, it's exactly what I meant.

@wesleytodd
Copy link
Collaborator

wesleytodd commented Nov 5, 2017

Awesome, this I can go on. I just read through that module module's readme and it looks solid. I will work on support for this. Thanks for following up with me!

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

3 participants