mirror of
https://github.com/vrana/adminer.git
synced 2025-08-12 09:34:10 +02:00
PostgreSQL: Support adding auto_increment (bug #761)
This commit is contained in:
@@ -358,7 +358,6 @@ WHERE relkind IN ('r', 'm', 'v', 'f', 'p')
|
||||
'timestamp without time zone' => 'timestamp',
|
||||
'timestamp with time zone' => 'timestamptz',
|
||||
);
|
||||
|
||||
foreach (get_rows("SELECT a.attname AS field, format_type(a.atttypid, a.atttypmod) AS full_type, pg_get_expr(d.adbin, d.adrelid) AS default, a.attnotnull::int, col_description(c.oid, a.attnum) AS comment" . (min_version(10) ? ", a.attidentity" : "") . "
|
||||
FROM pg_class c
|
||||
JOIN pg_namespace n ON c.relnamespace = n.oid
|
||||
@@ -509,6 +508,7 @@ ORDER BY connamespace, conname") as $row) {
|
||||
if ($table != "" && $table != $name) {
|
||||
$queries[] = "ALTER TABLE " . table($table) . " RENAME TO " . table($name);
|
||||
}
|
||||
$sequence = "";
|
||||
foreach ($fields as $field) {
|
||||
$column = idf_escape($field[0]);
|
||||
$val = $field[1];
|
||||
@@ -530,10 +530,15 @@ ORDER BY connamespace, conname") as $row) {
|
||||
$queries[] = "ALTER TABLE " . table($name) . " RENAME $column TO $val[0]";
|
||||
}
|
||||
$alter[] = "ALTER $column TYPE$val[1]";
|
||||
if (!$val[6]) {
|
||||
$alter[] = "ALTER $column " . ($val[3] ? "SET$val[3]" : "DROP DEFAULT");
|
||||
$alter[] = "ALTER $column " . ($val[2] == " NULL" ? "DROP NOT" : "SET") . $val[2];
|
||||
$sequence_name = $table . "_" . idf_unescape($val[0]) . "_seq";
|
||||
$alter[] = "ALTER $column " . ($val[3] ? "SET$val[3]"
|
||||
: (isset($val[6]) ? "SET DEFAULT nextval(" . q($sequence_name) . ")"
|
||||
: "DROP DEFAULT"
|
||||
));
|
||||
if (isset($val[6])) {
|
||||
$sequence = "CREATE SEQUENCE IF NOT EXISTS " . idf_escape($sequence_name) . " OWNED BY " . idf_escape($table) . ".$val[0]";
|
||||
}
|
||||
$alter[] = "ALTER $column " . ($val[2] == " NULL" ? "DROP NOT" : "SET") . $val[2];
|
||||
}
|
||||
if ($field[0] != "" || $val5 != "") {
|
||||
$queries[] = "COMMENT ON COLUMN " . table($name) . ".$val[0] IS " . ($val5 != "" ? substr($val5, 9) : "''");
|
||||
@@ -546,6 +551,9 @@ ORDER BY connamespace, conname") as $row) {
|
||||
} elseif ($alter) {
|
||||
array_unshift($queries, "ALTER TABLE " . table($table) . "\n" . implode(",\n", $alter));
|
||||
}
|
||||
if ($sequence) {
|
||||
array_unshift($queries, $sequence);
|
||||
}
|
||||
if ($comment !== null) {
|
||||
$queries[] = "COMMENT ON TABLE " . table($name) . " IS " . q($comment);
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ Adminer 4.16.0-dev:
|
||||
MySQL: Fix saving bit(64) values (bug #839)
|
||||
PostgreSQL: Preserve whitespace in EXPLAIN (bug #827)
|
||||
PostgreSQL: Support SSL
|
||||
PostgreSQL: Support dropping auto_increment
|
||||
PostgreSQL: Support altering auto_increment (bug #761)
|
||||
SQLite: Fix altering forign keys (bug #841)
|
||||
SQLite: Fix expressions in default values (bug #860)
|
||||
MS SQL: Foreign keys in non-default schema (bug #833)
|
||||
|
Reference in New Issue
Block a user