Commit 3d510dff authored by abkrim's avatar abkrim 😀
Browse files

Correct some problems with multidatabases

parent 87b30872
Pipeline #256 passed with stages
in 1 minute and 18 seconds
......@@ -15,3 +15,6 @@ All notable changes to `db-schema` will be documented in this file
- Create a new class DoctrineListSchema for command db-schema:doctrine-list. This is using Doctrine / DBAL to not depend on different database models. In principle and because of the urgency of my other projects I have not performed testing and I have only tested it on MySQL, but in principle it should work with the rest of the Database engines.
- This command permit save schemas in tables for control changes in databases of our project or databases associated with our project but not maintained by us.
## [1.0.1] - 2019-09-12
- Correct some problems with multidatabase projects
- I need some help for make tests in package ... Help me !!!
......@@ -2,3 +2,4 @@ To Do
=====
1. MonitorSchema need method refresh time & a config value
2. Testing, testing 6 testing
......@@ -66,7 +66,7 @@ class DoctrineListSchema extends Command
{
$table_schemas = array();
$sm = Schema::connection('mysql_vmail')->getConnection()->getDoctrineSchemaManager();
$sm = Schema::connection($this->connection)->getConnection()->getDoctrineSchemaManager();
$indexes = $sm->listTableIndexes($table);
foreach ($indexes as $index) {
......@@ -106,7 +106,7 @@ class DoctrineListSchema extends Command
private function showSchema(string $table, array $table_schemas): void
{
$this->info("Table: ". $table);
$this->info("Show table: ". $table);
// Columns
$rows = $table_schemas['columns'];
......@@ -126,6 +126,7 @@ class DoctrineListSchema extends Command
private function saveSchema(string $table, array $table_schemas): void
{
$this->info('Save table: ' . $table);
if ($this->option('f')) {
$this->saveOrUpdateTableSchema($table, $table_schemas);
} else {
......@@ -135,19 +136,22 @@ class DoctrineListSchema extends Command
private function setConnection(): void
{
if ($this->option('c')) {
if (! is_null($this->option('c'))) {
$this->connection = $this->option('c');
} else {
$this->connection = config('database.default');
}
if (! Arr::has(config('database.connections'), $this->connection)) {
$this->error('Incorrect option database connection');
exit;
}
if (! Arr::has(config('database.connections'), $this->connection)) {
$this->error('Incorrect option database connection');
exit;
}
}
private function setDbTables(): void
{
$sm_tables = Schema::connection($this->connection)->getAllTables();
$sm_db = 'Tables_in_'.config('database.connections.' . $this->connection . '.database');
foreach ($sm_tables as $sm_table) {
......@@ -186,7 +190,7 @@ class DoctrineListSchema extends Command
]);
} catch (\Exception $e) {
$this->warn("Some connection+table+version is already in system");
echo $e->getMessage(); //Integrity constraint violation:
echo $e->getMessage().PHP_EOL; //Integrity constraint violation:
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment