Skip to content

Commit

Permalink
refactor: improve migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielberthier committed May 9, 2023
1 parent 6033b5c commit 68bd1d7
Show file tree
Hide file tree
Showing 6 changed files with 604 additions and 808 deletions.
43 changes: 43 additions & 0 deletions app/Data/Migrations/Version20230509190734.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Core\Data\Migrations;

use DateTimeImmutable;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230509190734 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
$date = new DateTimeImmutable();
$now = $date->getTimestamp();
$fields = "id,email,username,password,role,uuid,created_at,updated_at";
$values = array(
"id" => 42,
"email" => '[email protected]',
"username" => 'admin',
"password" => '$2y$08$dBhkPXXqtiZoRyFQ5BIfaOVe2pbdd03lZaEUnux9pNcbGf4/5epoe',
"role" => 'admin',
"uuid" => '0c04d7f5-5e42-4fdd-9ba2-d1b44cd22ac9',
"created_at" => $now,
"updated_at" => $now
);
$this->addSql("INSERT into accounts ({$fields}) VALUES (:id,:email,:username,:password,:role,:uuid,:created_at,:updated_at)", $values);
}

public function down(Schema $schema): void
{
$this->addSql("DELETE FROM accounts where id = :id", ['id' => 42]);
}
}
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"firebase/php-jwt": "^5.2",
"gabrielberthier/s3-data-transfer": "~1.0",
"league/flysystem-aws-s3-v3": "^1.0",
"lodash-php/lodash-php": "^0.0.7",
"maennchen/zipstream-php": "^2.1",
"middlewares/trailing-slash": "^2.0",
"monolog/monolog": ">=2.0",
Expand Down Expand Up @@ -75,7 +74,7 @@
"test:nodebug": "@php -c ./disable-xdebug.ini && phpunit",
"test:update": "phpunit --migrate-configuration",
"doctrine": "doctrine",
"doctrine:create-db": "doctrine orm:clear-cache:metadata && doctrine orm:schema-tool:create && doctrine dbal:import database/bootstrap.sql",
"doctrine:create-db": "doctrine orm:clear-cache:metadata && doctrine orm:schema-tool:create && doctrine dbal:run-sql database/bootstrap.sql",
"doctrine:update-db": "doctrine orm:schema-tool:update",
"doctrine:drop-db": "doctrine orm:schema-tool:drop --force",
"doctrine:clear-cache": "doctrine orm:clear-cache:metadata && doctrine orm:clear-cache:query && doctrine orm:clear-cache:result"
Expand Down
Loading

0 comments on commit 68bd1d7

Please sign in to comment.