Justfile targets for db-backup, db-restore, pgshell and re-migrate for debugging

This commit is contained in:
Imbus 2024-03-06 08:22:58 +01:00
parent a5dadfc1d1
commit a2064b440d

View file

@ -55,6 +55,24 @@ start-postgres-dev: create-network
podman rm -f {{pg_container}} podman rm -f {{pg_container}}
podman run --network {{network}} --name {{pg_container}} -e POSTGRES_PASSWORD={{pg_pass}} -d -p {{pg_port}}:5432 docker.io/postgres:16.1-alpine podman run --network {{network}} --name {{pg_container}} -e POSTGRES_PASSWORD={{pg_pass}} -d -p {{pg_port}}:5432 docker.io/postgres:16.1-alpine
pgshell:
podman exec -it {{pg_container}} psql -U {{pg_user}} -d {{db_name}}
re-migrate:
echo {{env_local}} > server/.env
cd server && cargo sqlx database drop -y
cd server && cargo sqlx database create
cd server && cargo sqlx migrate run
@echo "Database re-initialized and migrations re-run."
db-backup:
podman exec -t {{pg_container}} pg_dump -U {{pg_user}} -d {{db_name}} | gzip > frostbyte_backup$(date +'%Y-%m-%d_%H:%M:%S').sql.gz
# Drops the database and restores it from a backup file
db-restore backupfile: db-backup
podman exec -i {{pg_container}} psql -U {{pg_user}} -d {{db_name}} -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
gunzip -c {{backupfile}} | podman exec -i {{pg_container}} psql -U {{pg_user}} -d {{db_name}}
[private] [private]
create-network: create-network:
podman network create {{network}} --ignore podman network create {{network}} --ignore