Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into null-bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
abnegate committed Jan 19, 2024
2 parents 83e2525 + 2651f41 commit d5499c8
Show file tree
Hide file tree
Showing 70 changed files with 5,419 additions and 2,369 deletions.
126 changes: 93 additions & 33 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,100 @@
name: "Tests"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
IMAGE: databases-dev
CACHE_KEY: databases-dev-${{ github.event.pull_request.head.sha }}

on: [pull_request]

jobs:
tests:
name: Unit & E2E
setup:
name: Setup & Build Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build Docker Image
uses: docker/build-push-action@v3
with:
context: .
push: false
tags: ${{ env.IMAGE }}
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=docker,dest=/tmp/${{ env.IMAGE }}.tar

- name: Cache Docker Image
uses: actions/cache@v3
with:
key: ${{ env.CACHE_KEY }}
path: /tmp/${{ env.IMAGE }}.tar

unit_test:
name: Unit Test
runs-on: ubuntu-latest
needs: setup

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 2
submodules: recursive

- run: git checkout HEAD^2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build image
uses: docker/build-push-action@v3
with:
context: .
push: false
tags: database-dev
load: true
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Start Databases
run: |
docker compose up -d
sleep 10
- name: Run Tests
run: docker compose exec -T tests vendor/bin/phpunit --configuration phpunit.xml

- name: Check Coverage
run: docker compose exec -T tests vendor/bin/coverage-check tmp/clover.xml 90
- name: checkout
uses: actions/checkout@v2

- name: Load Cache
uses: actions/cache@v3
with:
key: ${{ env.CACHE_KEY }}
path: /tmp/${{ env.IMAGE }}.tar
fail-on-cache-miss: true

- name: Load and Start Services
run: |
docker load --input /tmp/${{ env.IMAGE }}.tar
docker compose up -d
sleep 10
- name: Run Unit Tests
run: docker compose exec tests vendor/bin/phpunit /usr/src/code/tests/unit

adapter_test:
name: Adapter Tests
runs-on: ubuntu-latest
needs: setup
strategy:
fail-fast: false
matrix:
adapter:
[
MariaDB,
MySQL,
Postgres,
SQLite,
MongoDB,
]

steps:
- name: checkout
uses: actions/checkout@v3

- name: Load Cache
uses: actions/cache@v3
with:
key: ${{ env.CACHE_KEY }}
path: /tmp/${{ env.IMAGE }}.tar
fail-on-cache-miss: true

- name: Load and Start Services
run: |
docker load --input /tmp/${{ env.IMAGE }}.tar
docker compose up -d
sleep 10
- name: Run ${{matrix.service}} Tests
run: docker compose exec -T tests vendor/bin/phpunit /usr/src/code/tests/e2e/Adapter/${{matrix.adapter}}Test.php --debug
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ mock.json
data-tests.php
loader.php
.phpunit.result.cache
/bin/view/results/
.vscode
.vscode/*
database.sql

## - Oh Wess!
Makefile
.envrc
.vscode
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ $database->setNamespace(
);

// Get default database
$database->getDefaultDatabase();
$database->getDatabase();

// Sets default database
$database->setDefaultDatabase(
$database->setDatabase(
name: 'dbName'
);

Expand Down Expand Up @@ -402,7 +402,7 @@ $database->deleteCollection(
);

// Delete cached documents of a collection
$database->deleteCachedCollection(
$database->purgeCachedCollection(
collection: 'users'
);
```
Expand Down Expand Up @@ -836,7 +836,7 @@ $database->deleteDocument(

// Delete a cached document
Note: Cached Documents or Collections are automatically deleted when a document or collection is updated or deleted
$database->deleteCachedDocument(
$database->purgeCachedDocument(
collection: 'movies',
id: $document->getId()
);
Expand Down
3 changes: 2 additions & 1 deletion bin/cli.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

// require_once __DIR__.'/init.php';
require_once '/usr/src/code/vendor/autoload.php';

use Utopia\CLI\CLI;

ini_set('memory_limit', '-1');

$cli = new CLI();

include 'tasks/load.php';
Expand Down
22 changes: 11 additions & 11 deletions bin/tasks/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

/**
* @Example
* docker-compose exec tests bin/index --adapter=mysql --name=testing
* docker compose exec tests bin/index --adapter=mysql --name=testing
*/

$cli
->task('index')
->desc('Index mock data for testing queries')
->param('adapter', '', new Text(0), 'Database adapter', false)
->param('name', '', new Text(0), 'Name of created database.', false)
->param('adapter', '', new Text(0), 'Database adapter')
->param('name', '', new Text(0), 'Name of created database.')
->action(function ($adapter, $name) {
$namespace = '_ns';
$cache = new Cache(new NoCache());
Expand Down Expand Up @@ -71,39 +71,39 @@
return;
}

$database->setDefaultDatabase($name);
$database->setDatabase($name);
$database->setNamespace($namespace);

Console::info("For query: greaterThan(created, 2010-01-01 05:00:00)', 'equal(genre,travel)");

Console::info("greaterThan('created', ['2010-01-01 05:00:00']), equal('genre', ['travel'])");
$start = microtime(true);
$database->createIndex('articles', 'createdGenre', Database::INDEX_KEY, ['created', 'genre'], [], [Database::ORDER_DESC, Database::ORDER_DESC]);
$time = microtime(true) - $start;
Console::success("{$time} seconds");

Console::info("equal('genre', ['fashion', 'finance', 'sports'])");

$start = microtime(true);
$database->createIndex('articles', 'genre', Database::INDEX_KEY, ['genre'], [], [Database::ORDER_ASC]);
$time = microtime(true) - $start;
Console::success("{$time} seconds");


Console::info("greaterThan('views', 100000)");

$start = microtime(true);
$database->createIndex('articles', 'views', Database::INDEX_KEY, ['views'], [], [Database::ORDER_DESC]);
$time = microtime(true) - $start;
Console::success("{$time} seconds");


Console::info("search('text', 'Alice')");
$start = microtime(true);
$database->createIndex('articles', 'fulltextsearch', Database::INDEX_FULLTEXT, ['text']);
$time = microtime(true) - $start;
Console::success("{$time} seconds");
});

Console::info("contains('tags', ['tag1'])");
$start = microtime(true);
$database->createIndex('articles', 'tags', Database::INDEX_KEY, ['tags']);
$time = microtime(true) - $start;
Console::success("{$time} seconds");
});

$cli
->error()
Expand Down
Loading

0 comments on commit d5499c8

Please sign in to comment.