austintoddj / canvas

Publishing on your own terms
http://trycanvas.app
MIT License
3.26k stars 520 forks source link

Ability to use a dedicated Canvas database connection #1283

Open mho22 opened 1 year ago

mho22 commented 1 year ago

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.

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 commented 9 months ago

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?

austintoddj commented 9 months ago

@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.

mho22 commented 9 months ago

@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.