Commit 66ff620a56336635399ebfed6c5a33ebf605413c
1 parent
5410d5a0
Video + fixes
Showing
10 changed files
with
564 additions
and
0 deletions
Show diff stats
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\db\Migration; | |
| 4 | + | |
| 5 | +class m161101_142334_blog_article extends Migration | |
| 6 | +{ | |
| 7 | + public function up() | |
| 8 | + { | |
| 9 | + /** | |
| 10 | + * Create main table with blog's articles | |
| 11 | + */ | |
| 12 | + $this->createTable( | |
| 13 | + 'blog_article', | |
| 14 | + [ | |
| 15 | + 'id' => $this->primaryKey(), | |
| 16 | + 'image' => $this->string(255), | |
| 17 | + 'created_at' => $this->integer(), | |
| 18 | + 'updated_at' => $this->integer(), | |
| 19 | + 'deleted_at' => $this->integer(), | |
| 20 | + 'sort' => $this->integer(), | |
| 21 | + 'status' => $this->boolean(), | |
| 22 | + 'author_id' => $this->integer(), | |
| 23 | + ] | |
| 24 | + ); | |
| 25 | + } | |
| 26 | + | |
| 27 | + public function down() | |
| 28 | + { | |
| 29 | + $this->dropTable('blog_article'); | |
| 30 | + } | |
| 31 | +} | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\db\Migration; | |
| 4 | + | |
| 5 | +class m161101_142752_blog_article_lang extends Migration | |
| 6 | +{ | |
| 7 | + public function up() | |
| 8 | + { | |
| 9 | + /** | |
| 10 | + * Create table with language fields of blog articles | |
| 11 | + */ | |
| 12 | + $this->createTable( | |
| 13 | + 'blog_article_lang', | |
| 14 | + [ | |
| 15 | + 'id' => $this->primaryKey(), | |
| 16 | + 'blog_article_id' => $this->integer() | |
| 17 | + ->notNull(), | |
| 18 | + 'language_id' => $this->integer() | |
| 19 | + ->notNull(), | |
| 20 | + 'title' => $this->string(255), | |
| 21 | + 'body' => $this->text(), | |
| 22 | + 'body_preview' => $this->text(), | |
| 23 | + 'alias' => $this->string(255), | |
| 24 | + 'meta_title' => $this->string(255), | |
| 25 | + 'meta_description' => $this->string(255), | |
| 26 | + 'h1' => $this->string(255), | |
| 27 | + 'seo_text' => $this->string(255), | |
| 28 | + ] | |
| 29 | + ); | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * Creating indexes for unique fields (field pairs) | |
| 33 | + */ | |
| 34 | + $this->createIndex( | |
| 35 | + 'blog_article_lang_uk', | |
| 36 | + 'blog_article_lang', | |
| 37 | + [ | |
| 38 | + 'blog_article_id', | |
| 39 | + 'language_id', | |
| 40 | + ], | |
| 41 | + true | |
| 42 | + ); | |
| 43 | + | |
| 44 | + $this->createIndex( | |
| 45 | + 'blog_article_alias_uk', | |
| 46 | + 'blog_article_lang', | |
| 47 | + 'alias', | |
| 48 | + true | |
| 49 | + ); | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * Add foreign keys in blog_articles and language tables | |
| 53 | + */ | |
| 54 | + $this->addForeignKey( | |
| 55 | + 'blog_article_fk', | |
| 56 | + 'blog_article_lang', | |
| 57 | + 'blog_article_id', | |
| 58 | + 'blog_article', | |
| 59 | + 'id', | |
| 60 | + 'CASCADE', | |
| 61 | + 'CASCADE' | |
| 62 | + ); | |
| 63 | + | |
| 64 | + $this->addForeignKey( | |
| 65 | + 'blog_article_lang_fk', | |
| 66 | + 'blog_article_lang', | |
| 67 | + 'language_id', | |
| 68 | + 'language', | |
| 69 | + 'id', | |
| 70 | + 'RESTRICT', | |
| 71 | + 'CASCADE' | |
| 72 | + ); | |
| 73 | + } | |
| 74 | + | |
| 75 | + public function down() | |
| 76 | + { | |
| 77 | + $this->dropForeignKey('blog_article_lang_fk', 'blog_article_lang'); | |
| 78 | + $this->dropForeignKey('blog_article_fk', 'blog_article_lang'); | |
| 79 | + $this->dropIndex('blog_article_alias_uk', 'blog_article_lang'); | |
| 80 | + $this->dropIndex('blog_article_lang_uk', 'blog_article_lang'); | |
| 81 | + $this->dropTable('blog_article_lang'); | |
| 82 | + } | |
| 83 | +} | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\db\Migration; | |
| 4 | + | |
| 5 | +class m161101_143033_blog_category extends Migration | |
| 6 | +{ | |
| 7 | + public function up() | |
| 8 | + { | |
| 9 | + /** | |
| 10 | + * Create table for blog's categories | |
| 11 | + */ | |
| 12 | + $this->createTable( | |
| 13 | + 'blog_category', | |
| 14 | + [ | |
| 15 | + 'id' => $this->primaryKey(), | |
| 16 | + 'sort' => $this->integer(), | |
| 17 | + 'image' => $this->string(255), | |
| 18 | + 'parent_id' => $this->integer() | |
| 19 | + ->defaultValue(0), | |
| 20 | + 'status' => $this->boolean(), | |
| 21 | + ] | |
| 22 | + ); | |
| 23 | + } | |
| 24 | + | |
| 25 | + public function down() | |
| 26 | + { | |
| 27 | + $this->dropTable('blog_category'); | |
| 28 | + } | |
| 29 | +} | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\db\Migration; | |
| 4 | + | |
| 5 | +class m161101_143259_blog_category_lang extends Migration | |
| 6 | +{ | |
| 7 | + public function up() | |
| 8 | + { | |
| 9 | + /** | |
| 10 | + * Table for category languages | |
| 11 | + */ | |
| 12 | + $this->createTable( | |
| 13 | + 'blog_category_lang', | |
| 14 | + [ | |
| 15 | + 'id' => $this->primaryKey(), | |
| 16 | + 'blog_category_id' => $this->integer() | |
| 17 | + ->notNull(), | |
| 18 | + 'language_id' => $this->integer() | |
| 19 | + ->notNull(), | |
| 20 | + 'title' => $this->string(255), | |
| 21 | + 'alias' => $this->string(255), | |
| 22 | + 'description' => $this->text(), | |
| 23 | + 'meta_title' => $this->string(255), | |
| 24 | + 'meta_description' => $this->string(255), | |
| 25 | + 'h1' => $this->string(255), | |
| 26 | + 'seo_text' => $this->string(255), | |
| 27 | + ] | |
| 28 | + ); | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * Create unique indexes for language and alias | |
| 32 | + */ | |
| 33 | + $this->createIndex( | |
| 34 | + 'blog_category_lang_uk', | |
| 35 | + 'blog_category_lang', | |
| 36 | + [ | |
| 37 | + 'blog_category_id', | |
| 38 | + 'language_id', | |
| 39 | + ], | |
| 40 | + true | |
| 41 | + ); | |
| 42 | + | |
| 43 | + $this->createIndex( | |
| 44 | + 'blog_category_alias_uk', | |
| 45 | + 'blog_category_lang', | |
| 46 | + 'alias', | |
| 47 | + true | |
| 48 | + ); | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * Add foreign keys for language tables | |
| 52 | + */ | |
| 53 | + $this->addForeignKey( | |
| 54 | + 'blog_category_fk', | |
| 55 | + 'blog_category_lang', | |
| 56 | + 'blog_category_id', | |
| 57 | + 'blog_category', | |
| 58 | + 'id', | |
| 59 | + 'CASCADE', | |
| 60 | + 'CASCADE' | |
| 61 | + ); | |
| 62 | + | |
| 63 | + $this->addForeignKey( | |
| 64 | + 'blog_category_lang_fk', | |
| 65 | + 'blog_category_lang', | |
| 66 | + 'language_id', | |
| 67 | + 'language', | |
| 68 | + 'id', | |
| 69 | + 'RESTRICT', | |
| 70 | + 'CASCADE' | |
| 71 | + ); | |
| 72 | + } | |
| 73 | + | |
| 74 | + public function down() | |
| 75 | + { | |
| 76 | + $this->dropForeignKey('blog_category_lang_fk', 'blog_category_lang'); | |
| 77 | + $this->dropForeignKey('blog_category_fk', 'blog_category_lang'); | |
| 78 | + $this->dropIndex('blog_category_alias_uk', 'blog_category_lang'); | |
| 79 | + $this->dropIndex('blog_category_lang_uk', 'blog_category_lang'); | |
| 80 | + $this->dropTable('blog_category_lang'); | |
| 81 | + } | |
| 82 | +} | ... | ... |
migrations/m161101_143541_blog_article_to_category.php
0 โ 100755
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\db\Migration; | |
| 4 | + | |
| 5 | +class m161101_143541_blog_article_to_category extends Migration | |
| 6 | +{ | |
| 7 | + public function up() | |
| 8 | + { | |
| 9 | + /** | |
| 10 | + * Create junction table to connect articles with categories | |
| 11 | + */ | |
| 12 | + $this->createTable( | |
| 13 | + 'blog_article_to_category', | |
| 14 | + [ | |
| 15 | + 'id' => $this->primaryKey(), | |
| 16 | + 'blog_article_id' => $this->integer() | |
| 17 | + ->notNull(), | |
| 18 | + 'blog_category_id' => $this->integer() | |
| 19 | + ->notNull(), | |
| 20 | + ] | |
| 21 | + ); | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * Add foreign keys and indexes for junction table | |
| 25 | + */ | |
| 26 | + $this->createIndex( | |
| 27 | + 'blog_article_to_category_uk', | |
| 28 | + 'blog_article_to_category', | |
| 29 | + [ | |
| 30 | + 'blog_article_id', | |
| 31 | + 'blog_category_id', | |
| 32 | + ], | |
| 33 | + true | |
| 34 | + ); | |
| 35 | + | |
| 36 | + $this->addForeignKey( | |
| 37 | + 'blog_article_to_category_art_fk', | |
| 38 | + 'blog_article_to_category', | |
| 39 | + 'blog_article_id', | |
| 40 | + 'blog_article', | |
| 41 | + 'id', | |
| 42 | + 'CASCADE', | |
| 43 | + 'CASCADE' | |
| 44 | + ); | |
| 45 | + | |
| 46 | + $this->addForeignKey( | |
| 47 | + 'blog_article_to_category_cat_fk', | |
| 48 | + 'blog_article_to_category', | |
| 49 | + 'blog_category_id', | |
| 50 | + 'blog_category', | |
| 51 | + 'id', | |
| 52 | + 'CASCADE', | |
| 53 | + 'CASCADE' | |
| 54 | + ); | |
| 55 | + } | |
| 56 | + | |
| 57 | + public function down() | |
| 58 | + { | |
| 59 | + $this->dropForeignKey('blog_article_to_category_cat_fk', 'blog_article_to_category'); | |
| 60 | + $this->dropForeignKey('blog_article_to_category_art_fk', 'blog_article_to_category'); | |
| 61 | + $this->dropIndex('blog_article_to_category_uk', 'blog_article_to_category'); | |
| 62 | + $this->dropTable('blog_article_to_category'); | |
| 63 | + } | |
| 64 | +} | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\db\Migration; | |
| 4 | + | |
| 5 | +class m161101_143734_blog_tag extends Migration | |
| 6 | +{ | |
| 7 | + public function up() | |
| 8 | + { | |
| 9 | + /** | |
| 10 | + * Create table for tags | |
| 11 | + */ | |
| 12 | + $this->createTable( | |
| 13 | + 'blog_tag', | |
| 14 | + [ | |
| 15 | + 'id' => $this->primaryKey(), | |
| 16 | + ] | |
| 17 | + ); | |
| 18 | + } | |
| 19 | + | |
| 20 | + public function down() | |
| 21 | + { | |
| 22 | + $this->dropTable('blog_tag'); | |
| 23 | + } | |
| 24 | +} | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\db\Migration; | |
| 4 | + | |
| 5 | +class m161101_143939_blog_tag_lang extends Migration | |
| 6 | +{ | |
| 7 | + public function up() | |
| 8 | + { | |
| 9 | + /** | |
| 10 | + * Tags can be in different languages | |
| 11 | + */ | |
| 12 | + $this->createTable( | |
| 13 | + 'blog_tag_lang', | |
| 14 | + [ | |
| 15 | + 'id' => $this->primaryKey(), | |
| 16 | + 'blog_tag_id' => $this->integer() | |
| 17 | + ->notNull(), | |
| 18 | + 'language_id' => $this->integer() | |
| 19 | + ->notNull(), | |
| 20 | + 'label' => $this->string(255), | |
| 21 | + ] | |
| 22 | + ); | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * Creating indexes and foreign keys for language table | |
| 26 | + */ | |
| 27 | + $this->createIndex( | |
| 28 | + 'blog_tag_lang_uk', | |
| 29 | + 'blog_tag_lang', | |
| 30 | + [ | |
| 31 | + 'blog_tag_id', | |
| 32 | + 'language_id', | |
| 33 | + ], | |
| 34 | + true | |
| 35 | + ); | |
| 36 | + | |
| 37 | + $this->addForeignKey( | |
| 38 | + 'blog_tag_lang_fk', | |
| 39 | + 'blog_tag_lang', | |
| 40 | + 'language_id', | |
| 41 | + 'language', | |
| 42 | + 'id', | |
| 43 | + 'RESTRICT', | |
| 44 | + 'CASCADE' | |
| 45 | + ); | |
| 46 | + | |
| 47 | + $this->addForeignKey( | |
| 48 | + 'blog_tag_fk', | |
| 49 | + 'blog_tag_lang', | |
| 50 | + 'blog_tag_id', | |
| 51 | + 'blog_tag', | |
| 52 | + 'id', | |
| 53 | + 'CASCADE', | |
| 54 | + 'CASCADE' | |
| 55 | + ); | |
| 56 | + } | |
| 57 | + | |
| 58 | + public function down() | |
| 59 | + { | |
| 60 | + $this->dropForeignKey('blog_tag_fk', 'blog_tag_lang'); | |
| 61 | + $this->dropForeignKey('blog_tag_lang_fk', 'blog_tag_lang'); | |
| 62 | + $this->dropIndex('blog_tag_lang_uk', 'blog_tag_lang'); | |
| 63 | + $this->dropTable('blog_tag_lang'); | |
| 64 | + } | |
| 65 | +} | ... | ... |
migrations/m161101_144140_blog_article_to_tag.php
0 โ 100755
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\db\Migration; | |
| 4 | + | |
| 5 | +class m161101_144140_blog_article_to_tag extends Migration | |
| 6 | +{ | |
| 7 | + public function up() | |
| 8 | + { | |
| 9 | + /** | |
| 10 | + * Create junction table to connect articles with tags | |
| 11 | + */ | |
| 12 | + $this->createTable( | |
| 13 | + 'blog_article_to_tag', | |
| 14 | + [ | |
| 15 | + 'id' => $this->primaryKey(), | |
| 16 | + 'blog_article_id' => $this->integer() | |
| 17 | + ->notNull(), | |
| 18 | + 'blog_tag_id' => $this->integer() | |
| 19 | + ->notNull(), | |
| 20 | + ] | |
| 21 | + ); | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * Create indexes and foreign keys for junction table | |
| 25 | + */ | |
| 26 | + $this->createIndex( | |
| 27 | + 'blog_article_to_tag_uk', | |
| 28 | + 'blog_article_to_tag', | |
| 29 | + [ | |
| 30 | + 'blog_article_id', | |
| 31 | + 'blog_tag_id', | |
| 32 | + ], | |
| 33 | + true | |
| 34 | + ); | |
| 35 | + | |
| 36 | + $this->addForeignKey( | |
| 37 | + 'blog_article_to_tag_tag_fk', | |
| 38 | + 'blog_article_to_tag', | |
| 39 | + 'blog_tag_id', | |
| 40 | + 'blog_tag', | |
| 41 | + 'id', | |
| 42 | + 'CASCADE', | |
| 43 | + 'CASCADE' | |
| 44 | + ); | |
| 45 | + | |
| 46 | + $this->addForeignKey( | |
| 47 | + 'blog_article_to_tag_art_fk', | |
| 48 | + 'blog_article_to_tag', | |
| 49 | + 'blog_article_id', | |
| 50 | + 'blog_article', | |
| 51 | + 'id', | |
| 52 | + 'CASCADE', | |
| 53 | + 'CASCADE' | |
| 54 | + ); | |
| 55 | + } | |
| 56 | + | |
| 57 | + public function down() | |
| 58 | + { | |
| 59 | + $this->dropForeignKey('blog_article_to_tag_art_fk', 'blog_article_to_tag'); | |
| 60 | + $this->dropForeignKey('blog_article_to_tag_tag_fk', 'blog_article_to_tag'); | |
| 61 | + $this->dropIndex('blog_article_to_tag_uk', 'blog_article_to_tag'); | |
| 62 | + $this->dropTable('blog_article_to_tag'); | |
| 63 | + } | |
| 64 | +} | ... | ... |
migrations/m161101_144312_blog_article_to_article.php
0 โ 100755
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\db\Migration; | |
| 4 | + | |
| 5 | +class m161101_144312_blog_article_to_article extends Migration | |
| 6 | +{ | |
| 7 | + public function up() | |
| 8 | + { | |
| 9 | + /** | |
| 10 | + * Create table and all relations for related articles functionality | |
| 11 | + */ | |
| 12 | + $this->createTable( | |
| 13 | + 'blog_article_to_article', | |
| 14 | + [ | |
| 15 | + 'id' => $this->primaryKey(), | |
| 16 | + 'blog_article_id' => $this->integer() | |
| 17 | + ->notNull(), | |
| 18 | + 'related_blog_article_id' => $this->integer() | |
| 19 | + ->notNull(), | |
| 20 | + ] | |
| 21 | + ); | |
| 22 | + | |
| 23 | + $this->createIndex( | |
| 24 | + 'blog_article_to_article_uk', | |
| 25 | + 'blog_article_to_article', | |
| 26 | + [ | |
| 27 | + 'blog_article_id', | |
| 28 | + 'related_blog_article_id', | |
| 29 | + ], | |
| 30 | + true | |
| 31 | + ); | |
| 32 | + | |
| 33 | + $this->addForeignKey( | |
| 34 | + 'blog_article_to_article_art_fk', | |
| 35 | + 'blog_article_to_article', | |
| 36 | + 'blog_article_id', | |
| 37 | + 'blog_article', | |
| 38 | + 'id', | |
| 39 | + 'CASCADE', | |
| 40 | + 'CASCADE' | |
| 41 | + ); | |
| 42 | + | |
| 43 | + $this->addForeignKey( | |
| 44 | + 'blog_article_to_article_rel_fk', | |
| 45 | + 'blog_article_to_article', | |
| 46 | + 'related_blog_article_id', | |
| 47 | + 'blog_article', | |
| 48 | + 'id', | |
| 49 | + 'CASCADE', | |
| 50 | + 'CASCADE' | |
| 51 | + ); | |
| 52 | + } | |
| 53 | + | |
| 54 | + public function down() | |
| 55 | + { | |
| 56 | + $this->dropForeignKey('blog_article_to_article_rel_fk', 'blog_article_to_article'); | |
| 57 | + $this->dropForeignKey('blog_article_to_article_art_fk', 'blog_article_to_article'); | |
| 58 | + $this->dropIndex('blog_article_to_article_uk', 'blog_article_to_article'); | |
| 59 | + $this->dropTable('blog_article_to_article'); | |
| 60 | + } | |
| 61 | +} | ... | ... |
migrations/m161101_144434_blog_article_to_product.php
0 โ 100755
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\db\Migration; | |
| 4 | + | |
| 5 | +class m161101_144434_blog_article_to_product extends Migration | |
| 6 | +{ | |
| 7 | + public function up() | |
| 8 | + { | |
| 9 | + /** | |
| 10 | + * Creates junction table and all stuff for adding related products to articles | |
| 11 | + */ | |
| 12 | + $this->createTable( | |
| 13 | + 'blog_article_to_product', | |
| 14 | + [ | |
| 15 | + 'id' => $this->primaryKey(), | |
| 16 | + 'blog_article_id' => $this->integer() | |
| 17 | + ->notNull(), | |
| 18 | + 'product_id' => $this->integer() | |
| 19 | + ->notNull(), | |
| 20 | + ] | |
| 21 | + ); | |
| 22 | + | |
| 23 | + $this->createIndex( | |
| 24 | + 'blog_article_to_product_uk', | |
| 25 | + 'blog_article_to_product', | |
| 26 | + [ | |
| 27 | + 'blog_article_id', | |
| 28 | + 'product_id', | |
| 29 | + ], | |
| 30 | + true | |
| 31 | + ); | |
| 32 | + | |
| 33 | + $this->addForeignKey( | |
| 34 | + 'blog_article_to_product_art_fk', | |
| 35 | + 'blog_article_to_product', | |
| 36 | + 'blog_article_id', | |
| 37 | + 'blog_article', | |
| 38 | + 'id', | |
| 39 | + 'CASCADE', | |
| 40 | + 'CASCADE' | |
| 41 | + ); | |
| 42 | + | |
| 43 | + $this->addForeignKey( | |
| 44 | + 'blog_article_to_product_prod_fk', | |
| 45 | + 'blog_article_to_product', | |
| 46 | + 'product_id', | |
| 47 | + 'product', | |
| 48 | + 'id', | |
| 49 | + 'CASCADE', | |
| 50 | + 'CASCADE' | |
| 51 | + ); | |
| 52 | + } | |
| 53 | + | |
| 54 | + public function down() | |
| 55 | + { | |
| 56 | + $this->dropForeignKey('blog_article_to_product_prod_fk', 'blog_article_to_product'); | |
| 57 | + $this->dropForeignKey('blog_article_to_product_art_fk', 'blog_article_to_product'); | |
| 58 | + $this->dropIndex('blog_article_to_product_uk', 'blog_article_to_product'); | |
| 59 | + $this->dropTable('blog_article_to_product'); | |
| 60 | + } | |
| 61 | +} | ... | ... |