-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
40 lines (32 loc) · 1.26 KB
/
Makefile
File metadata and controls
40 lines (32 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
.PHONY: reset-db deploy reset-migrations run migrations
SHELL := /bin/bash
reset-db:
@export $$(grep -v '^#' .env | xargs) && \
DB_NAME=$$(echo $$DATABASE_URL | sed -E 's|.*/([^/?]+).*|\1|') && \
DB_USER=$$(echo $$DATABASE_URL | sed -E 's|.*://([^:]+):.*|\1|') && \
sudo -u postgres psql -c "DROP DATABASE IF EXISTS $$DB_NAME;" && \
sudo -u postgres psql -c "CREATE DATABASE $$DB_NAME;" && \
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $$DB_NAME TO $$DB_USER;" && \
echo "Postgres User '$$DB_USER' and database '$$DB_NAME' reset successfully."
reset-migrations:
@export $$(grep -v '^#' .env | xargs) && \
source .venv/bin/activate && \
rm -rf migrations/versions/* && \
alembic revision --autogenerate -m "Initial Migrations" && \
alembic upgrade head && \
echo "Migrations reset successfully."
migrations:
@export $$(grep -v '^#' .env | xargs) && \
source .venv/bin/activate && \
if [ -z "$(msg)" ]; then \
echo "Error: Please provide a commit message with msg=..."; \
exit 1; \
fi && \
alembic revision --autogenerate -m "$(msg)" && \
alembic upgrade head && \
echo "Migrations created and applied."
run:
@export $$(grep -v '^#' .env | xargs) && \
export PYTHONPATH=$(pwd) && \
source .venv/bin/activate && \
fastapi dev src/main.py