modifs.mineures sans commentaires
This commit is contained in:
parent
146461a184
commit
2a50167241
@ -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();
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -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",
|
||||
]);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user