Skip to content

Commit

Permalink
fix: make the start work for postgres 14 and 13
Browse files Browse the repository at this point in the history
  • Loading branch information
avallete committed Sep 24, 2024
1 parent e6788f3 commit 76ef3d2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
4 changes: 4 additions & 0 deletions internal/db/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ func dumpData(ctx context.Context, config pgconn.Config, schema, excludeTable []
// "storage",
// "supabase_functions",
"supabase_migrations",
// TODO: Remove in a few version in favor of _supabase internal db
"_analytics",
"_realtime",
"_supavisor",
}
var env []string
if len(schema) > 0 {
Expand Down
11 changes: 9 additions & 2 deletions internal/db/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var (
HealthTimeout = 120 * time.Second
//go:embed templates/schema.sql
initialSchema string
//go:embed templates/_supabase.sql
_supabaseSchema string
)

func Run(ctx context.Context, fsys afero.Fs) error {
Expand Down Expand Up @@ -82,7 +84,7 @@ func NewContainerConfig() container.Config {
Retries: 3,
},
Entrypoint: []string{"sh", "-c", `cat <<'EOF' > /etc/postgresql.schema.sql && cat <<'EOF' > /etc/postgresql-custom/pgsodium_root.key && docker-entrypoint.sh postgres -D /etc/postgresql
` + initialSchema + `
` + initialSchema + "\n" + _supabaseSchema + "\n" + `
EOF
` + utils.Config.Db.RootKey + `
EOF
Expand Down Expand Up @@ -122,7 +124,12 @@ func StartDatabase(ctx context.Context, fsys afero.Fs, w io.Writer, options ...f
},
}
if utils.Config.Db.MajorVersion <= 14 {
config.Entrypoint = nil
config.Entrypoint = []string{"sh", "-c", `
cat <<'EOF' > /docker-entrypoint-initdb.d/supabase_schema.sql
` + _supabaseSchema + `
EOF
docker-entrypoint.sh postgres -D /etc/postgresql
`}
hostConfig.Tmpfs = map[string]string{"/docker-entrypoint-initdb.d": ""}
}
// Creating volume will not override existing volume, so we must inspect explicitly
Expand Down
18 changes: 18 additions & 0 deletions internal/db/start/templates/_supabase.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE DATABASE _supabase WITH OWNER postgres;

-- Switch to the newly created _supabase database
\c _supabase
-- Create schemas in _supabase database for
-- internals tools and reports to not overload user database
-- with non-user activity
CREATE SCHEMA IF NOT EXISTS _realtime;
ALTER SCHEMA _realtime OWNER TO postgres;
CREATE SCHEMA IF NOT EXISTS realtime;
ALTER SCHEMA realtime OWNER TO postgres;

CREATE SCHEMA IF NOT EXISTS _analytics;
ALTER SCHEMA _analytics OWNER TO postgres;

CREATE SCHEMA IF NOT EXISTS _supavisor;
ALTER SCHEMA _supavisor OWNER TO postgres;
\c postgres
19 changes: 0 additions & 19 deletions internal/db/start/templates/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,6 @@ ALTER USER supabase_storage_admin WITH PASSWORD :'pgpass';
ALTER USER supabase_replication_admin WITH PASSWORD :'pgpass';
ALTER USER supabase_read_only_user WITH PASSWORD :'pgpass';

CREATE DATABASE _supabase WITH OWNER postgres;
-- Connect to the _supabase database
\c _supabase
-- Create schemas in _supabase database for
-- internals tools and reports to not overload user database
-- with non-user activity
CREATE SCHEMA IF NOT EXISTS _realtime;
ALTER SCHEMA _realtime OWNER TO postgres;
CREATE SCHEMA IF NOT EXISTS realtime;
ALTER SCHEMA realtime OWNER TO postgres;

CREATE SCHEMA IF NOT EXISTS _analytics;
ALTER SCHEMA _analytics OWNER TO postgres;

CREATE SCHEMA IF NOT EXISTS _supavisor;
ALTER SCHEMA _supavisor OWNER TO postgres;
-- Switch back to the main database
\c postgres

BEGIN;

-- Create pg_net extension
Expand Down

0 comments on commit 76ef3d2

Please sign in to comment.