Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ x-base-mysql: &base-mysql
MYSQL_USER: app
MYSQL_PASSWORD: app

# PostgreSQL, instead of MySQL (see docs/postgresql.md)
#x-base-postgres: &base-postgres
# build:
# context: postgres
# args:
# UID: ${UID:-1000}
# GID: ${GID:-1000}
# POSTGRES_VERSION: ${POSTGRES_VERSION:-16}
# env_file: .env
# volumes:
# - process_bundle_demo_data:/var/lib/postgresql/data
# environment:
# POSTGRES_DB: app
# POSTGRES_USER: app
# POSTGRES_PASSWORD: app

x-base-sftp: &base-sftp
image: atmoz/sftp
volumes:
Expand All @@ -62,8 +78,11 @@ services:
<<: *base-php
tty: true
depends_on:
# PostgreSQL instead of MySQL (see docs/postgresql.md): comment mysql, uncomment postgres
mysql:
condition: service_healthy
#postgres:
# condition: service_healthy

apache2:
<<: *base-apache2
Expand All @@ -81,6 +100,17 @@ services:
ports:
- "${MYSQL_PORT:-3306}:3306"

# PostgreSQL instead of MySQL (see docs/postgresql.md): comment the mysql service above, uncomment this one
#postgres:
# <<: *base-postgres
# tty: true
# healthcheck:
# test: [ "CMD", "pg_isready", "-U", "app", "-d", "app" ]
# timeout: 5s
# retries: 100
# ports:
# - "${POSTGRES_PORT:-5432}:5432"

sftp:
<<: *base-sftp
tty: true
Expand Down
2 changes: 2 additions & 0 deletions .docker/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ RUN set -eux; \
libicu-dev \
libzip-dev \
libxml2-dev \
libpq-dev \
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl \
pdo \
pdo_mysql \
pdo_pgsql \
zip \
soap \
&& docker-php-ext-enable soap
Expand Down
14 changes: 14 additions & 0 deletions .docker/postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG POSTGRES_VERSION=16
FROM postgres:${POSTGRES_VERSION}

ARG UNAME=postgres
ARG UID
ARG GID

ENV TZ=Europe/Paris

RUN usermod -u $UID $UNAME \
&& groupmod -g $GID $UNAME \
&& chown -R $UNAME:$UNAME /var/lib/postgresql /var/run/postgresql

USER $UNAME:$UNAME
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data_%kernel.environment%.db"
DATABASE_URL="mysql://app:app@mysql:3306/app?serverVersion=9.1.0&charset=utf8mb4"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
# DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
# PostgreSQL service of .docker/compose.yaml, instead of MySQL (see docs/postgresql.md)
# DATABASE_URL="postgresql://app:app@postgres:5432/app?serverVersion=16&charset=utf8"
###< doctrine/doctrine-bundle ###

###> docker/atmoz-sftp ###
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ CleverAge/ProcessBundleDemo

A demo project using cleverage/process-bundle & cleverage/*-process-bundle bridges

The demo runs on MySQL by default. To run it on PostgreSQL, configure it before installing the project (first
`make start`): see [running the demo on PostgreSQL](docs/postgresql.md).

## Documentation

For usage documentation, see:
Expand Down
5 changes: 5 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ make start

Then access to UI via http://process-bundle-demo.localhost/process (username: admin@clever-age.com / password: admin@clever-age.com)

## PostgreSQL

The demo runs on MySQL by default. To run it on PostgreSQL, configure it before the first `make start`: see
[running the demo on PostgreSQL](postgresql.md).

## Mocking APIs

See [Mocking APIs with WireMock](wiremock.md): the `wiremock` service and the `demo.wiremock.*` processes.
Expand Down
41 changes: 41 additions & 0 deletions docs/postgresql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Running the demo on PostgreSQL
==============================

The demo runs on MySQL by default. It can run on PostgreSQL instead: the bundle migrations
(`cleverage/ui-process-bundle`), the demo migration (`author` / `book` tables) and the fixtures support both databases.

The database is chosen **when installing the project**, before the first `make start`.

## Configuration

1. In `.docker/compose.yaml`:
- comment out the `mysql` service and uncomment the `postgres` service (and the `x-base-postgres` block at the top
of the file);
- in the `depends_on` of the `php-fpm` service, comment out `mysql` and uncomment `postgres`.
2. In `.env.local`, point Doctrine to PostgreSQL (the URL is also in `.env`, commented out):

```dotenv
DATABASE_URL="postgresql://app:app@postgres:5432/app?serverVersion=16&charset=utf8"
```

3. Install and start the demo as usual:

```bash
make start
```

It runs the migrations and loads the fixtures on the PostgreSQL database. The UI is at
http://process-bundle-demo.localhost/process (login `admin@clever-age.com` / `admin@clever-age.com`).

Both databases use the same `process_bundle_demo_data` volume.

## Variables

| Variable | Default | Description |
|--------------------|---------|-------------------------------------------------|
| `POSTGRES_VERSION` | `16` | Tag of the `postgres:<version>` image. |
| `POSTGRES_PORT` | `5432` | Port published on the host. |

If you change `POSTGRES_VERSION`, also change `serverVersion` in `DATABASE_URL`.

Connect to the database: `docker compose -f .docker/compose.yaml exec postgres psql -U app app`.
16 changes: 13 additions & 3 deletions migrations/Version20241210154810.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace DoctrineMigrations;

use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

Expand All @@ -19,16 +20,25 @@ public function getDescription(): string

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
if ($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform) {
$this->addSql('CREATE TABLE author (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, firstname VARCHAR(255) NOT NULL, lastname VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE book (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, author_id INT NOT NULL, title VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_CBE5A331F675F31B ON book (author_id)');
$this->addSql('ALTER TABLE book ADD CONSTRAINT FK_CBE5A331F675F31B FOREIGN KEY (author_id) REFERENCES author (id) NOT DEFERRABLE');

return;
}

$this->addSql('CREATE TABLE author (id INT AUTO_INCREMENT NOT NULL, firstname VARCHAR(255) NOT NULL, lastname VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE book (id INT AUTO_INCREMENT NOT NULL, author_id INT NOT NULL, title VARCHAR(255) NOT NULL, INDEX IDX_CBE5A331F675F31B (author_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE book ADD CONSTRAINT FK_CBE5A331F675F31B FOREIGN KEY (author_id) REFERENCES author (id)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE book DROP FOREIGN KEY FK_CBE5A331F675F31B');
$this->addSql($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform
? 'ALTER TABLE book DROP CONSTRAINT FK_CBE5A331F675F31B'
: 'ALTER TABLE book DROP FOREIGN KEY FK_CBE5A331F675F31B');
$this->addSql('DROP TABLE author');
$this->addSql('DROP TABLE book');
}
Expand Down
Loading