From cf987b1e6612a4c054427dd36cb97618e157f74e Mon Sep 17 00:00:00 2001 From: Douglas Medeiros Date: Sat, 6 Jul 2024 19:41:50 -0300 Subject: [PATCH] build: configure mongo --- .docker/mongo/reset.sh | 59 ++++++++++++++++++++++++++ TODO.md | 1 + docker-compose.yml | 4 +- makefile | 31 +++++++++++++- migrations/mongo/records_collection.sh | 5 +-- 5 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 .docker/mongo/reset.sh create mode 100644 TODO.md diff --git a/.docker/mongo/reset.sh b/.docker/mongo/reset.sh new file mode 100644 index 0000000..52cfd5b --- /dev/null +++ b/.docker/mongo/reset.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +set -eu + +# Set variables +SDDB_USER=user +SDDB_PASS=password +SDDB_DATABASE=default + +# replicate set initiate +echo "Checking mongo container..." +until mongosh --host mongo --eval "print(\"waited for connection\")" +do + sleep 1 +done + +echo "Initializing replicaset..." +mongosh --host mongo < db.getCollection(c).drop());'" + +database-migrate: ## Migrate the database + docker-compose exec mongo bash -c "find /migrations/ -name \"*.sh\" -exec {} \;" + +playground: ## Start a PHP playground dockerized environment + @make check-docker + @docker-compose exec php bash + +check-docker: ## Check if Docker is installed + @docker --version > /dev/null 2>&1 || (echo "Docker is not installed. Please install Docker and try again." && exit 1) + +help: ## Show this help message + @echo "Usage: make [command]" + @echo "" + @echo "Commands available:" + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort diff --git a/migrations/mongo/records_collection.sh b/migrations/mongo/records_collection.sh index 1b86e4a..6dc27b8 100755 --- a/migrations/mongo/records_collection.sh +++ b/migrations/mongo/records_collection.sh @@ -1,8 +1,7 @@ #!/usr/bin/env bash -mongosh --host mongo <