Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to use a dedicated Canvas database connection #1270

Closed
wants to merge 2 commits into from
Closed

Ability to use a dedicated Canvas database connection #1270

wants to merge 2 commits into from

Conversation

mho22
Copy link
Contributor

@mho22 mho22 commented May 23, 2023

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.

@austintoddj austintoddj added the enhancement New feature or request label May 24, 2023
@austintoddj
Copy link
Owner

Thanks for putting this up - I'll review it as soon as I can.

@mho22 mho22 closed this by deleting the head repository Jun 1, 2023
@mho22
Copy link
Contributor Author

mho22 commented Jun 1, 2023

Sorry for the problem caused, the new PR is here #1283

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants