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

Get final database schema after all migrations are run #305

Open
vasilakisfil opened this issue Jan 11, 2024 · 3 comments
Open

Get final database schema after all migrations are run #305

vasilakisfil opened this issue Jan 11, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@vasilakisfil
Copy link
Contributor

Migrations are just diffs over time, not the final state of the database schema nor the source of truth. The actual database schema, after running all migrations, is the source of truth. Is there a way to get that using refinery, in an sql or barrel format ?

I guess an alternative is to use pg_dump and specify --schema-only but would be great if refinery could extract that from all migrations somehow.

@jxs
Copy link
Member

jxs commented Jan 22, 2024

Hi, and thanks for your interest! Can you give a practical use case for this change?

@vasilakisfil
Copy link
Contributor Author

  • Old migrations may fail to apply correctly, or even be possible to get applied at all, if those migrations use changing external dependencies or rely on application code which evolves separately from the migrations.

  • Schema is the source of truth, and it is also committed to the repo. Figuring out the state of the db (relations, constraints etc) from migrations is impossible. The only way is to run the migrations and query the db. However, having the schema in the repo, helps a lot even on repo discussion (issues, PRs) as you can reference a part of it directly.

  • It tends to be faster and less error prone to create a new instance of the application's database by loading the schema file directly than it is to replay the entire migration history.

@jxs jxs added the enhancement New feature or request label Feb 15, 2024
@jxs
Copy link
Member

jxs commented Feb 15, 2024

yeah makes sense, I think we can have a function in the runner that dumps the schema would you be interested in implementing it?

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

No branches or pull requests

2 participants