I am trying to migrate my app in with multiple databases. I have 3 databases in my app and when I run migrations I need to apply different settings to each database.
I have read this and tried to apply it but it does not work
http://www.yiiframework.com/doc-2.0/guide-db-migrations.html#migrating-multiple-databases
I used this code (but even if this did work ideally i would like to in the up function apply some changes to db 1 and some changes to db 2. Thanks for your help.
[color=#000080]consol/migrations[/color][color=#000080][b]<?php
[/b][/color][color=#000080][b]
[/b][/color][color=#000080]use [/color]yii\db\Migration;
[color=#000080]class [/color]m161208_142322_migrate2 [color=#000080]extends [/color]Migration
{
[color=#000080][b]public function [/b][/color]init()
{
[color=#660000]$this[/color]->[color=#660e7a][b]db [/b][/color]= [color=#008000][b]'db2'[/b][/color];
[color=#000080][b]parent[/b][/color]::[i]init[/i]();
}
[color=#000080][b]public function [/b][/color]up()
{
[color=#660000]$this[/color]->createTable([color=#008000][b]'news2'[/b][/color], [
[color=#008000][b]'id' [/b][/color]=> [color=#660000]$this[/color]->primaryKey(),
[color=#008000][b]'title' [/b][/color]=> [color=#660000]$this[/color]->string()->notNull(),
[color=#008000][b]'content' [/b][/color]=> [color=#660000]$this[/color]->text(),
]);
}
[color=#000080][b]public function [/b][/color]down()
{
[color=#000080][b]echo [/b][/color][color=#008000][b]"m161208_142322_migrate2 cannot be reverted.[/b][/color][color=#000080][b]\n[/b][/color][color=#008000][b]"[/b][/color];
[color=#000080][b]return false[/b][/color];
}
[color=#808080][i]/*
[/i][/color][color=#808080][i] // Use safeUp/safeDown to run migration code within a transaction
[/i][/color][color=#808080][i] public function safeUp()
[/i][/color][color=#808080][i] {
[/i][/color][color=#808080][i] }
[/i][/color][color=#808080][i]
[/i][/color][color=#808080][i] public function safeDown()
[/i][/color][color=#808080][i] {
[/i][/color][color=#808080][i] }
[/i][/color][color=#808080][i] */
[/i][/color]}
[color=#000080]Enviroments/dev/common/config[/color][color=#000080]<?php[/color][color=#000080][b]
[/b][/color][color=#000080]return [/color][
[color=#008000][b]'components' [/b][/color]=> [
[color=#008000][b]'db' [/b][/color]=> [
[color=#008000][b]'class' [/b][/color]=> [color=#008000][b]'yii\db\Connection'[/b][/color],
[color=#008000][b]'dsn' [/b][/color]=> [color=#008000][b]'mysql:host=localhost;dbname=eurotech_main_db'[/b][/color],
[color=#008000][b]'username' [/b][/color]=> [color=#008000][b]'eurotech_all_db'[/b][/color],
[color=#008000][b]'password' [/b][/color]=> [color=#008000][b]'!CN-xnvuNh!@'[/b][/color],
[color=#008000][b]'charset' [/b][/color]=> [color=#008000][b]'utf8'[/b][/color],
],
[color=#008000][b]'db1' [/b][/color]=> [
[color=#008000][b]'class' [/b][/color]=> [color=#008000][b]'yii\db\Connection'[/b][/color],
[color=#008000][b]'dsn' [/b][/color]=> [color=#008000][b]'mysql:host=localhost;dbname=eurotech_db1'[/b][/color],
[color=#008000][b]'username' [/b][/color]=> [color=#008000][b]'eurotech_all_db'[/b][/color],
[color=#008000][b]'password' [/b][/color]=> [color=#008000][b]'!CN-xnvuNh!@'[/b][/color],
[color=#008000][b]'charset' [/b][/color]=> [color=#008000][b]'utf8'[/b][/color],
],
[color=#008000][b]'db2' [/b][/color]=> [
[color=#008000][b]'class' [/b][/color]=> [color=#008000][b]'yii\db\Connection'[/b][/color],
[color=#008000][b]'dsn' [/b][/color]=> [color=#008000][b]'mysql:host=localhost;dbname=eurotech_db2'[/b][/color],
[color=#008000][b]'username' [/b][/color]=> [color=#008000][b]'eurotech_all_db'[/b][/color],
[color=#008000][b]'password' [/b][/color]=> [color=#008000][b]'!CN-xnvuNh!@'[/b][/color],
[color=#008000][b]'charset' [/b][/color]=> [color=#008000][b]'utf8'[/b][/color],
],
[color=#008000][b]'mailer' [/b][/color]=> [
[color=#008000][b]'class' [/b][/color]=> [color=#008000][b]'yii\swiftmailer\Mailer'[/b][/color],
[color=#008000][b]'viewPath' [/b][/color]=> [color=#008000][b]'@common/mail'[/b][/color],
[color=#808080][i]// send all mails to a file by default. You have to set
[/i][/color][color=#808080][i] // ‘useFileTransport’ to false and configure a transport
[/i][/color][color=#808080][i] // for the mailer to send real emails.
[/i][/color][color=#808080] [/color][color=#008000]‘useFileTransport’ [/color]=> [color=#000080]true[/color],
],
],
];