Skip to content

Commit

Permalink
Make resetdb
Browse files Browse the repository at this point in the history
  • Loading branch information
francoisfreitag committed Sep 12, 2024
1 parent 1c03698 commit ee06f04
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ LINTER_CHECKED_DIRS := config itou scripts tests
PGDATABASE ?= itou
REQUIREMENTS_PATH ?= requirements/dev.txt

ifdef $(XDG_CACHE_HOME)
CACHEDIR := $(XDG_CACHE_HOME)
else
CACHEDIR := $(HOME)/.cache
endif
CACHEDIR := $(CACHEDIR)/itou
DBDUMP ?= $(CACHEDIR)/development_db.dump

VIRTUAL_ENV ?= .venv
export PATH := $(VIRTUAL_ENV)/bin:$(PATH)

Expand Down Expand Up @@ -105,7 +113,23 @@ shell_on_postgres_container:
# Database.
# =============================================================================

.PHONY: restore_latest_backup
.PHONY: resetdb restore_latest_backup

DBREADY := 0

$(DBDUMP): itou/fixtures/*/*.sql itou/fixtures/*/*.json itou/*/migrations/*.py itou/siae_evaluations/fixtures.py
dropdb $(PGDATABASE)
createdb $(PGDATABASE)
python manage.py migrate
$(MAKE) populate_db
mkdir --parents $(CACHEDIR)
pg_dump --format=c --dbname=$(PGDATABASE) --file=$(DBDUMP)
$(eval DBREADY := 1)

resetdb: $(DBDUMP)
if (( $(DBREADY) == 0 )); then \
pg_restore --clean --dbname=$(PGDATABASE) $(DBDUMP); \
fi

restore_latest_backup:
./scripts/restore_latest_backup.sh $(PGDATABASE)

0 comments on commit ee06f04

Please sign in to comment.