Skip to content

Commit

Permalink
Revert "[4.0]Migration file prefix date specification option"
Browse files Browse the repository at this point in the history
  • Loading branch information
ucan-lab authored Jan 24, 2021
1 parent 2e27fc1 commit b5c7a5f
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 99 deletions.
13 changes: 1 addition & 12 deletions src/Console/DacapoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace UcanLab\LaravelDacapo\Console;

use DateTime;
use Exception;
use Illuminate\Console\ConfirmableTrait;
use UcanLab\LaravelDacapo\Dacapo\UseCase\Console\DacapoCommandUseCase;

Expand All @@ -24,7 +22,6 @@ class DacapoCommand extends Command
{--no-migrate : Do not migrate}
{--seed : Seed the database with records}
{--refresh : Migrate refresh (for debug)}
{--prefix=1970-01-01 : Prefix date of the output migration file}
';

/**
Expand Down Expand Up @@ -54,15 +51,7 @@ public function handle(): void
{
$this->call('dacapo:clear', ['--force' => true]);

try {
$prefixDate = new DateTime($this->option('prefix'));
} catch (Exception $exception) {
$this->error('Error: Set the --prefix option to a value that can be converted to a date type.');

return;
}

$fileList = $this->useCase->handle($prefixDate);
$fileList = $this->useCase->handle();

foreach ($fileList as $file) {
$this->line(sprintf('<fg=green>Generated:</> %s', $file->getName()));
Expand Down
6 changes: 2 additions & 4 deletions src/Dacapo/UseCase/Console/DacapoCommandUseCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace UcanLab\LaravelDacapo\Dacapo\UseCase\Console;

use DateTime;
use UcanLab\LaravelDacapo\Dacapo\Domain\ValueObject\Migration\MigrationFileList;
use UcanLab\LaravelDacapo\Dacapo\UseCase\Generator\MigrationGenerator;
use UcanLab\LaravelDacapo\Dacapo\UseCase\Port\SchemaListRepository;
Expand All @@ -24,11 +23,10 @@ public function __construct(SchemaListRepository $repository, MigrationGenerator
}

/**
* @param DateTime $prefixDate
* @return MigrationFileList
*/
public function handle(DateTime $prefixDate): MigrationFileList
public function handle(): MigrationFileList
{
return $this->generator->generate($prefixDate, $this->repository->get());
return $this->generator->generate($this->repository->get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace UcanLab\LaravelDacapo\Dacapo\UseCase\Converter;

use DateTime;
use Illuminate\Support\Str;
use UcanLab\LaravelDacapo\Dacapo\Domain\Entity\Schema;
use UcanLab\LaravelDacapo\Dacapo\Domain\Entity\SchemaList;
Expand All @@ -12,16 +11,7 @@
class SchemaToConstraintForeignKeyMigrationConverter
{
const MIGRATION_COLUMN_INDENT = ' ';
protected DateTime $prefixDate;

/**
* SchemaToConstraintForeignKeyMigrationConverter constructor.
* @param DateTime $prefixDate
*/
public function __construct(DateTime $prefixDate)
{
$this->prefixDate = $prefixDate;
}
protected Schema $schema;

/**
* @param SchemaList $schemaList
Expand All @@ -40,17 +30,6 @@ public function convertList(SchemaList $schemaList): MigrationFileList
return $fileList;
}

/**
* @param DateTime $prefixDate
* @return $this
*/
public function setPrefixDate(DateTime $prefixDate): self
{
$this->prefixDate = $prefixDate;

return $this;
}

/**
* @param Schema $schema
* @return MigrationFile
Expand All @@ -66,7 +45,7 @@ public function convert(Schema $schema): MigrationFile
*/
protected function makeMigrationFileName(Schema $schema): string
{
return sprintf('%s_000003_%s.php', $this->prefixDate->format('Y_m_d'), $this->makeMigrationName($schema));
return sprintf('1970_01_01_000003_%s.php', $this->makeMigrationName($schema));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace UcanLab\LaravelDacapo\Dacapo\UseCase\Converter;

use DateTime;
use Illuminate\Support\Str;
use UcanLab\LaravelDacapo\Dacapo\Domain\Entity\Schema;
use UcanLab\LaravelDacapo\Dacapo\Domain\Entity\SchemaList;
Expand All @@ -12,27 +11,7 @@
class SchemaToCreateIndexMigrationConverter
{
const MIGRATION_COLUMN_INDENT = ' ';
protected DateTime $prefixDate;

/**
* SchemaToCreateIndexMigrationConverter constructor.
* @param DateTime $prefixDate
*/
public function __construct(DateTime $prefixDate)
{
$this->prefixDate = $prefixDate;
}

/**
* @param DateTime $prefixDate
* @return $this
*/
public function setPrefixDate(DateTime $prefixDate): self
{
$this->prefixDate = $prefixDate;

return $this;
}
protected Schema $schema;

/**
* @param SchemaList $schemaList
Expand Down Expand Up @@ -66,7 +45,7 @@ public function convert(Schema $schema): MigrationFile
*/
protected function makeMigrationFileName(Schema $schema): string
{
return sprintf('%s_000002_%s.php', $this->prefixDate->format('Y_m_d'), $this->makeMigrationName($schema));
return sprintf('1970_01_01_000002_%s.php', $this->makeMigrationName($schema));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace UcanLab\LaravelDacapo\Dacapo\UseCase\Converter;

use DateTime;
use Illuminate\Support\Str;
use UcanLab\LaravelDacapo\Dacapo\Domain\Entity\Schema;
use UcanLab\LaravelDacapo\Dacapo\Domain\Entity\SchemaList;
Expand All @@ -15,28 +14,10 @@ class SchemaToCreateTableMigrationConverter
const MIGRATION_COLUMN_INDENT = ' ';

protected DatabaseBuilder $databaseBuilder;
protected DateTime $prefixDate;

/**
* SchemaToCreateTableMigrationConverter constructor.
* @param DatabaseBuilder $databaseBuilder
* @param DateTime $prefixDate
*/
public function __construct(DatabaseBuilder $databaseBuilder, DateTime $prefixDate)
public function __construct(DatabaseBuilder $databaseBuilder)
{
$this->databaseBuilder = $databaseBuilder;
$this->prefixDate = $prefixDate;
}

/**
* @param DateTime $prefixDate
* @return $this
*/
public function setPrefixDate(DateTime $prefixDate): self
{
$this->prefixDate = $prefixDate;

return $this;
}

/**
Expand Down Expand Up @@ -71,7 +52,7 @@ public function convert(Schema $schema): MigrationFile
*/
protected function makeMigrationFileName(Schema $schema): string
{
return sprintf('%s_000001_%s.php', $this->prefixDate->format('Y_m_d'), $this->makeMigrationName($schema));
return sprintf('1970_01_01_000001_%s.php', $this->makeMigrationName($schema));
}

/**
Expand Down
8 changes: 1 addition & 7 deletions src/Dacapo/UseCase/Generator/MigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace UcanLab\LaravelDacapo\Dacapo\UseCase\Generator;

use DateTime;
use UcanLab\LaravelDacapo\Dacapo\Domain\Entity\SchemaList;
use UcanLab\LaravelDacapo\Dacapo\Domain\ValueObject\Migration\MigrationFileList;
use UcanLab\LaravelDacapo\Dacapo\UseCase\Converter\SchemaToConstraintForeignKeyMigrationConverter;
Expand Down Expand Up @@ -37,16 +36,11 @@ public function __construct(
}

/**
* @param DateTime $prefixDate
* @param SchemaList $schemaList
* @return MigrationFileList
*/
public function generate(DateTime $prefixDate, SchemaList $schemaList): MigrationFileList
public function generate(SchemaList $schemaList): MigrationFileList
{
$this->schemaToCreateTableMigrationConverter->setPrefixDate($prefixDate);
$this->schemaToCreateIndexMigrationConverter->setPrefixDate($prefixDate);
$this->schemaToConstraintForeignKeyMigrationConverter->setPrefixDate($prefixDate);

$tableFileList = $this->generateCreateTable($schemaList);
$indexFileList = $this->generateCreateIndex($schemaList);
$foreignKeyFileList = $this->generateConstraintForeignKey($schemaList);
Expand Down
2 changes: 0 additions & 2 deletions tests/Console/DacapoClearCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace UcanLab\LaravelDacapo\Test\App\UseCase\Console;

use DateTime;
use UcanLab\LaravelDacapo\Dacapo\Domain\ValueObject\Migration\MigrationFile;
use UcanLab\LaravelDacapo\Dacapo\Domain\ValueObject\Migration\MigrationFileList;
use UcanLab\LaravelDacapo\Dacapo\Infra\Adapter\InMemoryMigrationListRepository;
Expand All @@ -15,7 +14,6 @@ class DacapoClearCommandTest extends TestCase
public function testResolve(): void
{
$this->app->register(ConsoleServiceProvider::class);
$this->instance(DateTime::class, new DateTime());
$this->instance(MigrationListRepository::class, new InMemoryMigrationListRepository(new MigrationFileList([
new MigrationFile('1970_01_01_000000_create_users_table.php', ''),
new MigrationFile('1970_01_01_000000_create_password_resets_table.php', ''),
Expand Down
3 changes: 0 additions & 3 deletions tests/Console/DacapoCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace UcanLab\LaravelDacapo\Test\App\UseCase\Console;

use DateTime;
use Illuminate\Support\Facades\File;
use UcanLab\LaravelDacapo\Dacapo\Domain\ValueObject\Migration\MigrationFile;
use UcanLab\LaravelDacapo\Dacapo\Domain\ValueObject\Migration\MigrationFileList;
Expand Down Expand Up @@ -30,7 +29,6 @@ public function testMysql(MigrationFileList $expectedMigrationFileList, SchemaFi
$this->app->register(ConsoleServiceProvider::class);

$actualMigrationFileList = new MigrationFileList();
$this->instance(DateTime::class, new DateTime());
$this->instance(DatabaseBuilder::class, new MysqlDatabaseBuilder());
$this->instance(SchemaListRepository::class, new InMemorySchemaListRepository($schemaFileList));
$this->instance(MigrationListRepository::class, new InMemoryMigrationListRepository($actualMigrationFileList));
Expand Down Expand Up @@ -83,7 +81,6 @@ public function testPostgresql(MigrationFileList $expectedMigrationFileList, Sch
$this->app->register(ConsoleServiceProvider::class);

$actualMigrationFileList = new MigrationFileList();
$this->instance(DateTime::class, new DateTime());
$this->instance(DatabaseBuilder::class, new PostgresqlDatabaseBuilder());
$this->instance(SchemaListRepository::class, new InMemorySchemaListRepository($schemaFileList));
$this->instance(MigrationListRepository::class, new InMemoryMigrationListRepository($actualMigrationFileList));
Expand Down
2 changes: 0 additions & 2 deletions tests/Console/DacapoInitCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace UcanLab\LaravelDacapo\Test\App\UseCase\Console;

use DateTime;
use UcanLab\LaravelDacapo\Dacapo\Domain\ValueObject\Schema\SchemaFileList;
use UcanLab\LaravelDacapo\Dacapo\Infra\Adapter\InMemorySchemaListRepository;
use UcanLab\LaravelDacapo\Dacapo\UseCase\Port\SchemaListRepository;
Expand All @@ -14,7 +13,6 @@ class DacapoInitCommandTest extends TestCase
public function testResolve(): void
{
$this->app->register(ConsoleServiceProvider::class);
$this->instance(DateTime::class, new DateTime());
$this->instance(SchemaListRepository::class, new InMemorySchemaListRepository(new SchemaFileList()));
$this->artisan('dacapo:init')->assertExitCode(0);
}
Expand Down
2 changes: 0 additions & 2 deletions tests/Console/DacapoUninstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace UcanLab\LaravelDacapo\Test\App\UseCase\Console;

use DateTime;
use UcanLab\LaravelDacapo\Dacapo\Domain\ValueObject\Schema\SchemaFileList;
use UcanLab\LaravelDacapo\Dacapo\Infra\Adapter\InMemorySchemaListRepository;
use UcanLab\LaravelDacapo\Dacapo\UseCase\Port\SchemaListRepository;
Expand All @@ -14,7 +13,6 @@ class DacapoUninstallCommandTest extends TestCase
public function testResolve(): void
{
$this->app->register(ConsoleServiceProvider::class);
$this->instance(DateTime::class, new DateTime());
$this->instance(SchemaListRepository::class, new InMemorySchemaListRepository(new SchemaFileList()));
$this->artisan('dacapo:uninstall')->assertExitCode(0);
}
Expand Down

0 comments on commit b5c7a5f

Please sign in to comment.