canvas icon indicating copy to clipboard operation
canvas copied to clipboard

Ability to use a dedicated Canvas database connection

Open mho22 opened this issue 2 years ago • 3 comments

Pull Request Suggestion linked with Issue #509

The actual Canvas database connection is the config('database.default') . In order to use a dedicated database connection. It needed a config parameter to identify it.

config/canvas.php

'database_connection' => env('CANVAS_DB_CONNECTION', 'mysql'),

It is since then, implemented in the config file, migrations, models [ via a AbstractCanvasModel extended class ], the migrate command, and all the dedicated requests verifying if the table exists.

The config method call is a bit redundant, I confess.

The phpunit tests runs correctly with the CANVAS_DB_CONNECTION set to sqlite in phpunit.xml.dist file as it is the way indicated in the Contributing markdown page.

  • I couldn't try to create a post directly from the dashboard using the develop branch yet.
  • I haven't updated the readme.md file explaining the way and use of this feature yet. Waiting for your approval.
  • I based my PR on Wink's database connection implementation.

To make this work in a new laravel project, just follow the Contributing page. But before the php artisan canvas:install command. Be sure to have these data set :

.env

CANVAS_DB_CONNECTION={your-canvas-db-connection}
CANVAS_DB_DATABASE=canvas
.
.
.

config/database.php [ custom connection, for example here a custom mysql database ]

'connections' => [
    {your-canvas-db-connection} => [
            'driver' => 'mysql',
            'url' => env('CANVAS_DATABASE_URL'),
            'host' => env('CANVAS_DB_HOST', '127.0.0.1'),
            'port' => env('CANVAS_DB_PORT', '3306'),
            'database' => env('CANVAS_DB_DATABASE', 'forge'),
            'username' => env('CANVAS_DB_USERNAME', 'forge'),
            'password' => env('CANVAS_DB_PASSWORD', ''),
            'unix_socket' => env('CANVAS_DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ], 

Hope this helps.

P.S.: Sorry for the duplicate, I got a problem with the previous PR.

mho22 avatar Jun 01 '23 15:06 mho22

Hi @austintoddj, I know it's been quite some time here. Do you want me to do something here or this is related to the V7?

mho22 avatar Jan 19 '24 08:01 mho22

@mho22 Apologies for not getting around to this yet - it's still on my mind to get it implemented. Lots of life things going on right now, I will get to this when I can.

austintoddj avatar Jan 25 '24 14:01 austintoddj

@austintoddj Absolutely! Feel free to reach out if you have any questions or if there's anything else you need regarding this pull request. Take care.

mho22 avatar Jan 25 '24 20:01 mho22