Closed jcerjak closed 9 months ago
If I comment out dbname
in tusker.toml
, then it works. I'm reading https://github.com/bikeshedder/tusker?tab=readme-ov-file#what-does-the-dbname-setting-in-tuskertoml-mean and I don't fully understand when dbname
should be defined.
tusker diff database
does diff the schema against the database specified in the [database]
section. As you haven't created that database you get that error.
This command is meant to be run after you have migrated your database.
Quoting from the README:
Is it possible to diff the schema and/or migrations against an existing database?
Yes. This feature has been added in 0.2. You can pass a
from
andto
argument to thetusker diff
command. Check the output of`tusker diff --help
for more details.(...)
What does the
dbname
setting intusker.toml
mean?When diffing against a ready migrated database this database name is used. This command will print out the difference between the current database schema and the target schema:
Normally you will just run tusker diff
and use the created migrations in a migration management tool of your choice. tusker diff database
is for checking if the migrations were applied correctly.
If I comment out
dbname
intusker.toml
, then it works. I'm reading https://github.com/bikeshedder/tusker?tab=readme-ov-file#what-does-the-dbname-setting-in-tuskertoml-mean and I don't fully understand whendbname
should be defined.
If you do not specify a dbname
it will use the default database which defaults to your current user name.
If that database exists you don't get an error. Still it's probably not what you want as explained in my previous answer.
tusker diff database does diff the schema against the database specified in the [database] section. As you haven't created that database you get that error.
Based on the README I was somehow under the impression that dbname
is an internal database tusker uses when doing the diffs, not my main database. Maybe the README can be clarified a bit? And/or using dbname = "<your db name here>"
in tusker.toml.example
would also help.
This command is meant to be run after you have migrated your database.
I was first trying to export the schema of the existing database, looks like tusker diff database --reverse
does the trick.
tusker diff database
is for checking if the migrations were applied correctly.
I was thinking of also doing roundtrip development. For example, do some schema changes in a GUI tool, then export those changes to git repo for versioning etc. Do you see some potential issues with this approach?
Otherwise feel free to close this issue, apart from potential documentation improvements, the issue is resolved.
For dumping the initial schema from an existing database you should rather be using pg_dump --schema-only
.
If you want to edit your schema inside the database you could use pg_dump --schema-only > schema.sql
to update the schema file and then use tusker diff
to create the migrations.
Personally I prefer editing my schema in files so I can organize them, add comments, use code generators, etc.
If you're editing the database already in a tool maybe that tool already has some kind of diffing mechanism built-in? pgadmin4
does have built-in diffing and is said to be much better than what migra
(the library tusker uses) provides.
The README states that the dbname
is also used when creating the temporary databases:
Tusker also needs to create temporary databases when diffing against the
schema
and/ormigrations
. The two databases are called{dbname}_{timestamp}_schema
and{dbname}_{timestamp}_migrations
.
Thanks for the info @bikeshedder . I've created a PR to include some of this information in the README: https://github.com/bikeshedder/tusker/pull/33
I just merged the PR.
Steps to reproduce the issue:
tusker.toml.example
totusker.toml
and specify database connection string (url
) in[database]
sectiontusker diff database
FATAL: database "tusker" does not exist
is displayedShouldn't matter, but note that I installed by cloning the repo from Github (commit: 166cd9d79544b699604bafe5c0781be41ca7b348), replaced
psycopg2
withpsycopg2-binary
inpyproject.toml
and ranpoetry install
.