Skip to content

Commit 6d87ac7

Browse files
author
Gaetano Giunta
committed
docs
1 parent 5955f88 commit 6d87ac7

File tree

12 files changed

+38
-26
lines changed

12 files changed

+38
-26
lines changed

TODO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- missing for psql? (according to slack discussion: this is impossible using psql and can only be done using a different
77
driver... it might be in fact already happening when NOT using input via files...)
88
+ examine in detail and document the differences between running a command vs a file (eg. transaction usage)
9+
+ check: can the temp user drop&creates schemas for postgresql?
910

1011
- improve cli scripts:
1112
+ add scripts to create and drop a schema on all servers

WHATSNEW.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
Version 0.3 (unreleased)
2-
------------------------
1+
Version 0.3.1
2+
-------------
3+
4+
- Fixed: temporary db schemas would not be dropped, at least for mariadb/mysql databases
5+
6+
7+
Version 0.3
8+
-----------
39

410
- Improved: add confirmation question to the cli command which deletes all database data
511

@@ -8,7 +14,7 @@ Version 0.3 (unreleased)
814
- allow to print output in json/yaml/php format
915
- allow to execute sql commands stored in a file besides specifying them as cli option
1016
- all sql commands are now executed in a temporary db schema, by a corresponding temp. db user, instead of being
11-
executed with the database 'root' account
17+
executed with the database 'root' account
1218

1319

1420
Version 0.2

app/config/services.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ services:
133133
# this creates a service per class whose id is the fully-qualified class name
134134
Db3v4l\:
135135
resource: '../src/*'
136-
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
136+
exclude: '../src/{API,Core,Tests,Util,Kernel.php}'
137137

138138
# controllers are imported separately to make sure services can be injected
139139
# as action arguments even if you don't extend any base controller class

app/src/Command/SqlExecute.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Symfony\Component\Yaml\Yaml;
99
use Db3v4l\API\Interfaces\TimedExecutor;
1010
use Db3v4l\Service\DatabaseConfigurationManager;
11-
use Db3v4l\Service\DatabaseSchemaManager;
11+
use Db3v4l\Core\DatabaseSchemaManager;
1212
use Db3v4l\Service\SqlExecutorFactory;
1313
use Db3v4l\Service\ProcessManager;
1414
use Db3v4l\Util\Process;
@@ -177,9 +177,9 @@ protected function createSchemas($dbList, $maxParallel)
177177
$schemaName = null; // $userName will be used as schema name
178178

179179
foreach ($dbList as $dbName) {
180-
$dbConnectionSpec = $this->dbManager->getDatabaseConnectionSpecification($dbName);
180+
$rootDbConnectionSpec = $this->dbManager->getDatabaseConnectionSpecification($dbName);
181181

182-
$schemaManager = new DatabaseSchemaManager($dbConnectionSpec);
182+
$schemaManager = new DatabaseSchemaManager($rootDbConnectionSpec);
183183
$sql = $schemaManager->getCreateSchemaSQL($userName, $password, $schemaName);
184184
// sadly, psql does not allow to create a db and a user using a multiple-sql-commands string,
185185
// and we have to resort to using temp files
@@ -188,10 +188,10 @@ protected function createSchemas($dbList, $maxParallel)
188188
file_put_contents($tempSQLFileName, $sql);
189189
$tempSQLFileNames[] = $tempSQLFileName;
190190

191-
$executor = $this->executorFactory->createForkedExecutor($dbConnectionSpec, 'NativeClient', false);
191+
$executor = $this->executorFactory->createForkedExecutor($rootDbConnectionSpec, 'NativeClient', false);
192192
$process = $executor->getExecuteFileProcess($tempSQLFileName);
193193
$processes[$dbName] = $process;
194-
$connectionSpecs[$dbName] = $dbConnectionSpec;
194+
$connectionSpecs[$dbName] = $rootDbConnectionSpec;
195195
}
196196

197197
$this->processManager->runParallel($processes, $maxParallel, 100);
@@ -226,15 +226,15 @@ protected function dropSchemas($dbSpecList, $maxParallel)
226226
$tempSQLFileNames = [];
227227

