Something went wrong. Try again.
A Haskell Webserver Template
Something went wrong. Try again.
4.2 kB · 128 lines
Just
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129# List this menu and exithelp: just --justfile "{{ justfile_directory() }}/database/justfile" --listcompose_file := justfile_directory() / "database" / "docker-compose.yml"# Open rainfrog PostgreSQL TUI clienttui: #!/usr/bin/env amber main { let env_file = "{{ justfile_directory() }}/.env.development" let pg_host = $ dotenvx get PGHOST -f {env_file} $? let pg_port = $ dotenvx get PGPORT -f {env_file} $? let pg_user = $ dotenvx get PGUSER -f {env_file} $? let pg_pass = $ dotenvx get PGPASSWORD -f {env_file} $? let pg_db = $ dotenvx get PGDATABASE -f {env_file} $? $ rainfrog --driver postgres --username {pg_user} --password {pg_pass} --host {pg_host} --port {pg_port} --database {pg_db}$? }# Start PostgreSQL containerstart: #!/usr/bin/env amber main { let compose_file = "{{ compose_file }}" let env_file = "{{ justfile_directory() }}/.env.development" let project = $ dotenvx get PROJECT -f {env_file} $? let pg_user = $ dotenvx get PGUSER -f {env_file} $? let pg_port = $ dotenvx get PGPORT -f {env_file} $? cd "{{ justfile_directory() }}" $ dotenvx run -f {env_file} -- podman compose -f {compose_file} up --build --force-recreate -d $? // Wait for readiness (check inside the container) let retries = 0 loop { if retries >= 30 { echo "PostgreSQL did not become ready in time." fail 1 } trust $ podman exec {project}-postgres pg_isready -U {pg_user} $ if status == 0 { break } $ sleep 0.2 $? retries += 1 } echo "PostgreSQL container started on port {pg_port}." }# Stop PostgreSQL containerstop: #!/usr/bin/env amber main { let compose_file = "{{ compose_file }}" let env_file = "{{ justfile_directory() }}/.env.development" cd "{{ justfile_directory() }}" $ dotenvx run -f {env_file} -- podman compose -f {compose_file} stop postgres $? exit 0 }# Stop PostgreSQL container and remove data volumedestroy: #!/usr/bin/env amber main { let compose_file = "{{ compose_file }}" let env_file = "{{ justfile_directory() }}/.env.development" cd "{{ justfile_directory() }}" $ dotenvx run -f {env_file} -- podman compose -f {compose_file} down -v $? exit 0 }# Create a migration for the databasenew_migration *description: #!/usr/bin/env amber import { parse_int, zfill } from "std/text" main { let deploy_dir = "{{ justfile_directory() }}/database/deploy" let old_id = $ ls -1 {deploy_dir}/*.sql | sed 's|.*/||' | sed 's|\.sql||' | sort -n | tail -1 $? let old_id_num = parse_int(old_id)? let new_id = zfill((old_id_num + 1) as Text, 8) cd "{{ justfile_directory() }}" $ sqitch add {new_id} --requires {old_id} -n '{{ description }}' $? exit 0 }# Migrate the database to the most recent revisionmigrate: #!/usr/bin/env amber main { let env_file = "{{ justfile_directory() }}/.env.development" cd "{{ justfile_directory() }}" $ dotenvx run -f {env_file} -- sqitch deploy $? exit 0 }# Migrate the database to a specific revisionupgrade_to rev: #!/usr/bin/env amber main { let env_file = "{{ justfile_directory() }}/.env.development" cd "{{ justfile_directory() }}" $ dotenvx run -f {env_file} -- sqitch deploy --to "{{ rev }}" $? exit 0 }# Revert the database to the initial staterevert: #!/usr/bin/env amber main { let env_file = "{{ justfile_directory() }}/.env.development" cd "{{ justfile_directory() }}" $ dotenvx run -f {env_file} -- sqitch revert $? exit 0 }# Revert the database to a specific revisionrevert_to rev: #!/usr/bin/env amber main { let env_file = "{{ justfile_directory() }}/.env.development" cd "{{ justfile_directory() }}" $ dotenvx run -f {env_file} -- sqitch revert --to "{{ rev }}" $? exit 0 }