From 90d6e0153368c3e54e65b8994cb68ddf7bbb4697 Mon Sep 17 00:00:00 2001 From: Fred Carlsen Date: Wed, 6 Mar 2019 15:16:31 +0100 Subject: [PATCH] Fix migration --- CHANGELOG.md | 5 +++ composer.json | 2 +- src/Reports.php | 2 +- src/migrations/Install.php | 22 +--------- .../m190306_140704_fix_double_table.php | 42 +++++++++++++++++++ 5 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 src/migrations/m190306_140704_fix_double_table.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 636947c..64da9f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 1.0.3 - 2019-03-06 + +### Fixed +- Fixed double table creation in install migration that caused SQL errors. + ## 1.0.2 - 2019-03-06 ### Fixed diff --git a/composer.json b/composer.json index 0c2a170..a06bc42 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "superbig/craft-reports", "description": "Write reports with Twig.", "type": "craft-plugin", - "version": "1.0.2", + "version": "1.0.3", "keywords": [ "craft", "cms", diff --git a/src/Reports.php b/src/Reports.php index 99929ba..644103d 100644 --- a/src/Reports.php +++ b/src/Reports.php @@ -73,7 +73,7 @@ class Reports extends Plugin /** * @var string */ - public $schemaVersion = '1.0.1'; + public $schemaVersion = '1.0.2'; // Public Methods // ========================================================================= diff --git a/src/migrations/Install.php b/src/migrations/Install.php index 217c1c2..375335d 100644 --- a/src/migrations/Install.php +++ b/src/migrations/Install.php @@ -114,26 +114,6 @@ protected function createTables() ); } - $tableSchema = Craft::$app->db->schema->getTableSchema(ReportsTargetsRecord::tableName()); - if ($tableSchema === null) { - $tablesCreated = true; - $this->createTable( - ReportsTargetsRecord::tableName(), - [ - 'id' => $this->primaryKey(), - 'dateCreated' => $this->dateTime()->notNull(), - 'dateUpdated' => $this->dateTime()->notNull(), - 'uid' => $this->uid(), - 'siteId' => $this->integer()->notNull(), - 'name' => $this->string(255)->notNull()->defaultValue(''), - 'handle' => $this->string(255)->notNull()->defaultValue(''), - 'content' => $this->text(), - 'settings' => $this->text(), - 'dateLastRun' => $this->dateTime()->null(), - ] - ); - } - $tableSchema = Craft::$app->db->schema->getTableSchema(ReportsTargetsRecord::tableName()); if ($tableSchema === null) { $this->createTable( @@ -225,5 +205,7 @@ protected function insertDefaultData() protected function removeTables() { $this->dropTableIfExists(ReportsRecord::tableName()); + $this->dropTableIfExists(TargetRecord::tableName()); + $this->dropTableIfExists(ReportsTargetsRecord::tableName()); } } diff --git a/src/migrations/m190306_140704_fix_double_table.php b/src/migrations/m190306_140704_fix_double_table.php new file mode 100644 index 0000000..a02227f --- /dev/null +++ b/src/migrations/m190306_140704_fix_double_table.php @@ -0,0 +1,42 @@ +db->schema->getTableSchema(ReportsTargetsRecord::tableName()); + if ($tableSchema !== null) { + if (isset($tableSchema->columns['dateLastRun'])) { + $migration = new m190305_191905_add_targets_reports_relationship(); + + $this->dropTableIfExists(ReportsTargetsRecord::tableName()); + $migration->safeUp(); + } + } + } + + /** + * @inheritdoc + */ + public function safeDown() + { + echo "m190306_140704_fix_double_table cannot be reverted.\n"; + + return false; + } +}