KEA Setup
This commit is contained in:
@@ -98,10 +98,6 @@ final class Database
|
||||
}
|
||||
}
|
||||
|
||||
// After init, ensure our metadata table exists (non-invasive)
|
||||
if (self::tableExists($pdo, 'hosts')) {
|
||||
self::ensureNexusTables($pdo);
|
||||
}
|
||||
}
|
||||
|
||||
private static function tableExists(\PDO $pdo, string $table): bool
|
||||
@@ -179,37 +175,6 @@ final class Database
|
||||
$pdo->exec($sql);
|
||||
}
|
||||
|
||||
private static function ensureNexusTables(\PDO $pdo): void
|
||||
{
|
||||
$pdo->exec(
|
||||
"CREATE TABLE IF NOT EXISTS nexus_host_meta (
|
||||
host_id BIGINT PRIMARY KEY,
|
||||
location TEXT,
|
||||
device_type TEXT,
|
||||
owner TEXT,
|
||||
tags JSONB,
|
||||
notes TEXT,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
)"
|
||||
);
|
||||
|
||||
$pdo->exec(
|
||||
"DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_name = 'fk_nexus_host_meta_host'
|
||||
) THEN
|
||||
ALTER TABLE nexus_host_meta
|
||||
ADD CONSTRAINT fk_nexus_host_meta_host
|
||||
FOREIGN KEY (host_id)
|
||||
REFERENCES hosts(host_id)
|
||||
ON DELETE CASCADE;
|
||||
END IF;
|
||||
END $$;"
|
||||
);
|
||||
}
|
||||
|
||||
private static function buildMysqlDsn(array $db): string
|
||||
{
|
||||
if (empty($db['dbname'])) {
|
||||
|
||||
Reference in New Issue
Block a user