Closed calebdw closed 1 year ago
I found that the --connection
options does work as expected when running the command manually through Artisan. However, I'm trying to loop over the connections in code, and every migration file has the same content as the first connection....maybe it has something to do with the --squash
option and the temporary files?
I think I found the reason---all of the schema managers are being registered as singletons:
foreach (
[
Setting::class => Setting::class,
MySQLRepository::class => MySQLRepository::class,
MySQLSchema::class => DBALMySQLSchema::class,
PgSQLRepository::class => PgSQLRepository::class,
PgSQLSchema::class => DBALPgSQLSchema::class,
SQLiteRepository::class => SQLiteRepository::class,
SQLiteSchema::class => DBALSQLiteSchema::class,
SQLSrvRepository::class => SQLSrvRepository::class,
SQLSrvSchema::class => DBALSQLSrvSchema::class,
MariaDBRepository::class => MariaDBRepository::class,
] as $abstract => $concrete
) {
$this->app->singleton($abstract, $concrete);
}
Hi @CalebDW Thank you for reporting.
Instead, the --connection
works fine for me, with --squash
.
I'm trying to loop over the connections in code
I am not fully clear with your usage here, perhaps you could provide some code examples? And how is the singleton broke your code?
Thanks for you providing more info.
I'm trying to use this package to create table migrations for Larastan to read (because it doesn't do great at reading Postgres dumps). The code is as follows:
collect(config('database.connections'))
->mapWithKeys(fn ($item, $key) => [$key => $item['database']])
->sortBy(fn ($database) => $database === config('database.default'))
->each(function ($database, $connection) {
$task = "Creating Larastan migration for database [{$database}] on connection [{$connection}]";
$this->components->info($task);
$this->call('migrate:generate', [
'--connection' => $connection,
'--path' => 'larastan/migrations',
'--table-filename' => "create_{$connection}_tables.php",
'--skip-log' => true,
'--skip-proc' => true,
'--skip-views' => true,
'--squash' => true,
]);
App::forgetInstance(PgSQLSchema::class);
});
I was able to solve the issue on my end by forgetting the singleton, but I think it would be good to update it on your end to not be a singleton.
Thank you @CalebDW
Awesome, no thank you!
Hello!
Describe the bug I have 3 different connections/databases in my application. When I try to use this package to create a squashed migration file for each of them using the
--connection
, I get 3 migration files all with the same tables from the default connection, but applied to the different connections withSchema::connection()
.To Reproduce Steps to reproduce the behavior:
Expected behavior I expect
--connection <connection_2>
to create a migration file for the tables in connection 2.Screenshots N/A
Details (please complete the following information):
doctrine/dbal
]: 3.6.1Additional context Add any other context about the problem here.