Browse Source

Address the schema changing on the service

redup
J. King 2 years ago
parent
commit
df185bbe42
  1. 1
      lib/AbstractException.php
  2. 8
      lib/Database.php
  3. 1
      lib/Service.php
  4. 1
      locale/en.php

1
lib/AbstractException.php

@ -38,6 +38,7 @@ abstract class AbstractException extends \Exception {
"Db/Exception.updateFileUnreadable" => 10216,
"Db/Exception.updateFileError" => 10217,
"Db/Exception.updateFileIncomplete" => 10218,
"Db/Exception.updateSchemaChange" => 10219,
"Db/Exception.paramTypeInvalid" => 10221,
"Db/Exception.paramTypeUnknown" => 10222,
"Db/Exception.paramTypeMissing" => 10223,

8
lib/Database.php

@ -25,7 +25,7 @@ use JKingWeb\Arsse\Rule\Exception as RuleException;
*
* - Users
* - Subscriptions to feeds, which belong to users
* - Folders, which belong to users and contain subscriptions
* - Folders, which belong to users and contain subscriptions or other folders
* - Tags, which belong to users and can be assigned to multiple subscriptions
* - Icons, which are associated with subscriptions
* - Articles, which belong to subscriptions
@ -76,9 +76,15 @@ class Database {
public function __construct($initialize = true) {
$driver = Arsse::$conf->dbDriver;
$this->db = $driver::create();
$this->checkSchemaVersion($initialize);
}
public function checkSchemaVersion(bool $initialize = false): void {
$ver = $this->db->schemaVersion();
if ($initialize && $ver < self::SCHEMA_VERSION) {
$this->db->schemaUpdate(self::SCHEMA_VERSION);
} elseif ($ver != self::SCHEMA_VERSION) {
throw new Db\Exception("updateSchemaChange");
}
}

1
lib/Service.php

@ -66,6 +66,7 @@ class Service {
}
public function checkIn(): bool {
Arsse::$db->checkSchemaVersion();
return Arsse::$db->metaSet("service_last_checkin", time(), "datetime");
}

1
locale/en.php

@ -147,6 +147,7 @@ return [
0 {Automatic updating of the {driver_name} database failed because it is already up to date with the requested version, {target}}
other {Automatic updating of the {driver_name} database failed because its version, {current}, is newer than the requested version, {target}}
}',
'Exception.JKingWeb/Arsse/Db/Exception.updateSchemaChange' => 'Database schema version has changed since the application was started; application restart is required',
'Exception.JKingWeb/Arsse/Db/Exception.engineErrorGeneral' => '{0}',
// indicates programming error
'Exception.JKingWeb/Arsse/Db/Exception.savepointStatusUnknown' => 'Savepoint status code {0} not implemented',

Loading…
Cancel
Save