228228
foreach ($dbSpecList as $dbName => $dbConnectionSpec) {
229-
$dbConnectionSpec = $this->dbManager->getDatabaseConnectionSpecification($dbName);
229+
$rootDbConnectionSpec = $this->dbManager->getDatabaseConnectionSpecification($dbName);
230230

231-
$schemaManager = new DatabaseSchemaManager($dbConnectionSpec);
231+
$schemaManager = new DatabaseSchemaManager($rootDbConnectionSpec);
232232
$sql= $schemaManager->getDropSchemaSQL($dbConnectionSpec['user'], isset($dbConnectionSpec['dbname']) ? $dbConnectionSpec['dbname'] : null );
233233
$tempSQLFileName = tempnam(sys_get_temp_dir(), 'db3val_');
234234
file_put_contents($tempSQLFileName, $sql);
235235
$tempSQLFileNames[] = $tempSQLFileName;
236236

237-
$executor = $this->executorFactory->createForkedExecutor($dbConnectionSpec, 'NativeClient', false);
237+
$executor = $this->executorFactory->createForkedExecutor($rootDbConnectionSpec, 'NativeClient', false);
238238
$process = $executor->getExecuteFileProcess($tempSQLFileName);
239239
$processes[$dbName] = $process;
240240
}

app/src/Service/DatabaseSchemaManager.php renamed to app/src/Core/DatabaseSchemaManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Db3v4l\Service;
3+
namespace Db3v4l\Core;
44

55
class DatabaseSchemaManager
66
{
@@ -62,7 +62,7 @@ public function getDropSchemaSQL($userName, $schemaName = null)
6262
switch ($dbType) {
6363
case 'mysql':
6464
return
65-
"DROP DATABASE IF EXISTS `$schemaName`; DROP USER '$userName'@'%';";
65+
"DROP USER '$userName'@'%'; DROP DATABASE IF EXISTS `$schemaName`;";
6666
case 'pgsql':
6767
return
6868
"DROP DATABASE IF EXISTS \"$schemaName\"; DROP USER IF EXISTS \"$userName\";";
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Db3v4l\Service\SqlExecutor;
3+
namespace Db3v4l\Core\SqlExecutor;
44

55
abstract class BaseExecutor
66
{
@@ -10,4 +10,4 @@ public function __construct(array $databaseConfiguration)
1010
{
1111
$this->databaseConfiguration = $databaseConfiguration;
1212
}
13-
}
13+
}

app/src/Service/SqlExecutor/Forked/Doctrine.php renamed to app/src/Core/SqlExecutor/Forked/Doctrine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Db3v4l\Service\SqlExecutor\Forked;
3+
namespace Db3v4l\Core\SqlExecutor\Forked;
44

55
use Db3v4l\API\Interfaces\ForkedCommandExecutor;
66
use Db3v4l\Util\Process;

app/src/Service/SqlExecutor/Forked/ForkedExecutor.php renamed to app/src/Core/SqlExecutor/Forked/ForkedExecutor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
namespace Db3v4l\Service\SqlExecutor\Forked;
3+
namespace Db3v4l\Core\SqlExecutor\Forked;
44

5-
use Db3v4l\Service\SqlExecutor\BaseExecutor;
5+
use Db3v4l\Core\SqlExecutor\BaseExecutor;
66

77
abstract class ForkedExecutor extends BaseExecutor
88
{

app/src/Service/SqlExecutor/Forked/NativeClient.php renamed to app/src/Core/SqlExecutor/Forked/NativeClient.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Db3v4l\Service\SqlExecutor\Forked;
3+
namespace Db3v4l\Core\SqlExecutor\Forked;
44

55
use Db3v4l\API\Interfaces\ForkedCommandExecutor;
66
use Db3v4l\API\Interfaces\ForkedFileExecutor;
@@ -99,4 +99,9 @@ protected function getDbClientTypeFromDriver($driver)
9999
{
100100
return str_replace('pdo_', '', $driver);
101101
}
102+
103+
protected function getEnv()
104+
{
105+
return array();
106+
}
102107
}

app/src/Service/SqlExecutor/Forked/TimedExecutor.php renamed to app/src/Core/SqlExecutor/Forked/TimedExecutor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Db3v4l\Service\SqlExecutor\Forked;
3+
namespace Db3v4l\Core\SqlExecutor\Forked;
44

55
use Db3v4l\API\Interfaces\ForkedCommandExecutor;
66
use Db3v4l\API\Interfaces\ForkedFileExecutor;

0 commit comments

Comments
 (0)