summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-03-04 07:26:05 +0300
committerAndrew Dolgov <[email protected]>2021-03-04 07:26:05 +0300
commit921569e5da6c3ccbf203506a243cbf499432ec15 (patch)
tree66c4046b3c59454d7d1995455dcc943910ffe689
parent8256ab5dd901904dfa8f78ebc3f3ed08a969226d (diff)
support loading base schema as latest version
-rw-r--r--classes/db/migrations.php23
1 files changed, 14 insertions, 9 deletions
diff --git a/classes/db/migrations.php b/classes/db/migrations.php
index d1eee61d3..f85b4d7c7 100644
--- a/classes/db/migrations.php
+++ b/classes/db/migrations.php
@@ -5,26 +5,28 @@ class Db_Migrations {
private $base_path;
private $migrations_path;
private $migrations_table;
+ private $base_is_latest;
private $pdo;
private $cached_version;
private $cached_max_version;
- function initialize_for_plugin(Plugin $plugin, string $schema_suffix = "sql") {
+ function __construct() {
+ $this->pdo = Db::pdo();
+ }
+
+ function initialize_for_plugin(Plugin $plugin, bool $base_is_latest = true, string $schema_suffix = "sql") {
$plugin_dir = PluginHost::getInstance()->get_plugin_dir($plugin);
$this->initialize($plugin_dir . "/${schema_suffix}",
- strtolower("ttrss_migrations_plugin_" . get_class($plugin)));
+ strtolower("ttrss_migrations_plugin_" . get_class($plugin)),
+ $base_is_latest);
}
- function initialize(string $root_path, string $migrations_table) {
+ function initialize(string $root_path, string $migrations_table, bool $base_is_latest = true) {
$this->base_path = "$root_path/" . Config::get(Config::DB_TYPE);
$this->migrations_path = $this->base_path . "/migrations";
-
$this->migrations_table = $migrations_table;
- }
-
- function __construct() {
- $this->pdo = Db::pdo();
+ $this->base_is_latest = $base_is_latest;
}
private function set_version(int $version) {
@@ -72,7 +74,10 @@ class Db_Migrations {
$this->pdo->query($line);
}
- $this->set_version($version);
+ if ($version == 0 && $this->base_is_latest)
+ $this->set_version($this->get_max_version());
+ else
+ $this->set_version($version);
$this->pdo->commit();
} catch (PDOException $e) {