Skip to content

Commit

Permalink
Merge pull request #437 from utopia-php/feat-migrations
Browse files Browse the repository at this point in the history
Feat migrations
  • Loading branch information
abnegate authored Nov 8, 2024
2 parents 44ea79a + 439655a commit 895176b
Show file tree
Hide file tree
Showing 21 changed files with 2,311 additions and 604 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jobs:
Postgres,
SQLite,
MongoDB,
Mirror,
SharedTables/MariaDB,
SharedTables/MySQL,
SharedTables/Postgres,
Expand Down
42 changes: 28 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
FROM composer:2.0 AS composer

ARG TESTING=false
ENV TESTING=$TESTING
ARG DEBUG=false
ENV DEBUG=$DEBUG

WORKDIR /usr/local/src/

COPY composer.lock /usr/local/src/
COPY composer.json /usr/local/src/

RUN composer install --ignore-platform-reqs --optimize-autoloader \
--no-plugins --no-scripts --prefer-dist

FROM php:8.3.3-cli-alpine3.19 AS compile
RUN composer install \
--ignore-platform-reqs \
--optimize-autoloader \
--no-plugins \
--no-scripts \
--prefer-dist

FROM php:8.3.10-cli-alpine3.20 AS compile

ENV PHP_REDIS_VERSION=6.0.2 \
PHP_SWOOLE_VERSION=v5.1.2 \
PHP_MONGO_VERSION=1.16.1 \
PHP_XDEBUG_VERSION=3.3.2
ENV PHP_REDIS_VERSION="6.0.2" \
PHP_SWOOLE_VERSION="v5.1.3" \
PHP_MONGO_VERSION="1.16.1" \
PHP_XDEBUG_VERSION="3.3.2"

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN \
apk update \
&& apk add --no-cache postgresql-libs postgresql-dev make automake autoconf gcc g++ git brotli-dev linux-headers \
&& apk add --no-cache \
postgresql-libs \
postgresql-dev \
make \
automake \
autoconf \
gcc \
g++ \
git \
brotli-dev \
linux-headers \
&& docker-php-ext-install opcache pgsql pdo_mysql pdo_pgsql \
&& apk del postgresql-dev \
&& rm -rf /var/cache/apk/*
Expand Down Expand Up @@ -86,6 +100,7 @@ RUN echo extension=redis.so >> /usr/local/etc/php/conf.d/redis.ini
RUN echo extension=swoole.so >> /usr/local/etc/php/conf.d/swoole.ini
RUN echo extension=mongodb.so >> /usr/local/etc/php/conf.d/mongodb.ini
RUN echo extension=pcov.so >> /usr/local/etc/php/conf.d/pcov.ini
RUN echo extension=xdebug.so >> /usr/local/etc/php/conf.d/xdebug.ini

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

Expand All @@ -100,14 +115,13 @@ COPY --from=mongodb /usr/local/lib/php/extensions/no-debug-non-zts-20230831/mong
COPY --from=pcov /usr/local/lib/php/extensions/no-debug-non-zts-20230831/pcov.so /usr/local/lib/php/extensions/no-debug-non-zts-20230831/
COPY --from=xdebug /usr/local/lib/php/extensions/no-debug-non-zts-20230831/xdebug.so /usr/local/lib/php/extensions/no-debug-non-zts-20230831/

# Add Source Code
COPY ./bin /usr/src/code/bin
COPY ./src /usr/src/code/src
COPY ./dev /usr/src/code/dev

# Add Debug Configs
RUN if [ "$DEBUG" == "true" ]; then cp /usr/src/code/dev/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini; fi
RUN if [ "$DEBUG" == "true" ]; then mkdir -p /tmp/xdebug; fi
RUN if [ "$DEBUG" = "true" ]; then cp /usr/src/code/dev/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini; fi
RUN if [ "$DEBUG" = "true" ]; then mkdir -p /tmp/xdebug; fi
RUN if [ "$DEBUG" = "false" ]; then rm -rf /usr/src/code/dev; fi
RUN if [ "$DEBUG" = "false" ]; then rm -f /usr/local/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so; fi

Expand Down
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions dev/xdebug.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
zend_extension=xdebug
zend_extension = xdebug.so

[xdebug]
xdebug.mode=develop,debug,profile
xdebug.mode = develop,debug,profile
xdebug.start_with_request = yes
xdebug.use_compression=false
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.output_dir=/tmp/xdebug
xdebug.use_compression=false
xdebug.client_port = 9003
xdebug.log = /tmp/xdebug.log

xdebug.var_display_max_depth = 10
xdebug.var_display_max_children = 256
xdebug.var_display_max_data = 4096
65 changes: 55 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,35 @@ services:
- ./tests:/usr/src/code/tests
- ./dev:/usr/src/code/dev
- ./phpunit.xml:/usr/src/code/phpunit.xml
ports:
- "8708:8708"
- ./dev/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini

adminer:
image: adminer
container_name: utopia-adminer
restart: always
ports:
- "8760:8080"
- "8700:8080"
networks:
- database

postgres:
image: postgres:13
image: postgres:16.4
container_name: utopia-postgres
networks:
- database
ports:
- "8700:5432"
- "8701:5432"
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: password

postgres-mirror:
image: postgres:16.4
container_name: utopia-postgres-mirror
networks:
- database
ports:
- "8702:5432"
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: password
Expand All @@ -44,7 +54,18 @@ services:
networks:
- database
ports:
- "8701:3306"
- "8703:3306"
environment:
- MYSQL_ROOT_PASSWORD=password

mariadb-mirror:
image: mariadb:10.11
container_name: utopia-mariadb-mirror
command: mariadbd --max_allowed_packet=1G
networks:
- database
ports:
- "8704:3306"
environment:
- MYSQL_ROOT_PASSWORD=password

Expand All @@ -54,7 +75,7 @@ services:
networks:
- database
ports:
- "8702:27017"
- "8705:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
Expand All @@ -65,7 +86,23 @@ services:
networks:
- database
ports:
- "8703:3307"
- "8706:3307"
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: default
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_TCP_PORT: 3307
cap_add:
- SYS_NICE

mysql-mirror:
image: mysql:8.0.33
container_name: utopia-mysql-mirror
networks:
- database
ports:
- "8707:3307"
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: default
Expand All @@ -76,10 +113,18 @@ services:
- SYS_NICE

redis:
image: redis:6.0-alpine
image: redis:7.4.1-alpine3.20
container_name: utopia-redis
ports:
- "8706:6379"
- "8708:6379"
networks:
- database

redis-mirror:
image: redis:7.4.1-alpine3.20
container_name: utopia-redis-mirror
ports:
- "8709:6379"
networks:
- database

Expand Down
14 changes: 7 additions & 7 deletions src/Database/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract class Adapter
*
* @return $this
*/
public function setDebug(string $key, mixed $value): self
public function setDebug(string $key, mixed $value): static
{
$this->debug[$key] = $value;

Expand All @@ -59,9 +59,9 @@ public function getDebug(): array
}

/**
* @return self
* @return static
*/
public function resetDebug(): self
public function resetDebug(): static
{
$this->debug = [];

Expand Down Expand Up @@ -197,7 +197,7 @@ public function getTenant(): ?int
* @param mixed $value
* @return $this
*/
public function setMetadata(string $key, mixed $value): self
public function setMetadata(string $key, mixed $value): static
{
$this->metadata[$key] = $value;

Expand Down Expand Up @@ -228,7 +228,7 @@ public function getMetadata(): array
*
* @return $this
*/
public function resetMetadata(): self
public function resetMetadata(): static
{
$this->metadata = [];

Expand Down Expand Up @@ -354,9 +354,9 @@ public function withTransaction(callable $callback): mixed
* @param string $event
* @param string $name
* @param ?callable $callback
* @return self
* @return static
*/
public function before(string $event, string $name = '', ?callable $callback = null): self
public function before(string $event, string $name = '', ?callable $callback = null): static
{
if (!isset($this->transformations[$event])) {
$this->transformations[$event] = [];
Expand Down
Loading

0 comments on commit 895176b

Please sign in to comment.