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

feature: add functionality to dump database schema #278

Open
mfridman opened this issue Oct 12, 2021 · 3 comments · May be fixed by #459
Open

feature: add functionality to dump database schema #278

mfridman opened this issue Oct 12, 2021 · 3 comments · May be fixed by #459
Labels
Milestone

Comments

@mfridman
Copy link
Collaborator

The proposal is to enable goose to drop the current database schema. This is usually done with tools like pg_dump.

Now, this would require the user to have this executable in their $PATH or we can invoke a lightweight container such as postgres:14-alpine, if neither is available then fail.

I don't think this should live inside the github.com/pressly/goose/v3 package, and instead should be its own subdir package, such as pgutil or something. I imagine we should expose a few of these mysqlutil. (can't come up with a better name, suggestions welcome to not use {dialect}util)

In the goose binaries, the behaviour could be to dump a schema file after running a modifying migration. The file could be written to the same folder as -dir as schema.sql

@mfridman mfridman changed the title Add functionality to dump database schema feature: add functionality to dump database schema Oct 16, 2021
@timuckun
Copy link

+1

@mfridman mfridman modified the milestone: Upcoming v3 changes Jan 28, 2023
@mfridman
Copy link
Collaborator Author

I've had to implement the command in this #345 (comment) a few times now, would be nice to have goose do this, for consistency.

@mfridman mfridman linked a pull request Jan 28, 2023 that will close this issue
@mfridman
Copy link
Collaborator Author

mfridman commented Feb 1, 2024

This was another useful snippet a user shared in Gophers Public Slack:

pg_dump --schema-only \
  --no-comments \
  --quote-all-identifiers \
  -T public.goose_db_version \
  -T public.goose_db_version_id_seq | sed \
    -e '/^--.*/d' \
    -e '/^SET /d' \
    -e '/^[[:space:]]*$/d' \
    -e '/^SELECT pg_catalog./d' \
    -e '/^ALTER TABLE .* OWNER TO "postgres";/d' \
    -e 's/"public"\.//' \
      > ./schema/schema.sql

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

Successfully merging a pull request may close this issue.

2 participants