Skip to content

Commit

Permalink
fix: perms issues w/ pg_dump output
Browse files Browse the repository at this point in the history
  • Loading branch information
soedirgo committed Aug 12, 2022
1 parent 5d4f175 commit 6b114b7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
17 changes: 13 additions & 4 deletions internal/db/remote/commit/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commit
import (
"bytes"
"context"
_ "embed"
"errors"
"fmt"
"io"
Expand All @@ -19,7 +20,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/stdcopy"
pgx "github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4"
"github.com/muesli/reflow/wrap"
"github.com/spf13/afero"
"github.com/spf13/viper"
Expand All @@ -36,6 +37,11 @@ CREATE TABLE supabase_migrations.schema_migrations (version text NOT NULL PRIMAR
INSERT_MIGRATION_VERSION = "INSERT INTO supabase_migrations.schema_migrations(version) VALUES($1)"
)

var (
//go:embed templates/dump_initial_migration.sh
dumpInitialMigrationScript string
)

func Run(ctx context.Context, username, password, database string, fsys afero.Fs) error {
// Sanity checks.
{
Expand Down Expand Up @@ -160,10 +166,13 @@ func run(p utils.Program, ctx context.Context, username, password, database stri
dbId,
&container.Config{
Image: utils.DbImage,
Env: []string{"POSTGRES_PASSWORD=postgres"},
Env: []string{
"POSTGRES_PASSWORD=postgres",
"EXCLUDED_SCHEMAS=" + strings.Join(utils.InternalSchemas, "|"),
"DB_URL=" + conn.Config().ConnString(),
},
Entrypoint: []string{
"sh", "-c",
"pg_dump --schema-only --quote-all-identifier --exclude-schema '" + strings.Join(utils.InternalSchemas, "|") + `' --schema '*' --extension '*' --dbname '` + conn.Config().ConnString() + `' | sed 's/CREATE SCHEMA "public"/-- CREATE SCHEMA "public"/'`,
"bash", "-c", dumpInitialMigrationScript,
},
Labels: map[string]string{
"com.supabase.cli.project": utils.Config.ProjectId,
Expand Down
13 changes: 13 additions & 0 deletions internal/db/remote/commit/templates/dump_initial_migration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail

pg_dump \
--schema-only \
--quote-all-identifier \
--exclude-schema "$EXCLUDED_SCHEMAS" \
--schema '*' \
--extension '*' \
--dbname "$DB_URL" \
| sed 's/CREATE SCHEMA "public"/-- CREATE SCHEMA "public"/' \
| sed 's/COMMENT ON EXTENSION/-- COMMENT ON EXTENSION/' \
| sed 's/ALTER DEFAULT PRIVILEGES FOR ROLE "supabase_admin"/-- ALTER DEFAULT PRIVILEGES FOR ROLE "supabase_admin"/'

0 comments on commit 6b114b7

Please sign in to comment.