From 5d9d1b1cb5c4c301e7c60f58225e9a85168eafbe Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 7 Jun 2017 13:51:54 +0200 Subject: [PATCH] Allow to check the schema in pre and post as well Signed-off-by: Joas Schilling --- core/Command/Db/Migrations/GenerateCommand.php | 13 +++++++++---- lib/private/DB/MigrationService.php | 10 +++++++--- lib/public/Migration/IMigrationStep.php | 13 +++++++++---- lib/public/Migration/SimpleMigrationStep.php | 13 +++++++++---- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/core/Command/Db/Migrations/GenerateCommand.php b/core/Command/Db/Migrations/GenerateCommand.php index 92d8e15b66..b6e1a17d68 100644 --- a/core/Command/Db/Migrations/GenerateCommand.php +++ b/core/Command/Db/Migrations/GenerateCommand.php @@ -51,26 +51,31 @@ class extends SimpleMigrationStep { /** * @param IOutput $output + * @param \Closure $schemaClosure The `\Closure` returns a `Schema` + * @param array $options * @since 13.0.0 */ - public function preSchemaChange(IOutput $output) { + public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { } /** - * @param \Closure $schema The `\Closure` returns a `Schema` + * @param IOutput $output + * @param \Closure $schemaClosure The `\Closure` returns a `Schema` * @param array $options * @return null|Schema * @since 13.0.0 */ - public function changeSchema(\Closure $schema, array $options) { + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { return null; } /** * @param IOutput $output + * @param \Closure $schemaClosure The `\Closure` returns a `Schema` + * @param array $options * @since 13.0.0 */ - public function postSchemaChange(IOutput $output) { + public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { } } '; diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php index 9c37a4ffa7..912166988c 100644 --- a/lib/private/DB/MigrationService.php +++ b/lib/private/DB/MigrationService.php @@ -390,9 +390,11 @@ class MigrationService { throw new \InvalidArgumentException('Not a valid migration'); } - $instance->preSchemaChange($this->output); + $instance->preSchemaChange($this->output, function() { + return $this->connection->createSchema(); + }, ['tablePrefix' => $this->connection->getPrefix()]); - $toSchema = $instance->changeSchema(function() { + $toSchema = $instance->changeSchema($this->output, function() { return $this->connection->createSchema(); }, ['tablePrefix' => $this->connection->getPrefix()]); @@ -400,7 +402,9 @@ class MigrationService { $this->connection->migrateToSchema($toSchema); } - $instance->postSchemaChange($this->output); + $instance->postSchemaChange($this->output, function() { + return $this->connection->createSchema(); + }, ['tablePrefix' => $this->connection->getPrefix()]); $this->markAsExecuted($version); } diff --git a/lib/public/Migration/IMigrationStep.php b/lib/public/Migration/IMigrationStep.php index aeb35bc839..49bb236ab7 100644 --- a/lib/public/Migration/IMigrationStep.php +++ b/lib/public/Migration/IMigrationStep.php @@ -30,21 +30,26 @@ interface IMigrationStep { /** * @param IOutput $output + * @param \Closure $schemaClosure The `\Closure` returns a `Schema` + * @param array $options * @since 13.0.0 */ - public function preSchemaChange(IOutput $output); + public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options); /** - * @param \Closure $schema The `\Closure` returns a `Schema` + * @param IOutput $output + * @param \Closure $schemaClosure The `\Closure` returns a `Schema` * @param array $options * @return null|Schema * @since 13.0.0 */ - public function changeSchema(\Closure $schema, array $options); + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options); /** * @param IOutput $output + * @param \Closure $schemaClosure The `\Closure` returns a `Schema` + * @param array $options * @since 13.0.0 */ - public function postSchemaChange(IOutput $output); + public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options); } diff --git a/lib/public/Migration/SimpleMigrationStep.php b/lib/public/Migration/SimpleMigrationStep.php index 681bd5c6b5..df4ae4e2eb 100644 --- a/lib/public/Migration/SimpleMigrationStep.php +++ b/lib/public/Migration/SimpleMigrationStep.php @@ -30,25 +30,30 @@ abstract class SimpleMigrationStep implements IMigrationStep { /** * @param IOutput $output + * @param \Closure $schemaClosure The `\Closure` returns a `Schema` + * @param array $options * @since 13.0.0 */ - public function preSchemaChange(IOutput $output) { + public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { } /** - * @param \Closure $schema + * @param IOutput $output + * @param \Closure $schemaClosure The `\Closure` returns a `Schema` * @param array $options * @return null|Schema * @since 13.0.0 */ - public function changeSchema(\Closure $schema, array $options) { + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { return null; } /** * @param IOutput $output + * @param \Closure $schemaClosure The `\Closure` returns a `Schema` + * @param array $options * @since 13.0.0 */ - public function postSchemaChange(IOutput $output) { + public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { } }