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

Migration in a Postgresql database does not migrate in the specific schema. #11

Open
jun1111 opened this issue Oct 4, 2016 · 13 comments
Labels

Comments

@jun1111
Copy link

jun1111 commented Oct 4, 2016

I have followed the instruction in the documentation, created two files that will create a pets table and a owners table. I specified a schema name in the database.json file. However when the migration finishes, I found out that the new tables created are in the public schema!


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@wzrdtales
Copy link
Member

Hey @jun1111 ,

unfortunately we can't help you if you don't provide us all informations necessary to reproduce your case.

This means, always post:

  • used node version
  • used npm version
  • used db-migrate version
  • used driver and its version
  • used plugins
  • full output of the verbose run
  • in complex cases a full gist, as an executable proof
  • if necessary used migrations and configuration details (replace sensible informations before posting configs!)

As soon as you provide us all information needed, we have an easy way to reproduce your problem and provide you with the help or bugfix you need.

Thank you.

@jun1111
Copy link
Author

jun1111 commented Oct 5, 2016

node version: v4.4.5
npm version: 2.15.5
db-migrate version: 0.10.0-beta.19
driver: pg
used plugin: pg

database.json file content:
{
"dev": {
"driver": "pg",
"filename": "~/dev.db"
},
"pg": {
"driver": "pg",
"user": "postgres",
"password": "xxx",
"host": "localhost",
"database": "xxx",
"schema": "jun"
}
}

output for command "db-migrate up":
config.schema is undefined
[INFO] Processed migration 20161004171130-create-tables
[INFO] Processed migration 20161004174319-create-another-table
[INFO] Done

@jun1111
Copy link
Author

jun1111 commented Oct 5, 2016

What is the following line in the database.json file for? I copied it from the documentation and left it unchanged.

"filename": "~/dev.db"

@wzrdtales
Copy link
Member

@jun1111 This is no where documented in relation with pg, but with sqlite. I think that should be already answer enough :)

@wzrdtales
Copy link
Member

You also forgot to post the full verbose run, but it hardly seems that you misconfigured db-migrate though. Which command do you used? Really only db-migrate up? If yes, it is going to execute the config of the dev environment you defined.

@wzrdtales
Copy link
Member

Please carefully read https://docs-0-10.dbmigrate.wizardtales.com/Getting%20Started/configuration again to understand how the config is structured. It allows you to define multiple environments though, you seem to confuse this with db configurations instead, which wont work if not using the right environment.

@jun1111
Copy link
Author

jun1111 commented Oct 5, 2016

@wzrdtales Thanks for your reply. Having read the documentation again, I have realized that "pg" is a environment. So I have removed the "dev" section from the database.json file and just kept the "pg" section. I now run it like the following and it works. It created the two tables in the correct schema.

db-migrate up -e pg

@wzrdtales
Copy link
Member

@jun1111 You can also define a different default via "defaultEnv": "pg"

Basically the environment named dev is always the default if defaultEnv does not define otherwise.

@jun1111
Copy link
Author

jun1111 commented Oct 5, 2016

@wzrdtales
Thanks. I have tried "defaultEnv": "pg" and it works.
If I want to do the same migration for multiple schemas, named as say jun_xxxx, what is the best approach?
Thanks.

@wzrdtales
Copy link
Member

Well either you look at scopes with subconfigs or you just define multiple environments for it and execute them one by one. As this sounds as if you intend to do here something programatically you may want to use the module programatically instead.

@jun1111
Copy link
Author

jun1111 commented Oct 5, 2016

@wzrdtales Yes. I need to do it pragmatically. Thanks for your help.

@jun1111
Copy link
Author

jun1111 commented Oct 5, 2016

@wzrdtales Could you explain to me the following line in the created js file. How is it used and should I change it to a sensible value? Thanks.

exports._meta = {
  "version": 1
};

@wzrdtales
Copy link
Member

It defines the protocol version of your migration, and is intended for the transition helper introduced to ease the handling of some breaking changes that have been introduced.

In short, don't touch it, just keep it as it is.

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

No branches or pull requests

2 participants