Created
January 6, 2025 12:37
-
-
Save avallete/4dafc2fe665364780768bb831f92c3b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Load environment variables from .env file | |
set -a | |
source .env | |
set +a | |
# Start the database container | |
# wait until all healthy | |
docker compose up db -d --wait | |
# Check if _supabase database exists | |
DB_EXISTS=$(docker exec -i supabase-db psql -U postgres -t -c "SELECT 1 FROM pg_database WHERE datname='_supabase'") | |
if [ -z "$DB_EXISTS" ]; then | |
echo "Creating _supabase database and required schemas..." | |
echo "Postgres user in db container: " | |
docker exec -i supabase-db /bin/bash -c env | grep POSTGRES_USER | |
# Create database and schemas | |
docker exec -i supabase-db /bin/bash -c 'psql -U $POSTGRES_USER << EOF | |
\set pguser `echo "$POSTGRES_USER"` | |
CREATE DATABASE _supabase WITH OWNER :pguser; | |
\c _supabase | |
create schema if not exists _supavisor; | |
alter schema _supavisor owner to :pguser; | |
create schema if not exists _analytics; | |
alter schema _analytics owner to :pguser; | |
\c postgres | |
EOF' | |
echo "Database setup complete" | |
else | |
echo "_supabase database already exists" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment