Skip to content

Commit

Permalink
added migration
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanmula committed Aug 27, 2019
1 parent c6b1796 commit e824db4
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ down: ## down dockers
install: ## make composer install
docker-compose -f ${FILE} exec --user=${UID} ${CONTAINER} sh -c "php bin/composer.phar install"

init: ## init environment
docker-compose -f ${FILE} run --rm -u ${UID}:${GID} php php bin/console ocib:environment:init

checkin: ## new checkin
docker-compose -f ${FILE} run --rm -u ${UID}:${GID} php php bin/console ocib:checkin:add

Expand Down
12 changes: 12 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ services:
- "%env(TELEGRAM_TOKEN)%"
- "%env(TELEGRAM_CHAT_ID)%"

migration.sqlite:
class: App\Infrastructure\SqliteMigration
arguments:
- '%db%'

command.init-environment:
class: App\Entrypoint\Command\InitEnvironmentCommand
arguments:
- '@migration.sqlite'
tags:
- { name: console.command, command: 'ocib:environment:init' }

command.checkin:
class: App\Entrypoint\Command\CheckInCommand
arguments:
Expand Down
9 changes: 9 additions & 0 deletions src/Domain/Persistence/Migration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php declare(strict_types=1);

namespace App\Domain\Persistence;

interface Migration
{
public function up(): void;
public function down(): void;
}
35 changes: 35 additions & 0 deletions src/Entrypoint/Command/InitEnvironmentCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php declare(strict_types=1);

namespace App\Entrypoint\Command;

use App\Domain\Persistence\Migration;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class InitEnvironmentCommand extends Command
{
private $migrations;

public function __construct(Migration ...$migration)
{
parent::__construct(null);

$this->migrations = $migration;
}

protected function configure(): void
{
$this->setDescription('Environment init');
}

protected function execute(InputInterface $input, OutputInterface $output): void
{
foreach ($this->migrations as $migration) {
$migration->down();
$migration->up();

$output->writeln(get_class($migration) . ' executed');
}
}
}
Binary file modified src/Infrastructure/DataBase/OCIB.db
Binary file not shown.
25 changes: 25 additions & 0 deletions src/Infrastructure/SqliteMigration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types=1);

namespace App\Infrastructure;

use App\Domain\Persistence\Migration;

class SqliteMigration implements Migration
{
protected $connection;

public function __construct(string $url)
{
$this->connection = new \SQLite3($url);
}

public function up(): void
{
$this->connection->exec('CREATE TABLE "not-working-days" (date TEXT NOT NULL)');
}

public function down(): void
{
$this->connection->exec('DROP TABLE IF EXISTS "not-working-days"');
}
}

0 comments on commit e824db4

Please sign in to comment.