goose icon indicating copy to clipboard operation
goose copied to clipboard

feature: add functionality to dump database schema

Open mfridman opened this issue 4 years ago • 4 comments

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 avatar Oct 12 '21 01:10 mfridman

+1

timuckun avatar Apr 11 '22 04:04 timuckun

I've had to implement the command in this https://github.com/pressly/goose/issues/345#issuecomment-1121375847 a few times now, would be nice to have goose do this, for consistency.

mfridman avatar Jan 28 '23 18:01 mfridman

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

mfridman avatar Feb 01 '24 15:02 mfridman