diff options
author | Andrew Dolgov <[email protected]> | 2021-03-04 08:30:52 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-03-04 08:30:52 +0300 |
commit | c0fb0a5ec04c064bb848534185b51c5d1b7bdaaf (patch) | |
tree | 1023912c25fb14a917d0ff23d21bc6b72c73bef0 /classes/config.php | |
parent | 921569e5da6c3ccbf203506a243cbf499432ec15 (diff) |
wip for db_migrations for core schema
Diffstat (limited to 'classes/config.php')
-rw-r--r-- | classes/config.php | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/classes/config.php b/classes/config.php index 7a37d4a86..30b65305a 100644 --- a/classes/config.php +++ b/classes/config.php @@ -114,6 +114,9 @@ class Config { private $schema_version = null; private $version = []; + /** @var Db_Migrations $migrations */ + private $migrations; + public static function get_instance() : Config { if (self::$instance == null) self::$instance = new self(); @@ -218,18 +221,25 @@ class Config { return $rv; } - static function get_schema_version(bool $nocache = false) { - return self::get_instance()->_schema_version($nocache); + static function get_migrations() : Db_Migrations { + return self::get_instance()->_get_migrations(); } - function _schema_version(bool $nocache = false) { - if (empty($this->schema_version) || $nocache) { - $row = Db::pdo()->query("SELECT schema_version FROM ttrss_version")->fetch(); - - $this->schema_version = (int) $row["schema_version"]; + private function _get_migrations() : Db_Migrations { + if (empty($this->migrations)) { + $this->migrations = new Db_Migrations(); + $this->migrations->initialize(dirname(__DIR__) . "/sql", "ttrss_version", true); } - return $this->schema_version; + return $this->migrations; + } + + static function is_migration_needed() : bool { + return self::get_migrations()->is_migration_needed(); + } + + static function get_schema_version() : int { + return self::get_migrations()->get_version(); } static function cast_to(string $value, int $type_hint) { |