Skip to content

Commit

Permalink
Fix database command warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Sep 1, 2025
1 parent a398624 commit bcce9d3
Showing 1 changed file with 39 additions and 35 deletions.
74 changes: 39 additions & 35 deletions app/src/Lib/Util/SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,40 +46,6 @@
class SchemaManager {
use \App\Lib\Traits\LabeledLogTrait;

/**
* Resolve a PostgreSQL constraint's owning table (schema-qualified) by constraint name.
* Returns null if the given name is not found as a constraint.
*/
protected function resolvePgConstraintTable(string $constraintName): ?string {
if($this->conn->driver !== 'Cake\\Database\\Driver\\Postgres') {
return null;
}

// Query pg catalogs to find the table for this constraint name
// We return schema-qualified name: schema.table
$sql = <<<CATALOG
SELECT n.nspname AS schema, c.relname AS table
FROM pg_constraint co
JOIN pg_class c ON c.oid = co.conrelid
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE co.conname = :name
LIMIT 1
CATALOG;

try {
$stmt = $this->conn->executeQuery($sql, ['name' => $constraintName]);
$row = $stmt->fetchAssociative();
if(!$row || empty($row['schema']) || empty($row['table'])) {
return null;
}
// Quote/qualify as schema.table (matching how other statements look)
return $row['schema'] . '.' . $row['table'];
} catch(\Throwable $e) {
// On any error, fail open by returning null so caller uses original SQL
return null;
}
}

// Console for output
protected $io = null;

Expand Down Expand Up @@ -449,4 +415,42 @@ protected function processSchema(
// but so far we don't have an example indicating it's needed.
}

}
/**
* Resolve a PostgreSQL constraint's owning table (schema-qualified) by constraint name.
* Returns null if the given name is not found as a constraint.
*
* @param string $constraintName
* @return ?string Schema-qualified table name or null if constraint not found
* @since COmanage Registry v5.2.0
*/

protected function resolvePgConstraintTable(string $constraintName): ?string {
if($this->conn->driver !== 'Cake\\Database\\Driver\\Postgres') {
return null;
}

// Query pg catalogs to find the table for this constraint name
// We return schema-qualified name: schema.table
$sql = <<<CATALOG
SELECT n.nspname AS schema, c.relname AS table
FROM pg_constraint co
JOIN pg_class c ON c.oid = co.conrelid
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE co.conname = :name
LIMIT 1
CATALOG;

try {
$stmt = $this->conn->executeQuery($sql, ['name' => $constraintName]);
$row = $stmt->fetchAssociative();
if(!$row || empty($row['schema']) || empty($row['table'])) {
return null;
}
// Quote/qualify as schema.table (matching how other statements look)
return $row['schema'] . '.' . $row['table'];
} catch(\Throwable $e) {
// On any error, fail open by returning null so caller uses original SQL
return null;
}
}
}

0 comments on commit bcce9d3

Please sign in to comment.