From 3740e6bd233b6e0db8b3e2714dfa894b373be353 Mon Sep 17 00:00:00 2001 From: cornernote Date: Wed, 12 Aug 2015 15:52:48 +0930 Subject: [PATCH] redo database --- src/commands/PackageController.php | 32 ++++++++++++++++ .../m150809_000001_update_package.php | 19 ---------- .../m150810_000001_update_package.php | 19 ---------- .../m150810_000002_update_package.php | 25 ------------- .../m150810_000003_update_package.php | 37 ------------------- .../m150811_000001_update_package.php | 19 ---------- ....php => m150812_000001_create_package.php} | 13 +++++-- 7 files changed, 41 insertions(+), 123 deletions(-) delete mode 100644 src/migrations/m150809_000001_update_package.php delete mode 100644 src/migrations/m150810_000001_update_package.php delete mode 100644 src/migrations/m150810_000002_update_package.php delete mode 100644 src/migrations/m150810_000003_update_package.php delete mode 100644 src/migrations/m150811_000001_update_package.php rename src/migrations/{m150808_000001_create_package.php => m150812_000001_create_package.php} (72%) diff --git a/src/commands/PackageController.php b/src/commands/PackageController.php index 156b0f6..44b0360 100644 --- a/src/commands/PackageController.php +++ b/src/commands/PackageController.php @@ -47,6 +47,38 @@ class PackageController extends Controller } } + /** + * + */ + public function actionRestore() + { + $file = 'https://gist.githubusercontent.com/cornernote/d18f9048b230a8075be1/raw/bc76dc90013422053642865111ff8a5553fa6dd5/packages.json'; + $this->stdout('Importing restore from ' . $file . "\n"); + $data = json_decode(file_get_contents($file), true); + $count = count($data); + foreach ($data as $k => $row) { + $this->stdout('[' . ($k + 1) . '/' . $count . '] ', Console::FG_GREY); + $this->stdout($row['name'] . ' ' . $row['url'] . ': '); + $package = Package::find()->where(['name' => $row['name']])->one(); + if (!$package) { + $package = new Package(); + $package->name = $row['name']; + } + if (!$package->url) { + $package->url = $row['url']; + } + if ($package->save()) { + $this->stdout('Saved!' . "\n", Console::FG_GREEN); + } else { + $this->stdout('Errors', Console::FG_RED); + foreach ($package->errors as $attribute => $errors) { + $this->stdout(' -- ' . $attribute . ' ' . implode(', ', $errors), Console::FG_RED); + } + $this->stdout("\n"); + } + } + } + /** * */ diff --git a/src/migrations/m150809_000001_update_package.php b/src/migrations/m150809_000001_update_package.php deleted file mode 100644 index 8289397..0000000 --- a/src/migrations/m150809_000001_update_package.php +++ /dev/null @@ -1,19 +0,0 @@ -addColumn(self::TABLE, 'readme', Schema::TYPE_TEXT); - } - - public function down() - { - $this->dropColumn(self::TABLE, 'readme'); - } -} \ No newline at end of file diff --git a/src/migrations/m150810_000001_update_package.php b/src/migrations/m150810_000001_update_package.php deleted file mode 100644 index e6a80ab..0000000 --- a/src/migrations/m150810_000001_update_package.php +++ /dev/null @@ -1,19 +0,0 @@ -addColumn(self::TABLE, 'readme_format', Schema::TYPE_STRING . '(8)'); - } - - public function down() - { - $this->dropColumn(self::TABLE, 'readme_format'); - } -} \ No newline at end of file diff --git a/src/migrations/m150810_000002_update_package.php b/src/migrations/m150810_000002_update_package.php deleted file mode 100644 index 5e3da17..0000000 --- a/src/migrations/m150810_000002_update_package.php +++ /dev/null @@ -1,25 +0,0 @@ -dropColumn(self::TABLE, 'screenshot'); - $this->addColumn(self::TABLE, 'screenshots', Schema::TYPE_TEXT); - $this->addColumn(self::TABLE, 'authors', Schema::TYPE_TEXT); - $this->addColumn(self::TABLE, 'license', Schema::TYPE_TEXT); - } - - public function down() - { - $this->addColumn(self::TABLE, 'screenshot', Schema::TYPE_STRING); - $this->dropColumn(self::TABLE, 'authors'); - $this->dropColumn(self::TABLE, 'screenshots'); - $this->dropColumn(self::TABLE, 'license'); - } -} \ No newline at end of file diff --git a/src/migrations/m150810_000003_update_package.php b/src/migrations/m150810_000003_update_package.php deleted file mode 100644 index 0ee2681..0000000 --- a/src/migrations/m150810_000003_update_package.php +++ /dev/null @@ -1,37 +0,0 @@ -dropColumn(self::TABLE, 'bower'); - $this->dropColumn(self::TABLE, 'readme'); - $this->dropColumn(self::TABLE, 'screenshots'); - $this->dropColumn(self::TABLE, 'authors'); - $this->dropColumn(self::TABLE, 'license'); - $this->addColumn(self::TABLE, 'bower', Schema::TYPE_BINARY); - $this->addColumn(self::TABLE, 'readme', Schema::TYPE_BINARY); - $this->addColumn(self::TABLE, 'screenshots', Schema::TYPE_BINARY); - $this->addColumn(self::TABLE, 'authors', Schema::TYPE_BINARY); - $this->addColumn(self::TABLE, 'license', Schema::TYPE_BINARY); - } - - public function down() - { - $this->dropColumn(self::TABLE, 'bower'); - $this->dropColumn(self::TABLE, 'readme'); - $this->dropColumn(self::TABLE, 'screenshots'); - $this->dropColumn(self::TABLE, 'authors'); - $this->dropColumn(self::TABLE, 'license'); - $this->addColumn(self::TABLE, 'bower', Schema::TYPE_TEXT); - $this->addColumn(self::TABLE, 'readme', Schema::TYPE_TEXT); - $this->addColumn(self::TABLE, 'screenshots', Schema::TYPE_TEXT); - $this->addColumn(self::TABLE, 'authors', Schema::TYPE_TEXT); - $this->addColumn(self::TABLE, 'license', Schema::TYPE_TEXT); - } -} \ No newline at end of file diff --git a/src/migrations/m150811_000001_update_package.php b/src/migrations/m150811_000001_update_package.php deleted file mode 100644 index 5447063..0000000 --- a/src/migrations/m150811_000001_update_package.php +++ /dev/null @@ -1,19 +0,0 @@ -addColumn(self::TABLE, 'forum', Schema::TYPE_STRING . '(255)'); - } - - public function down() - { - $this->dropColumn(self::TABLE, 'forum'); - } -} \ No newline at end of file diff --git a/src/migrations/m150808_000001_create_package.php b/src/migrations/m150812_000001_create_package.php similarity index 72% rename from src/migrations/m150808_000001_create_package.php rename to src/migrations/m150812_000001_create_package.php index c3724b2..c839165 100644 --- a/src/migrations/m150808_000001_create_package.php +++ b/src/migrations/m150812_000001_create_package.php @@ -3,22 +3,28 @@ use yii\db\Migration; use yii\db\Schema; -class m150808_000001_create_package extends Migration +class m150812_000001_create_package extends Migration { const TABLE = '{{%package}}'; public function up() { + $this->dropTable(self::TABLE); $this->createTable(self::TABLE, [ 'id' => Schema::TYPE_PK, 'name' => Schema::TYPE_STRING . '(50) NOT NULL', 'url' => Schema::TYPE_STRING . '(255) NOT NULL', 'hits' => Schema::TYPE_INTEGER . ' NOT NULL DEFAULT 0', - 'bower' => Schema::TYPE_TEXT, + 'bower' => Schema::TYPE_BINARY, + 'readme' => Schema::TYPE_BINARY, + 'readme_format' => Schema::TYPE_STRING . '(8)', 'homepage' => Schema::TYPE_STRING . '(255)', + 'forum' => Schema::TYPE_STRING . '(255)', 'description' => Schema::TYPE_STRING . '(140)', 'keywords' => Schema::TYPE_STRING . '(255)', - 'screenshot' => Schema::TYPE_STRING . '(255)', + 'screenshots' => Schema::TYPE_BINARY, + 'authors' => Schema::TYPE_BINARY, + 'license' => Schema::TYPE_BINARY, 'created_at' => Schema::TYPE_DATETIME . ' NOT NULL', 'updated_at' => Schema::TYPE_DATETIME . ' NOT NULL', ], ($this->db->driverName === 'mysql' ? 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB' : null)); @@ -29,6 +35,5 @@ class m150808_000001_create_package extends Migration public function down() { - $this->dropTable(self::TABLE); } } \ No newline at end of file