Skip to content

Commit

Permalink
- [bugfix] do not ignore readonly schema
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy-j committed Jan 14, 2020
1 parent eb8e045 commit e248689
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
21 changes: 6 additions & 15 deletions src/GenerateMigrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@

namespace Cycle\Migrations;

use Cycle\Schema\Generator\SyncTables;
use Cycle\Schema\GeneratorInterface;
use Cycle\Schema\Registry;
use Spiral\Database\Schema\AbstractTable;
use Spiral\Migrations\Atomizer\Atomizer;
use Spiral\Migrations\Atomizer\Renderer;
use Spiral\Migrations\Atomizer\RendererInterface;
use Spiral\Migrations\Config\MigrationConfig;
use Spiral\Migrations\Migration;
use Spiral\Migrations\RepositoryInterface;
use Spiral\Reactor\ClassDeclaration;
use Spiral\Reactor\FileDeclaration;

/**
* Migration generator creates set of migrations needed to sync database schema with desired state. Each database will
Expand All @@ -35,27 +32,21 @@ class GenerateMigrations implements GeneratorInterface
/** @var RepositoryInterface */
private $repository;

/** @var RendererInterface */
private $renderer;

/** @var MigrationConfig $migrationConfig */
private $migrationConfig;

/**
* GenerateMigrations constructor.
*
* @param RepositoryInterface $migrationRepository
* @param MigrationConfig $migrationConfig
* @param RendererInterface|null $renderer
* @param RepositoryInterface $migrationRepository
* @param MigrationConfig $migrationConfig
*/
public function __construct(
RepositoryInterface $migrationRepository,
MigrationConfig $migrationConfig,
RendererInterface $renderer = null
MigrationConfig $migrationConfig
) {
$this->repository = $migrationRepository;
$this->migrationConfig = $migrationConfig;
$this->renderer = $renderer ?? new Renderer();
}

/**
Expand All @@ -66,7 +57,7 @@ public function run(Registry $registry): Registry
{
$databases = [];
foreach ($registry as $e) {
if ($registry->hasTable($e)) {
if ($registry->hasTable($e) && !$e->getOptions()->has(SyncTables::READONLY_SCHEMA)) {
$databases[$registry->getDatabase($e)][] = $registry->getTableSchema($e);
}
}
Expand Down Expand Up @@ -182,6 +173,6 @@ private function generateName(Atomizer $atomizer): string
}
}

return join('_', $name);
return implode('_', $name);
}
}
41 changes: 39 additions & 2 deletions src/MigrationImage.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Cycle\Migrations;

use Spiral\Migrations\Config\MigrationConfig;
Expand All @@ -9,19 +11,30 @@

class MigrationImage
{

/** @var string */
public $fileNamePattern = '{database}_{name}';
/** @var ClassDeclaration */
protected $class;

/** @var FileDeclaration */
protected $file;

/** @var MigrationConfig */
protected $migrationConfig;

/** @var string */
protected $database;

/** @var string */
protected $name = '';

public $fileNamePattern = '{database}_{name}';

/**
* MigrationImage constructor.
*
* @param MigrationConfig $config
* @param string $database
*/
public function __construct(MigrationConfig $config, string $database)
{
$this->migrationConfig = $config;
Expand All @@ -37,26 +50,41 @@ public function __construct(MigrationConfig $config, string $database)
$this->setDatabase($database);
}

/**
* @return ClassDeclaration
*/
public function getClass(): ClassDeclaration
{
return $this->class;
}

/**
* @return FileDeclaration
*/
public function getFile(): FileDeclaration
{
return $this->file;
}

/**
* @return MigrationConfig
*/
public function getMigrationConfig(): MigrationConfig
{
return $this->migrationConfig;
}

/**
* @return string
*/
public function getDatabase(): string
{
return $this->database;
}

/**
* @param string $database
*/
public function setDatabase(string $database): void
{
$this->database = $database;
Expand All @@ -71,16 +99,25 @@ public function setDatabase(string $database): void
$this->class->constant('DATABASE')->setProtected()->setValue($database);
}

/**
* @return string
*/
public function buildFileName(): string
{
return str_replace(['{database}', '{name}'], [$this->database, $this->name], $this->fileNamePattern);
}

/**
* @return string
*/
public function getName(): string
{
return $this->name;
}

/**
* @param string $name
*/
public function setName(string $name): void
{
$this->name = $name;
Expand Down

0 comments on commit e248689

Please sign in to comment.