欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Using two different database users for web applications and console migrations....

Using two different database users for web applications and console migrations....

Hello everyone.

First case:

At the database level have I created two users - "app_web_worker"(for web app) and "app_console_worker"(for migrations)

  • User "app_web_worker" has privileges only on: SELECT, INSERT, UPDATE, DELETE, SHOW_VIEW, EXECUTE
  • User "app_console_worker" has full DB privileges

Question: What is the simplest and most correct way to use the user "app_worker" for web applications, and user "app_admin" only for migrations?

Second case:

I created two database users "app_web_admin", "app_web_worker".

  • User "app_web_worker", for example, has only SELECT privilege on the table app_products.
  • User "app_web_admin" has SELECT, INSERT, UPDATE, DELETE on the table app_products.

Question: how, depending on the current URL to use different settings for connect to db?

Example:

  • On URL - awesomesite.com - i use "app_web_worker" db user.
  • On URL - awesomesite.com/admin - i use "app_web_admin"
gudron
gudron
  • 2 years ago

My solution:

if($app->runningInConsole()) {

    $app->loadEnvironmentFrom('console.env');

} else {

    if(Illuminate\Http\Request::capture()->segment(1) == 'admin_url' ){
        $app->loadEnvironmentFrom('web_admin.env');
    } else {
        $app->loadEnvironmentFrom('web_client.env');
    }
}
来自 https://laravel.io/forum/02-22-2015-using-two-different-database-users-for-web-applications-and-cons...
普通分类: