summaryrefslogtreecommitdiff
path: root/classes/db
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-03-04 10:13:29 +0300
committerAndrew Dolgov <[email protected]>2021-03-04 10:13:29 +0300
commit8f8ca49e4b3d06b19f7bef0f918b7425a456c5ac (patch)
tree86422bc33733621e6752adff88ab4a602215e96e /classes/db
parent4ede76280b79ec02a5e1c05bf08bd87cf37c4334 (diff)
migrations: refuse to apply empty schema files
Diffstat (limited to 'classes/db')
-rw-r--r--classes/db/migrations.php44
1 files changed, 25 insertions, 19 deletions
diff --git a/classes/db/migrations.php b/classes/db/migrations.php
index 26866698b..4bd72bd09 100644
--- a/classes/db/migrations.php
+++ b/classes/db/migrations.php
@@ -82,29 +82,35 @@ class Db_Migrations {
else
Debug::log("Starting migration to $version...", Debug::LOG_VERBOSE);
- // mysql doesn't support transactions for DDL statements
- if (Config::get(Config::DB_TYPE) != "mysql")
- $this->pdo->beginTransaction();
-
- foreach ($this->get_lines($version) as $line) {
- Debug::log($line, Debug::LOG_EXTENDED);
- try {
- $this->pdo->query($line);
- } catch (PDOException $e) {
- Debug::log("Failed on line: $line", Debug::LOG_VERBOSE);
- throw $e;
+ $lines = $this->get_lines($version);
+
+ if (count($lines) > 0) {
+ // mysql doesn't support transactions for DDL statements
+ if (Config::get(Config::DB_TYPE) != "mysql")
+ $this->pdo->beginTransaction();
+
+ foreach ($lines as $line) {
+ Debug::log($line, Debug::LOG_EXTENDED);
+ try {
+ $this->pdo->query($line);
+ } catch (PDOException $e) {
+ Debug::log("Failed on line: $line", Debug::LOG_VERBOSE);
+ throw $e;
+ }
}
- }
- if ($version == 0 && $this->base_is_latest)
- $this->set_version($this->get_max_version());
- else
- $this->set_version($version);
+ if ($version == 0 && $this->base_is_latest)
+ $this->set_version($this->get_max_version());
+ else
+ $this->set_version($version);
- if (Config::get(Config::DB_TYPE) != "mysql")
- $this->pdo->commit();
+ if (Config::get(Config::DB_TYPE) != "mysql")
+ $this->pdo->commit();
- Debug::log("Migration finished, current version: " . $this->get_version(), Debug::LOG_VERBOSE);
+ Debug::log("Migration finished, current version: " . $this->get_version(), Debug::LOG_VERBOSE);
+ } else {
+ Debug::log("Migration failed: schema file is empty or missing.", Debug::LOG_VERBOSE);
+ }
} catch (PDOException $e) {
Debug::log("Migration failed: " . $e->getMessage(), Debug::LOG_VERBOSE);