Custom table name
Closed this issue · 3 comments
Pulse Version
1.4.1
Laravel Version
10
PHP Version
8.2
Livewire Version
Database Driver & Version
MySQL
Description
I have 2 applications running using the same database. I need to add prefix to the table names in Laravel Pulse to be like this dash_pulse_aggregates, dash_pulse_values, dash_pulse_entries. How can I make this possible?
Steps To Reproduce
Edited.
@rachmadep, I would recommend using a dedicated connection for Pulse.
You can specify the connection via the PULSE_DB_CONNECTION environment variable. For example, use PULSE_DB_CONNECTION=pulse. Then in your config/database.php, create a connection named pulse with all the same configuration values for your application's database.
Once that is in place, add a prefix to the pulse connection. Pulse should then use that prefix for its tables and avoid any conflict.
@timacdonald How to add a prefix to the pulse connection?
Since we use all the same configuration values for default application's database. Is it possible to avoid any conflict?
@rachmadep, here is an example of how you might do this.
You want to duplicate your database config under a dedicated pulse connection.
<?php
use Illuminate\Support\Str;
return [
// ...
'connections' => [
// ...
- 'mysql' => [
+ 'mysql' => $databaseConfig = [
'driver' => 'mysql',
'url' => env('DB_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'laravel'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => env('DB_CHARSET', 'utf8mb4'),
'collation' => env('DB_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'),
]) : [],
],
+ // Duplicate above "mysql" connection for pulse...
+
+ 'pulse' => [
+ ...$databaseConfig,
+ 'prefix' => 'dash_',
+ ],
+
// ...
],
// ...
];Then, configure pulse to use this new pulse connection:
PULSE_DB_CONNECTION=pulse