From 2f614ed2ea36c30131aa6ed6a271c5e4b475ab96 Mon Sep 17 00:00:00 2001 From: Joao Gilberto Magalhaes Date: Sun, 26 Apr 2020 23:21:21 -0500 Subject: [PATCH 1/5] Upgrade anydataset component --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9fc8816..763bbde 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "byjg/anydataset-db": "4.0.*", + "byjg/anydataset-db": "4.1.0.x-dev", "ext-pdo": "*" }, "require-dev": { From 3d74841bc847ae8c57229c260d9331ad0198a5f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joao=20Gilberto=20Magalh=C3=A3es?= Date: Wed, 6 May 2020 03:29:25 -0500 Subject: [PATCH 2/5] Added isDatabaseVersioned issue #27 --- src/Database/AbstractDatabase.php | 15 +++++++++++++++ src/Database/DatabaseInterface.php | 2 ++ src/Database/SqliteDatabase.php | 12 ++++++++++++ src/Migration.php | 10 ++++++++++ tests/BaseDatabase.php | 7 +++++++ 5 files changed, 46 insertions(+) diff --git a/src/Database/AbstractDatabase.php b/src/Database/AbstractDatabase.php index 702a6ea..202efab 100644 --- a/src/Database/AbstractDatabase.php +++ b/src/Database/AbstractDatabase.php @@ -121,4 +121,19 @@ public function updateVersionTable() $this->createVersion(); $this->setVersion($currentVersion, Migration::VERSION_STATUS_UNKNOWN); } + + public function isDatabaseVersioned() + { + $count = $this->getDbDriver()->getScalar( + 'SELECT count(*) FROM information_schema.tables ' . + ' WHERE table_schema = [[schema]] ' . + ' AND table_name = [[table]] ', + [ + "schema" => ltrim($this->getDbDriver()->getUri()->getPath(), "/"), + "table" => $this->getMigrationTable() + ] + ); + + return ($count !== 0); + } } diff --git a/src/Database/DatabaseInterface.php b/src/Database/DatabaseInterface.php index 7602ad5..5a8e144 100644 --- a/src/Database/DatabaseInterface.php +++ b/src/Database/DatabaseInterface.php @@ -27,6 +27,8 @@ public function setVersion($version, $status); public function createVersion(); + public function isDatabaseVersioned(); + public function getDbDriver(); public function getMigrationTable(); diff --git a/src/Database/SqliteDatabase.php b/src/Database/SqliteDatabase.php index 4242249..41fe719 100644 --- a/src/Database/SqliteDatabase.php +++ b/src/Database/SqliteDatabase.php @@ -53,4 +53,16 @@ protected function executeSqlInternal($sql) { $this->getDbDriver()->execute($sql); } + + public function isDatabaseVersioned() + { + $count = $this->getDbDriver()->getScalar( + "SELECT count(*) FROM sqlite_master WHERE type='table' AND name=[[table]]", + [ + "table" => $this->getMigrationTable() + ] + ); + + return (intval($count) !== 0); + } } diff --git a/src/Migration.php b/src/Migration.php index 8e71d19..fe2be0b 100644 --- a/src/Migration.php +++ b/src/Migration.php @@ -101,6 +101,11 @@ public function getDbCommand() return $this->dbCommand; } + public function getMigrationTable() + { + return $this->migrationTable; + } + /** * @return mixed * @throws \ByJG\DbMigration\Exception\DatabaseDoesNotRegistered @@ -346,4 +351,9 @@ public function addCallbackProgress(callable $callable) { $this->callableProgress = $callable; } + + public function isDatabaseVersioned() + { + return $this->getDbCommand()->isDatabaseVersioned(); + } } diff --git a/tests/BaseDatabase.php b/tests/BaseDatabase.php index 4afcadd..4a1cf3f 100644 --- a/tests/BaseDatabase.php +++ b/tests/BaseDatabase.php @@ -45,6 +45,13 @@ public function testVersion0() $this->assertVersion0(); } + public function testIsDatabaseVersioned() + { + $this->assertFalse($this->migrate->isDatabaseVersioned()); + $this->migrate->reset(); + $this->assertTrue($this->migrate->isDatabaseVersioned()); + } + /** * @throws \ByJG\DbMigration\Exception\DatabaseDoesNotRegistered * @throws \ByJG\DbMigration\Exception\DatabaseIsIncompleteException From 691de3e76a3d63bc7320e1fcba23c026ba28a399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joao=20Gilberto=20Magalh=C3=A3es?= Date: Thu, 7 May 2020 00:59:06 -0500 Subject: [PATCH 3/5] Fix isDatabaseVersioned issue on Postgres and MySQL --- .idea/runConfigurations/Start_MySql.xml | 38 ++++++++++++++++++ .idea/runConfigurations/Start_Postgres.xml | 42 ++++++++++++++++++++ .idea/runConfigurations/Start_SQL_Server.xml | 42 ++++++++++++++++++++ .idea/runConfigurations/Test_Postgres.xml | 24 +---------- .idea/runConfigurations/Test_SqlSever.xml | 6 +++ src/Database/AbstractDatabase.php | 13 ++++-- src/Database/PgsqlDatabase.php | 5 +++ 7 files changed, 144 insertions(+), 26 deletions(-) create mode 100644 .idea/runConfigurations/Start_MySql.xml create mode 100644 .idea/runConfigurations/Start_Postgres.xml create mode 100644 .idea/runConfigurations/Start_SQL_Server.xml create mode 100644 .idea/runConfigurations/Test_SqlSever.xml diff --git a/.idea/runConfigurations/Start_MySql.xml b/.idea/runConfigurations/Start_MySql.xml new file mode 100644 index 0000000..6ec0abf --- /dev/null +++ b/.idea/runConfigurations/Start_MySql.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Start_Postgres.xml b/.idea/runConfigurations/Start_Postgres.xml new file mode 100644 index 0000000..95c3e67 --- /dev/null +++ b/.idea/runConfigurations/Start_Postgres.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Start_SQL_Server.xml b/.idea/runConfigurations/Start_SQL_Server.xml new file mode 100644 index 0000000..81de896 --- /dev/null +++ b/.idea/runConfigurations/Start_SQL_Server.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Test_Postgres.xml b/.idea/runConfigurations/Test_Postgres.xml index 1027c17..999f71b 100644 --- a/.idea/runConfigurations/Test_Postgres.xml +++ b/.idea/runConfigurations/Test_Postgres.xml @@ -1,26 +1,6 @@ - - - - - - - + + \ No newline at end of file diff --git a/.idea/runConfigurations/Test_SqlSever.xml b/.idea/runConfigurations/Test_SqlSever.xml new file mode 100644 index 0000000..cd28e03 --- /dev/null +++ b/.idea/runConfigurations/Test_SqlSever.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Database/AbstractDatabase.php b/src/Database/AbstractDatabase.php index 202efab..cdb9117 100644 --- a/src/Database/AbstractDatabase.php +++ b/src/Database/AbstractDatabase.php @@ -122,18 +122,23 @@ public function updateVersionTable() $this->setVersion($currentVersion, Migration::VERSION_STATUS_UNKNOWN); } - public function isDatabaseVersioned() + protected function isDatabaseVersioned_Internal($schema, $table) { $count = $this->getDbDriver()->getScalar( 'SELECT count(*) FROM information_schema.tables ' . ' WHERE table_schema = [[schema]] ' . ' AND table_name = [[table]] ', [ - "schema" => ltrim($this->getDbDriver()->getUri()->getPath(), "/"), - "table" => $this->getMigrationTable() + "schema" => $schema, + "table" => $table ] ); - return ($count !== 0); + return (intval($count) !== 0); + } + + public function isDatabaseVersioned() + { + return $this->isDatabaseVersioned_Internal(ltrim($this->getDbDriver()->getUri()->getPath(), "/"), $this->getMigrationTable()); } } diff --git a/src/Database/PgsqlDatabase.php b/src/Database/PgsqlDatabase.php index e19676c..c0d10a2 100644 --- a/src/Database/PgsqlDatabase.php +++ b/src/Database/PgsqlDatabase.php @@ -80,4 +80,9 @@ protected function executeSqlInternal($sql) } $this->getDbDriver()->execute($sql); } + + public function isDatabaseVersioned() + { + return $this->isDatabaseVersioned_Internal('public', $this->getMigrationTable()); + } } From 6567506fb8176e717c5b43083a87ff5ffb5e2467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joao=20Gilberto=20Magalh=C3=A3es?= Date: Thu, 7 May 2020 01:23:42 -0500 Subject: [PATCH 4/5] Reorganizing code --- src/Database/AbstractDatabase.php | 4 ++-- src/Database/PgsqlDatabase.php | 2 +- src/Database/SqliteDatabase.php | 9 +++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Database/AbstractDatabase.php b/src/Database/AbstractDatabase.php index cdb9117..b46c172 100644 --- a/src/Database/AbstractDatabase.php +++ b/src/Database/AbstractDatabase.php @@ -122,7 +122,7 @@ public function updateVersionTable() $this->setVersion($currentVersion, Migration::VERSION_STATUS_UNKNOWN); } - protected function isDatabaseVersioned_Internal($schema, $table) + protected function isTableExists($schema, $table) { $count = $this->getDbDriver()->getScalar( 'SELECT count(*) FROM information_schema.tables ' . @@ -139,6 +139,6 @@ protected function isDatabaseVersioned_Internal($schema, $table) public function isDatabaseVersioned() { - return $this->isDatabaseVersioned_Internal(ltrim($this->getDbDriver()->getUri()->getPath(), "/"), $this->getMigrationTable()); + return $this->isTableExists(ltrim($this->getDbDriver()->getUri()->getPath(), "/"), $this->getMigrationTable()); } } diff --git a/src/Database/PgsqlDatabase.php b/src/Database/PgsqlDatabase.php index c0d10a2..533e1ec 100644 --- a/src/Database/PgsqlDatabase.php +++ b/src/Database/PgsqlDatabase.php @@ -83,6 +83,6 @@ protected function executeSqlInternal($sql) public function isDatabaseVersioned() { - return $this->isDatabaseVersioned_Internal('public', $this->getMigrationTable()); + return $this->isTableExists('public', $this->getMigrationTable()); } } diff --git a/src/Database/SqliteDatabase.php b/src/Database/SqliteDatabase.php index 41fe719..080b5d9 100644 --- a/src/Database/SqliteDatabase.php +++ b/src/Database/SqliteDatabase.php @@ -54,15 +54,20 @@ protected function executeSqlInternal($sql) $this->getDbDriver()->execute($sql); } - public function isDatabaseVersioned() + protected function isTableExists($schema, $table) { $count = $this->getDbDriver()->getScalar( "SELECT count(*) FROM sqlite_master WHERE type='table' AND name=[[table]]", [ - "table" => $this->getMigrationTable() + "table" => $table ] ); return (intval($count) !== 0); } + + public function isDatabaseVersioned() + { + return $this->isTableExists(null, $this->getMigrationTable()); + } } From edb688cf182f69c1fce532201c892037b9e464fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joao=20Gilberto=20Magalh=C3=A3es?= Date: Sun, 10 May 2020 11:24:09 -0500 Subject: [PATCH 5/5] Upgrade Anydataset-DB version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 763bbde..26a4ff2 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "byjg/anydataset-db": "4.1.0.x-dev", + "byjg/anydataset-db": "4.1.*", "ext-pdo": "*" }, "require-dev": {