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 #1283

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

mho22
Copy link
Contributor

@mho22 mho22 commented Jun 1, 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.

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

@austintoddj austintoddj added the enhancement New feature or request label Sep 16, 2023
@mho22
Copy link
Contributor Author

mho22 commented Jan 19, 2024

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
Copy link
Owner

@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
Copy link
Contributor Author

mho22 commented Jan 25, 2024

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

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.

None yet

2 participants