From feb747bd2130ba77952505a1844827c7dbbf84d5 Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 22 May 2025 01:57:01 +0200 Subject: [PATCH] chore: add regen_migrations script and seed-database to Justfile --- Justfile | 7 +++++-- regen_migrations.sh | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100755 regen_migrations.sh diff --git a/Justfile b/Justfile index ed412c3..ffbc2cc 100644 --- a/Justfile +++ b/Justfile @@ -1,4 +1,4 @@ -run: install-dependencies start-database migrate-database +run: install-dependencies start-database migrate-database seed-database mix phx.server install-dependencies: @@ -10,6 +10,9 @@ migrate-database: reset-database: mix ash.reset +seed-database: + mix run priv/repo/seeds.exs + start-database: docker compose up -d @@ -36,4 +39,4 @@ build-docker-container: # This is meant for debugging the container build process only. run-docker-container: build-docker-container - podman run -e "SECRET_KEY_BASE=ahK8BeiDaibaige1ahkooS0chie9lo7the7uuzar0eeBeeCh2iereteshee2Oosu" -e='DATABASE_URL=postgres://postgres@localhost:5432/mv_dev' -e='PORT=4040' -e='PHX_HOST=localhost' --network=host mitgliederverwaltung \ No newline at end of file + podman run -e "SECRET_KEY_BASE=ahK8BeiDaibaige1ahkooS0chie9lo7the7uuzar0eeBeeCh2iereteshee2Oosu" -e='DATABASE_URL=postgres://postgres@localhost:5432/mv_dev' -e='PORT=4040' -e='PHX_HOST=localhost' --network=host mitgliederverwaltung diff --git a/regen_migrations.sh b/regen_migrations.sh new file mode 100755 index 0000000..34cd4b0 --- /dev/null +++ b/regen_migrations.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Get count of untracked migrations +N_MIGRATIONS=$(git ls-files --others priv/repo/migrations | wc -l) + +# Rollback untracked migrations +mix ash_postgres.rollback -n $N_MIGRATIONS + +# Delete untracked migrations and snapshots +git ls-files --others priv/repo/migrations | xargs rm +git ls-files --others priv/resource_snapshots | xargs rm + +# Regenerate migrations +mix ash.codegen --name $1 + +# Run migrations if flag +if echo $* | grep -e "-m" -q; then + mix ash.migrate +fi