Skip to content

Commit

Permalink
Fix migration
Browse files Browse the repository at this point in the history
  • Loading branch information
sjelfull committed Mar 6, 2019
1 parent 88eacc4 commit 90d6e01
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Reports extends Plugin
/**
* @var string
*/
public $schemaVersion = '1.0.1';
public $schemaVersion = '1.0.2';

// Public Methods
// =========================================================================
Expand Down
22 changes: 2 additions & 20 deletions src/migrations/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -225,5 +205,7 @@ protected function insertDefaultData()
protected function removeTables()
{
$this->dropTableIfExists(ReportsRecord::tableName());
$this->dropTableIfExists(TargetRecord::tableName());
$this->dropTableIfExists(ReportsTargetsRecord::tableName());
}
}
42 changes: 42 additions & 0 deletions src/migrations/m190306_140704_fix_double_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace superbig\reports\migrations;

use Craft;
use craft\db\Migration;
use craft\db\mysql\ColumnSchema;
use superbig\reports\records\ReportsTargetsRecord;

require_once __DIR__ . '/m190305_191905_add_targets_reports_relationship.php';

/**
* m190306_140704_fix_double_table migration.
*/
class m190306_140704_fix_double_table extends Migration
{
/**
* @inheritdoc
*/
public function safeUp()
{
$tableSchema = Craft::$app->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;
}
}

0 comments on commit 90d6e01

Please sign in to comment.