Skip to content

Commit

Permalink
Merge pull request #9 from lohanidamodar/feat-utopia-db-integration
Browse files Browse the repository at this point in the history
first draft using utopia-php database
  • Loading branch information
eldadfux authored Aug 1, 2021
2 parents 57e4f8f + e4b03bf commit f81bbe0
Show file tree
Hide file tree
Showing 13 changed files with 4,392 additions and 328 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
composer.lock
/vendor/
/.idea/
38 changes: 28 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
language: php
dist: xenial

php:
- 7.4
- 8.0
- nightly
arch:
- amd64

os: linux

language: shell

services:
- mysql
- docker

notifications:
email:
- team@appwrite.io

before_script: docker run --rm --interactive --tty --volume "$(pwd)":/app composer update --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist

before_install:
- mysql < data/schema.sql
- curl -fsSL https://get.docker.com | sh
- echo '{"experimental":"enabled"}' | sudo tee /etc/docker/daemon.json
- mkdir -p $HOME/.docker
- echo '{"experimental":"enabled"}' | sudo tee $HOME/.docker/config.json
- sudo service docker start
- >
if [ ! -z "${DOCKERHUB_PULL_USERNAME:-}" ]; then
echo "${DOCKERHUB_PULL_PASSWORD}" | docker login --username "${DOCKERHUB_PULL_USERNAME}" --password-stdin
fi
- docker --version

before_script: composer install --ignore-platform-reqs
install:
- docker-compose up -d
- sleep 10

script:
- vendor/bin/phpunit --configuration phpunit.xml
- vendor/bin/psalm --show-info=true
- docker ps
- docker-compose exec php7.4 vendor/bin/phpunit --configuration phpunit.xml tests
- docker-compose exec php7.4 vendor/bin/psalm --show-info=true
- docker-compose exec php8 vendor/bin/phpunit --configuration phpunit.xml tests
- docker-compose exec php8 vendor/bin/psalm --show-info=true
27 changes: 27 additions & 0 deletions Dockerfile-php7
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM composer:2.0 as step0

WORKDIR /src/

COPY ./composer.json /src/
COPY ./composer.lock /src/

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

FROM php:7.4-cli-alpine as final

LABEL maintainer="team@appwrite.io"

RUN docker-php-ext-install pdo_mysql

WORKDIR /code

COPY --from=step0 /src/vendor /code/vendor

# Add Source Code
COPY ./tests /code/tests
COPY ./src /code/src
COPY ./phpunit.xml /code/phpunit.xml
COPY ./psalm.xml /code/psalm.xml

CMD [ "tail", "-f", "/dev/null" ]
27 changes: 27 additions & 0 deletions Dockerfile-php8
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM composer:2.0 as step0

WORKDIR /src/

COPY composer.lock /src/
COPY composer.json /src/

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

FROM php:8.0-cli-alpine as final

LABEL maintainer="team@appwrite.io"

RUN docker-php-ext-install pdo_mysql

WORKDIR /code

COPY --from=step0 /src/vendor /code/vendor

# Add Source Code
COPY ./tests /code/tests
COPY ./src /code/src
COPY ./phpunit.xml /code/phpunit.xml
COPY ./psalm.xml /code/psalm.xml

CMD [ "tail", "-f", "/dev/null" ]
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,35 @@ Init the audit object:

require_once __DIR__ . '/../../vendor/autoload.php';

use PDO;
use PDO;
use Utopia\Audit\Audit;
use Utopia\Audit\Adapters\MySQL;
use Utopia\Cache\Cache;
use Utopia\Cache\Adapter\None as NoCache;
use Utopia\Database\Adapter\MySQL;
use Utopia\Database\Database;


$dbHost = '127.0.0.1';
$dbUser = 'travis';
$dbPass = '';
$dbName = 'audit';

$pdo = new PDO("mysql:host={$dbHost};dbname={$dbName}", $dbUser, $dbPass, array(
$pdo = new PDO("mysql:host={$dbHost}", $dbUser, $dbPass, array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
PDO::ATTR_TIMEOUT => 5 // Seconds
));

// Connection settings
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); // Return arrays
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Handle all errors with exceptions
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Handle all errors with exceptions

$adapter = new MySQL($pdo);
$cache = new Cache(new NoCache());

$adapter
->setNamespace('namespace') // DB table namespace
;
$database = new Database(new MySQL($pdo),$cache);
$database->setNamespace('namespace');

$audit = new Audit($adapter);
$audit = new Audit($database);
$audit->setup();
```

**Create Log**
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
},
"require": {
"php": ">=7.4",
"ext-pdo": "*"
"ext-pdo": "*",
"utopia-php/database": "0.5.*"
},
"require-dev": {
"phpunit/phpunit": "^9.3",
Expand Down
Loading

0 comments on commit f81bbe0

Please sign in to comment.