Skip to content

Commit

Permalink
Merge pull request #25 from utopia-php/dev
Browse files Browse the repository at this point in the history
Merge dev into main
  • Loading branch information
eldadfux authored Feb 25, 2024
2 parents f78273b + a18b197 commit a72f27b
Show file tree
Hide file tree
Showing 35 changed files with 487 additions and 489 deletions.
26 changes: 5 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
FROM supabase/postgres:15.1.0.96 as supabase-db
COPY ./tests/Migration/resources/supabase/1_globals.sql /docker-entrypoint-initdb.d/1_globals.sql
COPY ./tests/Migration/resources/supabase/2_main.sql /docker-entrypoint-initdb.d/2_main.sql
COPY tests/Migration/resources/supabase/1_globals.sql /docker-entrypoint-initdb.d/1_globals.sql
COPY tests/Migration/resources/supabase/2_main.sql /docker-entrypoint-initdb.d/2_main.sql
RUN rm -rf /docker-entrypoint-initdb.d/migrate.sh

FROM postgres:alpine3.18 as nhost-db
COPY ./tests/Migration/resources/nhost/1_globals.sql /docker-entrypoint-initdb.d/1_globals.sql
COPY ./tests/Migration/resources/nhost/2_main.sql /docker-entrypoint-initdb.d/2_main.sql

# Use my fork of mockoon while waiting for range headers to be merged
FROM node:20.4-alpine3.17 as mock-api
WORKDIR /app
RUN apk add --no-cache git
RUN git clone https://github.com/PineappleIOnic/mockoon.git
WORKDIR /app/mockoon
RUN git checkout origin/feat-implement-range
RUN apk add python3 make gcc g++
RUN npm run bootstrap
RUN npm run build:libs
RUN npm run build:cli
RUN cd packages/cli && npm install -g .
RUN adduser --shell /bin/sh --disabled-password --gecos "" mockoon
USER mockoon
CMD mockoon-cli start --data /mockoon/api.json --port 80 --disable-log-to-file && tail -f /dev/null
COPY tests/Migration/resources/nhost/1_globals.sql /docker-entrypoint-initdb.d/1_globals.sql
COPY tests/Migration/resources/nhost/2_main.sql /docker-entrypoint-initdb.d/2_main.sql

FROM composer:2.0 as composer
WORKDIR /usr/local/src/
Expand All @@ -37,4 +21,4 @@ RUN set -ex \
COPY ./src /app/src
COPY ./tests /app/src/tests
COPY --from=composer /usr/local/src/vendor /app/vendor
CMD tail -f /dev/null
CMD tail -f /dev/null
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"require": {
"php": "8.*",
"utopia-php/cli": "0.*",
"appwrite/appwrite": "10.0.*"
"appwrite/appwrite": "10.1.0"
},
"require-dev": {
"phpunit/phpunit": "9.*",
Expand Down
14 changes: 6 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,18 @@ services:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres

nhost-storage:
build:
context: .
target: mock-api
image: mockoon/cli:latest
command: ["--data", "/mockoon/api.json", "--port", "80", "--disable-log-to-file"]
networks:
- tests
volumes:
- ./tests/Migration/resources/nhost:/mockoon

supabase-api:
build:
context: .
target: mock-api
image: mockoon/cli:latest
command: ["--data", "/mockoon/api.json", "--port", "80", "--disable-log-to-file"]
networks:
- tests
volumes:
Expand All @@ -65,4 +63,4 @@ services:
- SUPABASE_DB_URL=postgres://postgres:postgres@supabase-db:5432/postgres

networks:
tests:
tests:
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
<directory>./tests/Migration/E2E</directory>
</testsuite>
</testsuites>
</phpunit>
</phpunit>
30 changes: 17 additions & 13 deletions playground.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Utopia\CLI\Console;
use Utopia\Migration\Destinations\Appwrite as AppwriteDestination;
use Utopia\Migration\Destinations\Local;
use Utopia\Migration\Resource;
use Utopia\Migration\Sources\Appwrite;
use Utopia\Migration\Sources\Firebase;
use Utopia\Migration\Sources\NHost;
Expand Down Expand Up @@ -74,25 +73,30 @@
$destinationAppwrite
);

// /**
// * Run Transfer
// */
$transfer->run($sourceAppwrite->getSupportedResources(),
function (array $resources) {
/**
* Run Transfer
*/
$transfer->run(
$sourceAppwrite->getSupportedResources(),
function (array $resources) use ($transfer) {
var_dump($transfer->getStatusCounters());
}
);

$report = [];

$cache = $transfer->getCache()->getAll();

foreach ($cache as $type => $resources) {
foreach ($resources as $resource) {
/** @var resource $resource */
if ($resource->getStatus() !== Resource::STATUS_ERROR) {
continue;
}
if (count($sourceAppwrite->getErrors()) > 0) {
foreach ($sourceAppwrite->getErrors() as $error) {
/* @var \Utopia\Migration\Exception $error */
Console::error('[Source] ['.$error->getResourceType().'] '.$error->getMessage());
}
}

Console::error($resource->getName().' '.$resource->getInternalId().' '.$resource->getMessage());
if (count($destinationAppwrite->getErrors()) > 0) {
foreach ($destinationAppwrite->getErrors() as $error) {
/* @var \Utopia\Migration\Exception $error */
Console::error('[Destination] ['.$error->getResourceType().'] '.$error->getMessage());
}
}
6 changes: 6 additions & 0 deletions src/Migration/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public function add($resource)
$this->cache[$resource->getName()][$resource->getInternalId()] = $resource;
}

/**
* Add All Resources
*
* @param resource[] $resources
* @return void
*/
public function addAll(array $resources)
{
foreach ($resources as $resource) {
Expand Down
6 changes: 5 additions & 1 deletion src/Migration/Destination.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public function setSource(Source $source): self

/**
* Transfer Resources to Destination from Source callback
*
* @param string[] $resources Resources to transfer
* @param callable $callback Callback to run after transfer
*/
public function run(array $resources, callable $callback): void
{
Expand All @@ -40,7 +43,8 @@ public function run(array $resources, callable $callback): void
/**
* Import Resources
*
* @param callable $callback (array $resources)
* @param resource[] $resources Resources to import
* @param callable $callback Callback to run after import
*/
abstract protected function import(array $resources, callable $callback): void;
}
Loading

0 comments on commit a72f27b

Please sign in to comment.