Multi Tenant Multiple Database Setup [closed]

旧街凉风 提交于 2019-12-04 21:13:52

1) It all depends on how you set it up. How will you remember what user has to use what DB? You can always do something like

    'components' => [
        'db1' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=localhost;dbname=db1name', //maybe other dbms such as psql,...
            'username' => 'db1username',
            'password' => 'db1password',
        ],
        'db2' => function() use ($whatever, $variables, $you, $need) {
            return [
               'class' => 'yii\db\Connection',
               'dsn' => 'mysql:host=localhost;dbname=' . GETTHEDATABASEINAWAY, 
               'username' => GETTHEUSERINAWAY,
               'password' => GETTHEPASSINAWAY,
            ],
        }
    ],

];

More on anonymous functions http://php.net/manual/en/functions.anonymous.php

2) You probably have a list of databases someplace. Create your own migrate controller that extends the main one and you can call it to migrate instead of the the normal yii 2 controller. in console you can create migrationController.php that extends the the Yii2 one, instead of calling php yii migrate/up you will call php yii migration/up.

You can also trick the system to use your own MigrateControllor so you can still use php yii migrate/up , try using the URL rules to do this. I saw a guy doing it another way but I cannot find the location.

3) if you create your own migration controller (see number 2) then just add parameters to the migration command. Right now it can receive parameters like --migration-path and --db , add your own parameter to do what you need.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!