From 66ff620a56336635399ebfed6c5a33ebf605413c Mon Sep 17 00:00:00 2001 From: yarik Date: Fri, 9 Dec 2016 15:50:32 +0200 Subject: [PATCH] Video + fixes --- migrations/m161101_142334_blog_article.php | 31 +++++++++++++++++++++++++++++++ migrations/m161101_142752_blog_article_lang.php | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ migrations/m161101_143033_blog_category.php | 29 +++++++++++++++++++++++++++++ migrations/m161101_143259_blog_category_lang.php | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ migrations/m161101_143541_blog_article_to_category.php | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ migrations/m161101_143734_blog_tag.php | 24 ++++++++++++++++++++++++ migrations/m161101_143939_blog_tag_lang.php | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ migrations/m161101_144140_blog_article_to_tag.php | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ migrations/m161101_144312_blog_article_to_article.php | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ migrations/m161101_144434_blog_article_to_product.php | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 564 insertions(+), 0 deletions(-) create mode 100755 migrations/m161101_142334_blog_article.php create mode 100755 migrations/m161101_142752_blog_article_lang.php create mode 100755 migrations/m161101_143033_blog_category.php create mode 100755 migrations/m161101_143259_blog_category_lang.php create mode 100755 migrations/m161101_143541_blog_article_to_category.php create mode 100755 migrations/m161101_143734_blog_tag.php create mode 100755 migrations/m161101_143939_blog_tag_lang.php create mode 100755 migrations/m161101_144140_blog_article_to_tag.php create mode 100755 migrations/m161101_144312_blog_article_to_article.php create mode 100755 migrations/m161101_144434_blog_article_to_product.php diff --git a/migrations/m161101_142334_blog_article.php b/migrations/m161101_142334_blog_article.php new file mode 100755 index 0000000..235e2cb --- /dev/null +++ b/migrations/m161101_142334_blog_article.php @@ -0,0 +1,31 @@ +createTable( + 'blog_article', + [ + 'id' => $this->primaryKey(), + 'image' => $this->string(255), + 'created_at' => $this->integer(), + 'updated_at' => $this->integer(), + 'deleted_at' => $this->integer(), + 'sort' => $this->integer(), + 'status' => $this->boolean(), + 'author_id' => $this->integer(), + ] + ); + } + + public function down() + { + $this->dropTable('blog_article'); + } +} diff --git a/migrations/m161101_142752_blog_article_lang.php b/migrations/m161101_142752_blog_article_lang.php new file mode 100755 index 0000000..2fabca7 --- /dev/null +++ b/migrations/m161101_142752_blog_article_lang.php @@ -0,0 +1,83 @@ +createTable( + 'blog_article_lang', + [ + 'id' => $this->primaryKey(), + 'blog_article_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'title' => $this->string(255), + 'body' => $this->text(), + 'body_preview' => $this->text(), + 'alias' => $this->string(255), + 'meta_title' => $this->string(255), + 'meta_description' => $this->string(255), + 'h1' => $this->string(255), + 'seo_text' => $this->string(255), + ] + ); + + /** + * Creating indexes for unique fields (field pairs) + */ + $this->createIndex( + 'blog_article_lang_uk', + 'blog_article_lang', + [ + 'blog_article_id', + 'language_id', + ], + true + ); + + $this->createIndex( + 'blog_article_alias_uk', + 'blog_article_lang', + 'alias', + true + ); + + /** + * Add foreign keys in blog_articles and language tables + */ + $this->addForeignKey( + 'blog_article_fk', + 'blog_article_lang', + 'blog_article_id', + 'blog_article', + 'id', + 'CASCADE', + 'CASCADE' + ); + + $this->addForeignKey( + 'blog_article_lang_fk', + 'blog_article_lang', + 'language_id', + 'language', + 'id', + 'RESTRICT', + 'CASCADE' + ); + } + + public function down() + { + $this->dropForeignKey('blog_article_lang_fk', 'blog_article_lang'); + $this->dropForeignKey('blog_article_fk', 'blog_article_lang'); + $this->dropIndex('blog_article_alias_uk', 'blog_article_lang'); + $this->dropIndex('blog_article_lang_uk', 'blog_article_lang'); + $this->dropTable('blog_article_lang'); + } +} diff --git a/migrations/m161101_143033_blog_category.php b/migrations/m161101_143033_blog_category.php new file mode 100755 index 0000000..e2bfe5f --- /dev/null +++ b/migrations/m161101_143033_blog_category.php @@ -0,0 +1,29 @@ +createTable( + 'blog_category', + [ + 'id' => $this->primaryKey(), + 'sort' => $this->integer(), + 'image' => $this->string(255), + 'parent_id' => $this->integer() + ->defaultValue(0), + 'status' => $this->boolean(), + ] + ); + } + + public function down() + { + $this->dropTable('blog_category'); + } +} diff --git a/migrations/m161101_143259_blog_category_lang.php b/migrations/m161101_143259_blog_category_lang.php new file mode 100755 index 0000000..72f2e14 --- /dev/null +++ b/migrations/m161101_143259_blog_category_lang.php @@ -0,0 +1,82 @@ +createTable( + 'blog_category_lang', + [ + 'id' => $this->primaryKey(), + 'blog_category_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'title' => $this->string(255), + 'alias' => $this->string(255), + 'description' => $this->text(), + 'meta_title' => $this->string(255), + 'meta_description' => $this->string(255), + 'h1' => $this->string(255), + 'seo_text' => $this->string(255), + ] + ); + + /** + * Create unique indexes for language and alias + */ + $this->createIndex( + 'blog_category_lang_uk', + 'blog_category_lang', + [ + 'blog_category_id', + 'language_id', + ], + true + ); + + $this->createIndex( + 'blog_category_alias_uk', + 'blog_category_lang', + 'alias', + true + ); + + /** + * Add foreign keys for language tables + */ + $this->addForeignKey( + 'blog_category_fk', + 'blog_category_lang', + 'blog_category_id', + 'blog_category', + 'id', + 'CASCADE', + 'CASCADE' + ); + + $this->addForeignKey( + 'blog_category_lang_fk', + 'blog_category_lang', + 'language_id', + 'language', + 'id', + 'RESTRICT', + 'CASCADE' + ); + } + + public function down() + { + $this->dropForeignKey('blog_category_lang_fk', 'blog_category_lang'); + $this->dropForeignKey('blog_category_fk', 'blog_category_lang'); + $this->dropIndex('blog_category_alias_uk', 'blog_category_lang'); + $this->dropIndex('blog_category_lang_uk', 'blog_category_lang'); + $this->dropTable('blog_category_lang'); + } +} diff --git a/migrations/m161101_143541_blog_article_to_category.php b/migrations/m161101_143541_blog_article_to_category.php new file mode 100755 index 0000000..fd21784 --- /dev/null +++ b/migrations/m161101_143541_blog_article_to_category.php @@ -0,0 +1,64 @@ +createTable( + 'blog_article_to_category', + [ + 'id' => $this->primaryKey(), + 'blog_article_id' => $this->integer() + ->notNull(), + 'blog_category_id' => $this->integer() + ->notNull(), + ] + ); + + /** + * Add foreign keys and indexes for junction table + */ + $this->createIndex( + 'blog_article_to_category_uk', + 'blog_article_to_category', + [ + 'blog_article_id', + 'blog_category_id', + ], + true + ); + + $this->addForeignKey( + 'blog_article_to_category_art_fk', + 'blog_article_to_category', + 'blog_article_id', + 'blog_article', + 'id', + 'CASCADE', + 'CASCADE' + ); + + $this->addForeignKey( + 'blog_article_to_category_cat_fk', + 'blog_article_to_category', + 'blog_category_id', + 'blog_category', + 'id', + 'CASCADE', + 'CASCADE' + ); + } + + public function down() + { + $this->dropForeignKey('blog_article_to_category_cat_fk', 'blog_article_to_category'); + $this->dropForeignKey('blog_article_to_category_art_fk', 'blog_article_to_category'); + $this->dropIndex('blog_article_to_category_uk', 'blog_article_to_category'); + $this->dropTable('blog_article_to_category'); + } +} diff --git a/migrations/m161101_143734_blog_tag.php b/migrations/m161101_143734_blog_tag.php new file mode 100755 index 0000000..292ee38 --- /dev/null +++ b/migrations/m161101_143734_blog_tag.php @@ -0,0 +1,24 @@ +createTable( + 'blog_tag', + [ + 'id' => $this->primaryKey(), + ] + ); + } + + public function down() + { + $this->dropTable('blog_tag'); + } +} diff --git a/migrations/m161101_143939_blog_tag_lang.php b/migrations/m161101_143939_blog_tag_lang.php new file mode 100755 index 0000000..a98a4d5 --- /dev/null +++ b/migrations/m161101_143939_blog_tag_lang.php @@ -0,0 +1,65 @@ +createTable( + 'blog_tag_lang', + [ + 'id' => $this->primaryKey(), + 'blog_tag_id' => $this->integer() + ->notNull(), + 'language_id' => $this->integer() + ->notNull(), + 'label' => $this->string(255), + ] + ); + + /** + * Creating indexes and foreign keys for language table + */ + $this->createIndex( + 'blog_tag_lang_uk', + 'blog_tag_lang', + [ + 'blog_tag_id', + 'language_id', + ], + true + ); + + $this->addForeignKey( + 'blog_tag_lang_fk', + 'blog_tag_lang', + 'language_id', + 'language', + 'id', + 'RESTRICT', + 'CASCADE' + ); + + $this->addForeignKey( + 'blog_tag_fk', + 'blog_tag_lang', + 'blog_tag_id', + 'blog_tag', + 'id', + 'CASCADE', + 'CASCADE' + ); + } + + public function down() + { + $this->dropForeignKey('blog_tag_fk', 'blog_tag_lang'); + $this->dropForeignKey('blog_tag_lang_fk', 'blog_tag_lang'); + $this->dropIndex('blog_tag_lang_uk', 'blog_tag_lang'); + $this->dropTable('blog_tag_lang'); + } +} diff --git a/migrations/m161101_144140_blog_article_to_tag.php b/migrations/m161101_144140_blog_article_to_tag.php new file mode 100755 index 0000000..aed42ad --- /dev/null +++ b/migrations/m161101_144140_blog_article_to_tag.php @@ -0,0 +1,64 @@ +createTable( + 'blog_article_to_tag', + [ + 'id' => $this->primaryKey(), + 'blog_article_id' => $this->integer() + ->notNull(), + 'blog_tag_id' => $this->integer() + ->notNull(), + ] + ); + + /** + * Create indexes and foreign keys for junction table + */ + $this->createIndex( + 'blog_article_to_tag_uk', + 'blog_article_to_tag', + [ + 'blog_article_id', + 'blog_tag_id', + ], + true + ); + + $this->addForeignKey( + 'blog_article_to_tag_tag_fk', + 'blog_article_to_tag', + 'blog_tag_id', + 'blog_tag', + 'id', + 'CASCADE', + 'CASCADE' + ); + + $this->addForeignKey( + 'blog_article_to_tag_art_fk', + 'blog_article_to_tag', + 'blog_article_id', + 'blog_article', + 'id', + 'CASCADE', + 'CASCADE' + ); + } + + public function down() + { + $this->dropForeignKey('blog_article_to_tag_art_fk', 'blog_article_to_tag'); + $this->dropForeignKey('blog_article_to_tag_tag_fk', 'blog_article_to_tag'); + $this->dropIndex('blog_article_to_tag_uk', 'blog_article_to_tag'); + $this->dropTable('blog_article_to_tag'); + } +} diff --git a/migrations/m161101_144312_blog_article_to_article.php b/migrations/m161101_144312_blog_article_to_article.php new file mode 100755 index 0000000..a4f42b4 --- /dev/null +++ b/migrations/m161101_144312_blog_article_to_article.php @@ -0,0 +1,61 @@ +createTable( + 'blog_article_to_article', + [ + 'id' => $this->primaryKey(), + 'blog_article_id' => $this->integer() + ->notNull(), + 'related_blog_article_id' => $this->integer() + ->notNull(), + ] + ); + + $this->createIndex( + 'blog_article_to_article_uk', + 'blog_article_to_article', + [ + 'blog_article_id', + 'related_blog_article_id', + ], + true + ); + + $this->addForeignKey( + 'blog_article_to_article_art_fk', + 'blog_article_to_article', + 'blog_article_id', + 'blog_article', + 'id', + 'CASCADE', + 'CASCADE' + ); + + $this->addForeignKey( + 'blog_article_to_article_rel_fk', + 'blog_article_to_article', + 'related_blog_article_id', + 'blog_article', + 'id', + 'CASCADE', + 'CASCADE' + ); + } + + public function down() + { + $this->dropForeignKey('blog_article_to_article_rel_fk', 'blog_article_to_article'); + $this->dropForeignKey('blog_article_to_article_art_fk', 'blog_article_to_article'); + $this->dropIndex('blog_article_to_article_uk', 'blog_article_to_article'); + $this->dropTable('blog_article_to_article'); + } +} diff --git a/migrations/m161101_144434_blog_article_to_product.php b/migrations/m161101_144434_blog_article_to_product.php new file mode 100755 index 0000000..a47bc41 --- /dev/null +++ b/migrations/m161101_144434_blog_article_to_product.php @@ -0,0 +1,61 @@ +createTable( + 'blog_article_to_product', + [ + 'id' => $this->primaryKey(), + 'blog_article_id' => $this->integer() + ->notNull(), + 'product_id' => $this->integer() + ->notNull(), + ] + ); + + $this->createIndex( + 'blog_article_to_product_uk', + 'blog_article_to_product', + [ + 'blog_article_id', + 'product_id', + ], + true + ); + + $this->addForeignKey( + 'blog_article_to_product_art_fk', + 'blog_article_to_product', + 'blog_article_id', + 'blog_article', + 'id', + 'CASCADE', + 'CASCADE' + ); + + $this->addForeignKey( + 'blog_article_to_product_prod_fk', + 'blog_article_to_product', + 'product_id', + 'product', + 'id', + 'CASCADE', + 'CASCADE' + ); + } + + public function down() + { + $this->dropForeignKey('blog_article_to_product_prod_fk', 'blog_article_to_product'); + $this->dropForeignKey('blog_article_to_product_art_fk', 'blog_article_to_product'); + $this->dropIndex('blog_article_to_product_uk', 'blog_article_to_product'); + $this->dropTable('blog_article_to_product'); + } +} -- libgit2 0.21.4