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

Commit 9494f8c

Browse files
committed
Replace mysql by postgres, fix #1
1 parent 0d69aec commit 9494f8c

File tree

12 files changed

+96
-265
lines changed

12 files changed

+96
-265
lines changed

Diff for: .docker/mysql/Dockerfile

-13
This file was deleted.

Diff for: .docker/php/Dockerfile

+4-9
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ FROM php:7.4-fpm
44
RUN apt-get update && apt-get install -y --no-install-recommends vim curl locales apt-utils unzip
55

66
# https://github.com/mlocati/docker-php-extension-installer
7-
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
8-
9-
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && install-php-extensions \
7+
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
8+
RUN install-php-extensions @composer \
109
apcu opcache intl \
1110
gd imagick \
12-
pdo_mysql \
11+
pdo_pgsql \
1312
mbstring \
1413
xdebug \
1514
zip
@@ -18,10 +17,6 @@ RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && install-php-ext
1817
COPY php.ini /usr/local/etc/php/php.ini
1918
COPY php-fpm-pool.conf /usr/local/etc/php/php-fpm.conf
2019

21-
# Install composer
22-
RUN curl -sSk https://getcomposer.org/installer | php -- --disable-tls && \
23-
mv composer.phar /usr/local/bin/composer
24-
2520
# Purge
2621
RUN rm -rf /var/lib/apt/lists/* \
2722
&& apt-get purge --auto-remove -y g++ \
@@ -31,4 +26,4 @@ WORKDIR /var/www/
3126
USER www-data
3227

3328
EXPOSE 9000
34-
CMD ["php-fpm"]
29+
CMD ["php-fpm"]

Diff for: .docker/php/symfony-demo.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ APP_SECRET=2bd64f8d83b2e89d5f19d612841d6bb9
2525
# For a MySQL database, use: "mysql://db_user:[email protected]:3306/db_name"
2626
# For a PostgreSQL database, use: "postgresql://db_user:[email protected]:5432/db_name?serverVersion=11&charset=utf8"
2727
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
28-
DATABASE_URL=mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE}
28+
DATABASE_URL=postgres://${PG_USER}:${PG_PASSWORD}@${PG_HOST}:${PG_PORT}/${PG_DATABASE}
2929
###< doctrine/doctrine-bundle ###
3030

3131
###> symfony/mailer ###

Diff for: .docker/phpmyadmin/config.inc.php

-171
This file was deleted.

Diff for: .docker/phpmyadmin/uploads.ini renamed to .docker/phppgadmin/uploads.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ file_uploads = On
22
memory_limit = 200M
33
upload_max_filesize = 200M
44
post_max_size = 200M
5-
max_execution_time = 600
5+
max_execution_time = 600

Diff for: .env.dist

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
###> symfony/framework-bundle ###
1717
APP_ENV=dev
18-
APP_SECRET=1c033cf04c8c84f016ffa88768ee165a
18+
APP_SECRET=2d044cf04c8c84f096ffa88768ee276c
1919
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
2020
#TRUSTED_HOSTS='^localhost|example\.com$'
2121
###< symfony/framework-bundle ###
@@ -31,9 +31,10 @@ APP_SECRET=1c033cf04c8c84f016ffa88768ee165a
3131
COMPOSE_PROJECT_NAME=sfdemopg
3232
# VOLUME_USER_ID=1001 # You can set your Linux UserID (command: id -u)
3333
# COMPOSER_HOME=/home/$user/.cache/composer/ # You can set your composer folder, change $user by your username
34-
MYSQL_DATABASE=demo
35-
MYSQL_USER=local
36-
MYSQL_PASSWORD=local
37-
MYSQL_PORT=3306
34+
PG_HOST=db
35+
PG_USER=local
36+
PG_PASSWORD=local
37+
PG_DATABASE=demo
38+
PG_PORT=5432
3839
TIMEZONE=Europe/Paris
3940
###< Docker database conf ###

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
project/
2+
!project/.gitkeep
23
.env
34
!.env.dist
45
docker-compose.override.yml
6+
dump_*.sql

Diff for: Makefile

+31-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ EXEC_ROOT?=$(DOCKER_COMPOSE) exec -u root php
1111
CONSOLE=bin/console
1212
PHPCSFIXER?=$(EXEC) php -d memory_limit=1024m vendor/bin/php-cs-fixer
1313
DOCKER_COMPOSE_OVERRIDE ?= dev
14-
ENV ?= dev
1514

1615
help:
1716
@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/'
@@ -31,7 +30,7 @@ stop: ## Stop docker containers
3130

3231
restart: stop up-ci ## Restart docker containers
3332

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

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

4544
status: ## Docker container status
4645
@$(DOCKER_COMPOSE) ps
4746

48-
uninstall: stop clear ## Remove docker containers
47+
uninstall: clear stop ## Remove docker containers
4948
@$(DOCKER_COMPOSE) rm -vf
5049

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

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

5756
c\:c: clear-cache
5857

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

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

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

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

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

111110
db-fixtures: ## Apply doctrine fixtures
112-
@$(EXEC) $(CONSOLE) doctrine:fixtures:load -n --env=$(ENV)
111+
@$(EXEC) $(CONSOLE) doctrine:fixtures:load -n --env=$(APP_ENV)
112+
113+
db-install: db-create-database db-migrate db-fixtures ## Drop and install database with schema + fixtures
114+
115+
db-dump: ## Dump data only from database on dump_DBNAME.sql file
116+
@docker-compose exec db pg_dump -U $(PG_USER) -p $(PG_PORT) --data-only $(PG_DATABASE) > dump_$(PG_DATABASE).sql
117+
@ls -l dump_$(PG_DATABASE).sql
118+
119+
db-dump-full: ## Dump Schema + Data from database on dump_DBNAME.sql file
120+
@docker-compose exec db pg_dump -U $(PG_USER) -p $(PG_PORT) $(PG_DATABASE) > dump_$(PG_DATABASE).sql
121+
@ls -l dump_$(PG_DATABASE).sql
122+
123+
db-import-data: db-create-database db-migrate ## Import dump "dump_DBNAME.sql" (data only), the database will be reset before import
124+
@docker-compose exec -T db psql -U $(PG_USER) -p $(PG_PORT) $(PG_DATABASE) < dump_$(PG_DATABASE).sql
125+
126+
db-import-full: db-create-database ## Import dump "dump_DBNAME.sql" (schema + data), the database will be reset before import
127+
@docker-compose exec -T db psql -U $(PG_USER) -p $(PG_PORT) $(PG_DATABASE) < dump_$(PG_DATABASE).sql
128+
129+
db-query: ## Execute query $CMD="postgres query"
130+
@docker-compose exec -T db psql -U $(PG_USER) -p $(PG_PORT) $(PG_DATABASE) -c "$(CMD)"
131+
113132

114133
# ##
115134
# ## Assets

0 commit comments

Comments
 (0)