From 2814fd11eaed454f423d5a47426f3120d7061fde 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 | 5 ++++- regen_migrations.sh | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 regen_migrations.sh diff --git a/Justfile b/Justfile index 5d30963..f9f6d8d 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 ecto.reset +seed-database: + mix run priv/repo/seeds.exs + start-database: docker compose up -d 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