Skip to content

Commit

Permalink
Merge pull request #95 from kaskadia/2.0
Browse files Browse the repository at this point in the history
Upgrading to 2.2 in order to support L7. Fixing breaking changes.
  • Loading branch information
eigan authored Apr 5, 2020
2 parents 8922027 + 9933850 commit fa9aac7
Show file tree
Hide file tree
Showing 21 changed files with 228 additions and 113 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: php
php:
- 7.2
- 7.3
- 7.4

cache:
directories:
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
}
],
"require": {
"php": "^7.1",
"doctrine/migrations": "~1.8",
"illuminate/config": "^6.0",
"illuminate/contracts": "^6.0",
"illuminate/console": "^6.0",
"laravel-doctrine/orm": "^1.0"
"php": "^7.2",
"doctrine/migrations": "~2.2",
"illuminate/config": "^7.0",
"illuminate/contracts": "^7.0",
"illuminate/console": "^7.0",
"laravel-doctrine/orm": "^1.6"
},
"require-dev": {
"phpunit/phpunit": "^8.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace LaravelDoctrine\Migrations\Configuration;

use Doctrine\DBAL\Migrations\Configuration\Configuration as MigrationsConfiguration;
use Doctrine\Migrations\Configuration\Configuration as MigrationsConfiguration;
use LaravelDoctrine\Migrations\Naming\NamingStrategy;

class Configuration extends MigrationsConfiguration
Expand Down
6 changes: 5 additions & 1 deletion src/Configuration/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace LaravelDoctrine\Migrations\Configuration;

use Doctrine\DBAL\Connection;
use Doctrine\Migrations\Exception\MigrationException;
use Illuminate\Config\Repository;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Contracts\Container\Container;
use LaravelDoctrine\Migrations\Naming\DefaultNamingStrategy;

Expand Down Expand Up @@ -32,9 +34,11 @@ public function __construct(ConfigRepository $config, Container $container)

/**
* @param Connection $connection
* @param string $name
* @param string $name
*
* @return Configuration
* @throws MigrationException
* @throws BindingResolutionException
*/
public function make(Connection $connection, $name = null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Console/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace LaravelDoctrine\Migrations\Console;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\DBAL\Migrations\Provider\OrmSchemaProvider;
use Doctrine\Migrations\Provider\OrmSchemaProvider;
use Doctrine\ORM\EntityManagerInterface;
use Illuminate\Console\Command;
use LaravelDoctrine\Migrations\Configuration\ConfigurationProvider;
Expand Down
2 changes: 1 addition & 1 deletion src/Console/VersionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace LaravelDoctrine\Migrations\Console;

use Doctrine\DBAL\Migrations\MigrationException;
use Doctrine\Migrations\Exception\MigrationException;
use Illuminate\Console\Command;
use InvalidArgumentException;
use LaravelDoctrine\Migrations\Configuration\Configuration;
Expand Down
10 changes: 8 additions & 2 deletions src/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace LaravelDoctrine\Migrations;

use Doctrine\DBAL\Migrations\Migration as DBALMigration;
use Doctrine\Migrations\MigrationRepository;
use Doctrine\Migrations\Migrator as DBALMigration;
use Doctrine\Migrations\Version\Executor;
use Doctrine\Migrations\Version\Factory;
use LaravelDoctrine\Migrations\Configuration\Configuration;
use LaravelDoctrine\Migrations\Exceptions\ExecutedUnavailableMigrationsException;
use LaravelDoctrine\Migrations\Exceptions\MigrationVersionException;
Expand Down Expand Up @@ -44,7 +47,10 @@ public function __construct(Configuration $configuration, $version = 'latest')
*/
protected function makeMigration(Configuration $configuration)
{
return $this->migration = new DBALMigration($configuration);
$repository = $configuration->getDependencyFactory()->getMigrationRepository();
$outputWriter = $configuration->getOutputWriter();
$stopwatch = $configuration->getDependencyFactory()->getStopwatch();
return $this->migration = new DBALMigration($configuration, $repository, $outputWriter, $stopwatch);
}

/**
Expand Down
40 changes: 29 additions & 11 deletions src/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace LaravelDoctrine\Migrations;

use Doctrine\DBAL\Migrations\Version;
use Doctrine\Migrations\Exception\MigrationException;
use Doctrine\Migrations\MigratorConfiguration;
use Doctrine\Migrations\Version\Version;

class Migrator
{
Expand All @@ -11,20 +13,20 @@ class Migrator
*/
protected $notes = [];

/**
* @param Migration $migration
* @param bool|false $dryRun
* @param bool|false $timeQueries
* @param bool|false $allowNoMigration
*/
/**
* @param Migration $migration
* @param bool|false $dryRun
* @param bool|false $timeQueries
* @param bool|false $allowNoMigration
* @throws MigrationException
*/
public function migrate(Migration $migration, $dryRun = false, $timeQueries = false, bool $allowNoMigration = false)
{
$migration->getMigration()->setNoMigrationException($allowNoMigration);
$configuration = $this->setConfiguration($dryRun, $timeQueries, $allowNoMigration);

$sql = $migration->getMigration()->migrate(
$migration->getVersion(),
$dryRun,
$timeQueries
$configuration
);

$this->writeNotes($migration, $timeQueries, $sql);
Expand All @@ -38,7 +40,8 @@ public function migrate(Migration $migration, $dryRun = false, $timeQueries = fa
*/
public function execute(Version $version, $direction, $dryRun = false, $timeQueries = false)
{
$version->execute($direction, $dryRun, $timeQueries);
$configuration = $this->setConfiguration($dryRun, $timeQueries);
$version->execute($direction, $configuration);

$verb = $direction === 'down' ? 'Rolled back' : 'Migrated';

Expand Down Expand Up @@ -119,4 +122,19 @@ protected function note($versionName, Version $version, $timeQueries = false, $v

$this->notes[] = $msg;
}

/**
* @param bool $dryRun
* @param bool $timeQueries
* @param bool $allowNoMigrations
* @return MigratorConfiguration
*/
private function setConfiguration(bool $dryRun = false, bool $timeQueries = false, bool $allowNoMigrations = false)
{
$configuration = new MigratorConfiguration();
$configuration->setDryRun($dryRun);
$configuration->setTimeAllQueries($timeQueries);
$configuration->setNoMigrationException($allowNoMigrations);
return $configuration;
}
}
7 changes: 4 additions & 3 deletions src/Naming/DefaultNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace LaravelDoctrine\Migrations\Naming;

use Doctrine\DBAL\Migrations\Finder\MigrationFinderInterface;
use Doctrine\DBAL\Migrations\Finder\RecursiveRegexFinder;
use Doctrine\Migrations\Finder\MigrationDeepFinder;
use Doctrine\Migrations\Finder\MigrationFinder;
use Doctrine\Migrations\Finder\RecursiveRegexFinder;

class DefaultNamingStrategy implements NamingStrategy
{
Expand All @@ -30,7 +31,7 @@ public function getClassName($version = null)
}

/**
* @return MigrationFinderInterface
* @return MigrationDeepFinder
*/
public function getFinder()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Naming/NamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace LaravelDoctrine\Migrations\Naming;

use Doctrine\DBAL\Migrations\Finder\MigrationFinderInterface;
use Doctrine\Migrations\Finder\MigrationFinder;

interface NamingStrategy
{
Expand All @@ -21,7 +21,7 @@ public function getFilename($version = null);
public function getClassName($version = null);

/**
* @return MigrationFinderInterface
* @return MigrationFinder
*/
public function getFinder();
}
44 changes: 24 additions & 20 deletions src/Output/SqlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

namespace LaravelDoctrine\Migrations\Output;

use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\Schema;
use LaravelDoctrine\Migrations\Configuration\Configuration;

class SqlBuilder
{
/**
* @param Configuration $configuration
* @param Schema $from
* @param Schema $to
*
* @return string
*/
/**
* @param Configuration $configuration
* @param Schema $from
* @param Schema $to
*
* @return string
* @throws DBALException
*/
public function up(Configuration $configuration, Schema $from, Schema $to)
{
return $this->build(
Expand All @@ -22,13 +24,14 @@ public function up(Configuration $configuration, Schema $from, Schema $to)
);
}

/**
* @param Configuration $configuration
* @param Schema $from
* @param Schema $to
*
* @return string
*/
/**
* @param Configuration $configuration
* @param Schema $from
* @param Schema $to
*
* @return string
* @throws DBALException
*/
public function down(Configuration $configuration, Schema $from, Schema $to)
{
return $this->build(
Expand All @@ -37,12 +40,13 @@ public function down(Configuration $configuration, Schema $from, Schema $to)
);
}

/**
* @param Configuration $configuration
* @param array $queries
*
* @return string
*/
/**
* @param Configuration $configuration
* @param array $queries
*
* @return string
* @throws DBALException
*/
public function build(Configuration $configuration, array $queries = [])
{
$platform = $configuration->getConnection()->getDatabasePlatform()->getName();
Expand Down
4 changes: 2 additions & 2 deletions src/Output/stubs/blank.stub
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ class <class> extends AbstractMigration
/**
* @param Schema $schema
*/
public function up(Schema $schema)
public function up(Schema $schema): void
{
<up>
}

/**
* @param Schema $schema
*/
public function down(Schema $schema)
public function down(Schema $schema): void
{
<down>
}
Expand Down
4 changes: 2 additions & 2 deletions src/Output/stubs/create.stub
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class <class> extends AbstractMigration
/**
* @param Schema $schema
*/
public function up(Schema $schema)
public function up(Schema $schema): void
{
(new Builder($schema))->create('<table>', function (Table $table) {
$table->increments('id');
Expand All @@ -23,7 +23,7 @@ class <class> extends AbstractMigration
/**
* @param Schema $schema
*/
public function down(Schema $schema)
public function down(Schema $schema): void
{
(new Builder($schema))->drop('<table>');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Output/stubs/update.stub
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class <class> extends AbstractMigration
/**
* @param Schema $schema
*/
public function up(Schema $schema)
public function up(Schema $schema): void
{
(new Builder($schema))->table('<table>', function (Table $table) {
//
Expand All @@ -22,7 +22,7 @@ class <class> extends AbstractMigration
/**
* @param Schema $schema
*/
public function down(Schema $schema)
public function down(Schema $schema): void
{
(new Builder($schema))->table('<table>', function (Table $table) {
//
Expand Down
Loading

0 comments on commit fa9aac7

Please sign in to comment.