Skip to content
This repository has been archived by the owner on Apr 11, 2021. It is now read-only.

Commit

Permalink
Replace mysql by postgres, fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
jgauthi committed Apr 11, 2021
1 parent 0d69aec commit 9494f8c
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 265 deletions.
13 changes: 0 additions & 13 deletions .docker/mysql/Dockerfile

This file was deleted.

13 changes: 4 additions & 9 deletions .docker/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ FROM php:7.4-fpm
RUN apt-get update && apt-get install -y --no-install-recommends vim curl locales apt-utils unzip

# https://github.com/mlocati/docker-php-extension-installer
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/

RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && install-php-extensions \
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions @composer \
apcu opcache intl \
gd imagick \
pdo_mysql \
pdo_pgsql \
mbstring \
xdebug \
zip
Expand All @@ -18,10 +17,6 @@ RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && install-php-ext
COPY php.ini /usr/local/etc/php/php.ini
COPY php-fpm-pool.conf /usr/local/etc/php/php-fpm.conf

# Install composer
RUN curl -sSk https://getcomposer.org/installer | php -- --disable-tls && \
mv composer.phar /usr/local/bin/composer

# Purge
RUN rm -rf /var/lib/apt/lists/* \
&& apt-get purge --auto-remove -y g++ \
Expand All @@ -31,4 +26,4 @@ WORKDIR /var/www/
USER www-data

EXPOSE 9000
CMD ["php-fpm"]
CMD ["php-fpm"]
2 changes: 1 addition & 1 deletion .docker/php/symfony-demo.env
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ APP_SECRET=2bd64f8d83b2e89d5f19d612841d6bb9
# For a MySQL database, use: "mysql://db_user:db_password@127.0.0.1:3306/db_name"
# For a PostgreSQL database, use: "postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=11&charset=utf8"
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
DATABASE_URL=mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE}
DATABASE_URL=postgres://${PG_USER}:${PG_PASSWORD}@${PG_HOST}:${PG_PORT}/${PG_DATABASE}
###< doctrine/doctrine-bundle ###

###> symfony/mailer ###
Expand Down
171 changes: 0 additions & 171 deletions .docker/phpmyadmin/config.inc.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ file_uploads = On
memory_limit = 200M
upload_max_filesize = 200M
post_max_size = 200M
max_execution_time = 600
max_execution_time = 600
11 changes: 6 additions & 5 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=1c033cf04c8c84f016ffa88768ee165a
APP_SECRET=2d044cf04c8c84f096ffa88768ee276c
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
#TRUSTED_HOSTS='^localhost|example\.com$'
###< symfony/framework-bundle ###
Expand All @@ -31,9 +31,10 @@ APP_SECRET=1c033cf04c8c84f016ffa88768ee165a
COMPOSE_PROJECT_NAME=sfdemopg
# VOLUME_USER_ID=1001 # You can set your Linux UserID (command: id -u)
# COMPOSER_HOME=/home/$user/.cache/composer/ # You can set your composer folder, change $user by your username
MYSQL_DATABASE=demo
MYSQL_USER=local
MYSQL_PASSWORD=local
MYSQL_PORT=3306
PG_HOST=db
PG_USER=local
PG_PASSWORD=local
PG_DATABASE=demo
PG_PORT=5432
TIMEZONE=Europe/Paris
###< Docker database conf ###
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
project/
!project/.gitkeep
.env
!.env.dist
docker-compose.override.yml
dump_*.sql
43 changes: 31 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ EXEC_ROOT?=$(DOCKER_COMPOSE) exec -u root php
CONSOLE=bin/console
PHPCSFIXER?=$(EXEC) php -d memory_limit=1024m vendor/bin/php-cs-fixer
DOCKER_COMPOSE_OVERRIDE ?= dev
ENV ?= dev

help:
@grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(firstword $(MAKEFILE_LIST)) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
Expand All @@ -31,7 +30,7 @@ stop: ## Stop docker containers

restart: stop up-ci ## Restart docker containers

install: docker-compose.override.yml build up composer-install perm ## Create and start docker containers
install: docker-compose.override.yml build up ## Create and start docker containers

install-demo:
@$(EXEC_ROOT) chmod 775 /var/www
Expand All @@ -40,19 +39,19 @@ install-demo:
$(call composer,create-project symfony/symfony-demo demo)
@cp .docker/php/symfony-demo.env project/.env
@$(EXEC_ROOT) bash -c "mv demo/* . && rm -rf demo/ data/"
@make restart perm db-create-migration db-install db-fixtures clear-cache
@make restart perm db-create-migration db-install clear-cache

status: ## Docker container status
@$(DOCKER_COMPOSE) ps

uninstall: stop clear ## Remove docker containers
uninstall: clear stop ## Remove docker containers
@$(DOCKER_COMPOSE) rm -vf

reset: uninstall install ## Remove and re-create docker containers

clear-cache: perm ## Clear + Prepare Cache (alias: c:c), you can specify the env: ENV=prod
@$(EXEC) $(CONSOLE) cache:clear --no-warmup --env=$(ENV)
@$(EXEC) $(CONSOLE) cache:warmup --env=$(ENV)
@$(EXEC) $(CONSOLE) cache:clear --no-warmup --env=$(APP_ENV)
@$(EXEC) $(CONSOLE) cache:warmup --env=$(APP_ENV)

c\:c: clear-cache

Expand Down Expand Up @@ -96,20 +95,40 @@ db-create-migration: ## Create migration
@$(EXEC) $(CONSOLE) make:migration

db-migrate: ## Migrate database schema to the latest available version
@$(EXEC) $(CONSOLE) doctrine:migration:migrate -n --env=$(ENV)
@$(EXEC) $(CONSOLE) doctrine:migration:migrate -n --env=$(APP_ENV)

db-rollback: ## Rollback the latest executed migration
@$(EXEC) $(CONSOLE) doctrine:migration:migrate prev -n --env=$(ENV)
@$(EXEC) $(CONSOLE) doctrine:migration:migrate prev -n --env=$(APP_ENV)

db-validate: ## Check the ORM mapping
@$(EXEC) $(CONSOLE) doctrine:schema:validate

db-install: ## Install database, you can add 'db-fixtures' argument for apply fixtures after install
@$(EXEC) $(CONSOLE) doctrine:database:create --if-not-exists
@$(EXEC) $(CONSOLE) doctrine:migrations:migrate -n --env=$(ENV)
db-create-database: ## Drop and create empty database
@$(EXEC) $(CONSOLE) doctrine:database:drop --force
@$(EXEC) $(CONSOLE) doctrine:database:create

db-fixtures: ## Apply doctrine fixtures
@$(EXEC) $(CONSOLE) doctrine:fixtures:load -n --env=$(ENV)
@$(EXEC) $(CONSOLE) doctrine:fixtures:load -n --env=$(APP_ENV)

db-install: db-create-database db-migrate db-fixtures ## Drop and install database with schema + fixtures

db-dump: ## Dump data only from database on dump_DBNAME.sql file
@docker-compose exec db pg_dump -U $(PG_USER) -p $(PG_PORT) --data-only $(PG_DATABASE) > dump_$(PG_DATABASE).sql
@ls -l dump_$(PG_DATABASE).sql

db-dump-full: ## Dump Schema + Data from database on dump_DBNAME.sql file
@docker-compose exec db pg_dump -U $(PG_USER) -p $(PG_PORT) $(PG_DATABASE) > dump_$(PG_DATABASE).sql
@ls -l dump_$(PG_DATABASE).sql

db-import-data: db-create-database db-migrate ## Import dump "dump_DBNAME.sql" (data only), the database will be reset before import
@docker-compose exec -T db psql -U $(PG_USER) -p $(PG_PORT) $(PG_DATABASE) < dump_$(PG_DATABASE).sql

db-import-full: db-create-database ## Import dump "dump_DBNAME.sql" (schema + data), the database will be reset before import
@docker-compose exec -T db psql -U $(PG_USER) -p $(PG_PORT) $(PG_DATABASE) < dump_$(PG_DATABASE).sql

db-query: ## Execute query $CMD="postgres query"
@docker-compose exec -T db psql -U $(PG_USER) -p $(PG_PORT) $(PG_DATABASE) -c "$(CMD)"


# ##
# ## Assets
Expand Down
Loading

0 comments on commit 9494f8c

Please sign in to comment.