Skip to content

Commit

Permalink
add quotation marks for Makefile substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
Dopplerian committed Aug 29, 2023
1 parent 85e68cf commit 715494c
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,44 @@ db: $(DB_TARGETS)

db_postgres:
@echo -e $(BOLD)Setting up Postgres database...$(END_BOLD)
docker run --rm -d --name $(POSTGRES_CONTAINER) -p 5432:5432 \
-e POSTGRES_DB=$(POSTGRES_DB) \
-e POSTGRES_USER=$(POSTGRES_USER) \
-e POSTGRES_PASSWORD=$(POSTGRES_PASSWORD) \
docker run --rm -d --name "$(POSTGRES_CONTAINER)" -p 5432:5432 \
-e POSTGRES_DB="$(POSTGRES_DB)" \
-e POSTGRES_USER="$(POSTGRES_USER)" \
-e POSTGRES_PASSWORD="$(POSTGRES_PASSWORD)" \
postgres:latest
$(MAKE) diesel_postgres

db_mysql:
@echo -e $(BOLD)Setting up MySQL database...$(END_BOLD)
docker run --rm -d --name $(MYSQL_CONTAINER) -p 3306:3306 \
-e MYSQL_DATABASE=$(MYSQL_DB) \
-e MYSQL_ROOT_PASSWORD=$(MYSQL_PASSWORD) \
docker run --rm -d --name "$(MYSQL_CONTAINER)" -p 3306:3306 \
-e MYSQL_DATABASE="$(MYSQL_DB)" \
-e MYSQL_ROOT_PASSWORD="$(MYSQL_PASSWORD)" \
-e TZ=UTC \
mysql:latest
$(MAKE) diesel_mysql

db_sqlite:
@echo -e $(BOLD)Setting up SQLite database...$(END_BOLD)
sqlite3 $(SQLITE_FILE) "VACUUM;"
sqlite3 "$(SQLITE_FILE)" "VACUUM;"
$(MAKE) diesel_sqlite

wait_for_postgres:
@echo -e $(BOLD)Waiting for Postgres server to be up and running...$(END_BOLD)
while ! docker exec $(POSTGRES_CONTAINER) psql -U $(POSTGRES_USER) --command='' 2> /dev/null; \
while ! docker exec "$(POSTGRES_CONTAINER)" psql -U "$(POSTGRES_USER)" --command='' 2> /dev/null; \
do \
sleep 1; \
done

wait_for_mysql:
@echo -e $(BOLD)Waiting for MySQL server to be up and running...$(END_BOLD)
while ! docker exec $(MYSQL_CONTAINER) mysql --user=$(MYSQL_USER) --password=$(MYSQL_PASSWORD) --execute='' 2> /dev/null; \
while ! docker exec "$(MYSQL_CONTAINER)" mysql --user="$(MYSQL_USER)" --password="$(MYSQL_PASSWORD)" --execute='' 2> /dev/null; \
do \
sleep 1; \
done

wait_for_sqlite:
@echo -e $(BOLD)Waiting for SQLite DB file to be created...$(END_BOLD)
while [ ! -f $(SQLITE_FILE) ]; \
while [ ! -f "$(SQLITE_FILE)" ]; \
do \
sleep 1; \
done
Expand All @@ -75,37 +75,37 @@ diesel: $(DIESEL_TARGETS)
diesel_postgres: wait_for_postgres
@echo -e $(BOLD)Running Diesel migrations on Postgres database...$(END_BOLD)
diesel migration run \
--database-url $(POSTGRES_URL) \
--migration-dir $(POSTGRES_MIGRATIONS) \
--config-file $(POSTGRES_CONFIG)
--database-url "$(POSTGRES_URL)" \
--migration-dir "$(POSTGRES_MIGRATIONS)" \
--config-file "$(POSTGRES_CONFIG)"

diesel_mysql: wait_for_mysql
@echo -e $(BOLD)Running Diesel migrations on MySQL database...$(END_BOLD)
diesel migration run \
--database-url $(MYSQL_URL) \
--migration-dir $(MYSQL_MIGRATIONS) \
--config-file $(MYSQL_CONFIG)
--database-url "$(MYSQL_URL)" \
--migration-dir "$(MYSQL_MIGRATIONS)" \
--config-file "$(MYSQL_CONFIG)"

diesel_sqlite: wait_for_sqlite
@echo -e $(BOLD)Running Diesel migrations on SQLite database...$(END_BOLD)
diesel migration run \
--database-url sqlite://$(SQLITE_FILE) \
--migration-dir $(SQLITE_MIGRATIONS) \
--config-file $(SQLITE_CONFIG)
--database-url sqlite://"$(SQLITE_FILE)" \
--migration-dir "$(SQLITE_MIGRATIONS)" \
--config-file "$(SQLITE_CONFIG)"

clean: $(CLEAN_TARGETS)

clean_postgres: wait_for_postgres
@echo -e $(BOLD)Cleaning Postgres database...$(END_BOLD)
docker exec $(POSTGRES_CONTAINER) dropdb -U $(POSTGRES_USER) $(POSTGRES_DB)
docker exec $(POSTGRES_CONTAINER) psql -U $(POSTGRES_USER) --command="CREATE DATABASE $(POSTGRES_DB);"
docker exec "$(POSTGRES_CONTAINER)" dropdb -U "$(POSTGRES_USER)" "$(POSTGRES_DB)"
docker exec "$(POSTGRES_CONTAINER)" psql -U "$(POSTGRES_USER)" --command="CREATE DATABASE $(POSTGRES_DB);"
$(MAKE) diesel_postgres

clean_mysql: wait_for_mysql
@echo -e $(BOLD)Cleaning MySQL database...$(END_BOLD)
docker exec $(MYSQL_CONTAINER) mysql \
--user=$(MYSQL_USER) \
--password=$(MYSQL_PASSWORD) \
docker exec "$(MYSQL_CONTAINER)" mysql \
--user="$(MYSQL_USER)" \
--password="$(MYSQL_PASSWORD)" \
--execute="DROP DATABASE $(MYSQL_DB); CREATE DATABASE $(MYSQL_DB);"
$(MAKE) diesel_mysql

Expand All @@ -117,15 +117,15 @@ stop: $(STOP_TARGETS)

stop_postgres:
@echo -e $(BOLD)Stopping Postgres database...$(END_BOLD)
docker kill $(POSTGRES_CONTAINER)
docker kill "$(POSTGRES_CONTAINER)"

stop_mysql:
@echo -e $(BOLD)Stopping MySQL database...$(END_BOLD)
docker kill $(MYSQL_CONTAINER)
docker kill "$(MYSQL_CONTAINER)"

stop_sqlite:
@echo -e $(BOLD)Stopping SQLite database...$(END_BOLD)
rm $(SQLITE_FILE)
rm "$(SQLITE_FILE)"

clippy:
cargo clippy --verbose --all-targets --all-features -- -D warnings
Expand Down

0 comments on commit 715494c

Please sign in to comment.