From 2a50167241fe6b6d84d793aad748eb74c631eae9 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Tue, 15 Apr 2025 12:20:21 +0400 Subject: [PATCH] modifs.mineures sans commentaires --- php/src/db/_private/_migration.php | 22 +++++++++++----------- php/src/db/mysql/_mysqlMigration.php | 10 +++++----- php/src/db/pgsql/PgsqlStorage.php | 2 +- php/src/db/sqlite/SqliteStorage.php | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/php/src/db/_private/_migration.php b/php/src/db/_private/_migration.php index 5f33acb..761addf 100644 --- a/php/src/db/_private/_migration.php +++ b/php/src/db/_private/_migration.php @@ -5,14 +5,6 @@ use nulib\db\IDatabase; use nulib\php\func; abstract class _migration { - const MIGRATION_TABLE = "_migration"; - const MIGRATION_COLS = [ - "channel" => "varchar not null", - "name" => "varchar not null", - "done" => "integer not null default 0", - "primary key (channel, name)", - ]; - const MIGRATION = null; function __construct($migrations, string $channel="", ?IDatabase $db=null) { @@ -30,10 +22,15 @@ abstract class _migration { protected string $channel; - /** @var callable[]|string[] */ - protected $migrations; + const MIGRATION_TABLE = "_migration"; + const MIGRATION_COLS = [ + "channel" => "varchar not null", + "name" => "varchar not null", + "done" => "integer not null default 0", + "primary key (channel, name)", + ]; - function ensureTable(): void { + protected function ensureTable(): void { $this->db->exec([ "create table if not exists", "table" => static::MIGRATION_TABLE, @@ -55,6 +52,9 @@ abstract class _migration { abstract protected function setMigrated(string $name, bool $done): void; + /** @var callable[]|string[] */ + protected $migrations; + function migrate(?IDatabase $db=null): void { $db = ($this->db ??= $db); $this->ensureTable(); diff --git a/php/src/db/mysql/_mysqlMigration.php b/php/src/db/mysql/_mysqlMigration.php index ab107de..2d63db1 100644 --- a/php/src/db/mysql/_mysqlMigration.php +++ b/php/src/db/mysql/_mysqlMigration.php @@ -4,6 +4,11 @@ namespace nulib\db\mysql; use nulib\db\_private\_migration; class _mysqlMigration extends _migration { + static function with($migration): self { + if ($migration instanceof self) return $migration; + else return new static($migration); + } + const MIGRATION_COLS = [ "channel" => "varchar(64) not null", "name" => "varchar(64) not null", @@ -11,11 +16,6 @@ class _mysqlMigration extends _migration { "primary key (channel, name)", ]; - static function with($migration): self { - if ($migration instanceof self) return $migration; - else return new static($migration); - } - protected function setMigrated(string $name, bool $done): void { $this->db->exec([ "insert", diff --git a/php/src/db/pgsql/PgsqlStorage.php b/php/src/db/pgsql/PgsqlStorage.php index e7560da..d9ec58a 100644 --- a/php/src/db/pgsql/PgsqlStorage.php +++ b/php/src/db/pgsql/PgsqlStorage.php @@ -37,7 +37,7 @@ class PgsqlStorage extends CapacitorStorage { protected function _addToChannelsSql(CapacitorChannel $channel): array { return cl::merge(parent::_addToChannelsSql($channel), [ - "suffix" => "on conflict do nothing", + "suffix" => "on conflict (name) do nothing", ]); } diff --git a/php/src/db/sqlite/SqliteStorage.php b/php/src/db/sqlite/SqliteStorage.php index b63cac9..1f09520 100644 --- a/php/src/db/sqlite/SqliteStorage.php +++ b/php/src/db/sqlite/SqliteStorage.php @@ -53,7 +53,7 @@ class SqliteStorage extends CapacitorStorage { } protected function _addToChannelsSql(CapacitorChannel $channel): array { - return cl::merge(parent::_createChannelsSql(), [ + return cl::merge(parent::_addToChannelsSql($channel), [ "suffix" => "on conflict ignore", ]); }