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

'migrate' uses the wrong database #32

Open
sybrenstuvel opened this issue Jul 17, 2018 · 3 comments
Open

'migrate' uses the wrong database #32

sybrenstuvel opened this issue Jul 17, 2018 · 3 comments

Comments

@sybrenstuvel
Copy link

After applying the patch in #31, running fragmenta migrate at the top dir of my Fragmenta-CMS project gives me this output:

% fragmenta migrate                          
12:12:18 
------

12:12:18 Opened database at fragmentatest_development for user sybren
12:12:18 Database ERROR pq: relation "fragmenta_metadata" does not exist
12:12:18 Running migration 2018-07-17-115428-Create-Database.sql
12:12:18 Running database creation migration: db/migrate/2018-07-17-115428-Create-Database.sql
12:12:18 psql: FATAL:  database "sybren" does not exist
12:12:18 ERROR loading sql migration:exit status 2
12:12:18 All further migrations cancelled

12:12:18 No migrations to perform at path ./db/migrate

You can see on the first line that it knows the correct database name fragmentatest_development. However, the 5th line shows that the wrong database name sybren is used.

@kennygrant
Copy link
Contributor

Did you perhaps edit your secrets file after generating the site, without adjusting the Create-Database migration (which does exactly what the name would imply)?

If you prefer you can just delete this migration and create the db yourself manually with whatever username/pass combination you wish - this initial migration is just for bootstrapping so that you don't have to fiddle with the db, but it is optional if you wish to name/create a db yourself (as you seem to).

@sybrenstuvel
Copy link
Author

Did you perhaps edit your secrets file after generating the site, without adjusting the Create-Database migration (which does exactly what the name would imply)?

In the code that runs the migration (https://github.com/fragmenta/fragmenta/blob/master/migrate.go#L62) you explicitly do not pass a database name. This makes psql connect to the database named after the current user, which doesn't exist on my system.

I wouldn't expect to have to regenerate anything after changing the database credentials.

@kennygrant
Copy link
Contributor

OK, psql won't run a migration which consists of just creating a role and db (as this one does), so I don't see any solution to that really - you can't run psql against a db which doesn't exist yet (as is the situation when bootstrapping). I usually create the user db when creating a user to avoid exactly this sort of situation (for example your setup precludes you from just connecting to psql without specifying a database to query).

I think in this situation the best solution is not to attempt to use this migration but do your own db setup with your preferred user/db name and just edit the secrets file.

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

2 participants