Featured image of post Supabase Backup & Migration CheetSheet

Supabase Backup & Migration CheetSheet

Supabase 로컬 환경 구성과 원격-로컬 간 스키마·데이터 백업·마이그레이션 명령어 모음.

setting local env

supabase init

supabase start

From remote To local

Schema

# 1. Remote DB Schema 복사
# schema_migration 이력이 없는 경우
supabase db pull
# schema_migration 이력이 있는 경우
supabase migration fetch

# 2. local DB 리셋
supabase db reset

Data

# 1. Remote DB 데이터 복사
supabase db dump --data-only -s public > supabase/seed.sql

# 2. local DB 리셋
supabase db reset

From local To remote

Schema

# 1. Remote DB Schema 복사 (migration)
# schema_migration 이력이 없는 경우
supabase db pull
# schema_migration 이력이 있는 경우
supabase migration fetch

# 2. Remote DB Schema 복사 (dump)
mkdir -p supabase/schemas
supabase db dump > supabase/schemas/prod.sql

# 3. supabase/schemas 폴더에 적용 할 DDL sql 파일 추가

# 4. migration과 schemas의 ddl을 비교하여 새로운 migration 파일 생성
supabase db diff -f [name]

# 5. migration 반영
supabase db push

Data

From remote To local / Data 응용 (–db-url or –linked 사용)

Hugo로 만듦
JimmyStack 테마 사용 중