Fix foreign key schema
This commit is contained in:
parent
bbe46b7c0d
commit
c91185c435
|
@ -271,7 +271,7 @@ ORDER BY a.attnum"
|
||||||
function foreign_keys($table) {
|
function foreign_keys($table) {
|
||||||
global $on_actions;
|
global $on_actions;
|
||||||
$return = array();
|
$return = array();
|
||||||
foreach (get_rows("SELECT conname, (SELECT nspname FROM pg_namespace WHERE oid = connamespace) AS ns, pg_get_constraintdef(oid) AS definition
|
foreach (get_rows("SELECT conname, pg_get_constraintdef(oid) AS definition
|
||||||
FROM pg_constraint
|
FROM pg_constraint
|
||||||
WHERE conrelid = (SELECT oid FROM pg_class WHERE relname = " . q($table) . ")
|
WHERE conrelid = (SELECT oid FROM pg_class WHERE relname = " . q($table) . ")
|
||||||
AND contype = 'f'::char
|
AND contype = 'f'::char
|
||||||
|
@ -279,6 +279,10 @@ ORDER BY conkey, conname") as $row) {
|
||||||
if (preg_match('~FOREIGN KEY\s*\((.+)\)\s*REFERENCES (.+)\((.+)\)(.*)$~iA', $row['definition'], $match)) {
|
if (preg_match('~FOREIGN KEY\s*\((.+)\)\s*REFERENCES (.+)\((.+)\)(.*)$~iA', $row['definition'], $match)) {
|
||||||
$row['source'] = array_map('trim', explode(',', $match[1]));
|
$row['source'] = array_map('trim', explode(',', $match[1]));
|
||||||
$row['table'] = $match[2];
|
$row['table'] = $match[2];
|
||||||
|
if (preg_match('~(.+)\.(.+)~', $match[2], $match2)) {
|
||||||
|
$row['ns'] = $match2[1];
|
||||||
|
$row['table'] = $match2[2];
|
||||||
|
}
|
||||||
$row['target'] = array_map('trim', explode(',', $match[3]));
|
$row['target'] = array_map('trim', explode(',', $match[3]));
|
||||||
$row['on_delete'] = (preg_match('~ON DELETE (' . implode('|', $on_actions) . ')~', $match[4], $match2) ? $match2[1] : '');
|
$row['on_delete'] = (preg_match('~ON DELETE (' . implode('|', $on_actions) . ')~', $match[4], $match2) ? $match2[1] : '');
|
||||||
$row['on_update'] = (preg_match('~ON UPDATE (' . implode('|', $on_actions) . ')~', $match[4], $match2) ? $match2[1] : '');
|
$row['on_update'] = (preg_match('~ON UPDATE (' . implode('|', $on_actions) . ')~', $match[4], $match2) ? $match2[1] : '');
|
||||||
|
|
Loading…
Reference in a new issue