mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-10 08:04:36 -06:00
Ensure default values are honoured when adding/editing columns. Fixes #1860
This commit is contained in:
parent
d26337a1ba
commit
137bae1b04
@ -8,7 +8,7 @@ CREATE FOREIGN TABLE {{ conn|qtIdent(data.basensp, data.name) }}(
|
||||
{% for o in c.coloptions %}{% if o.option and o.value %}
|
||||
{% if loop.first %} OPTIONS ({% endif %}{% if not loop.first %}, {% endif %}{{o.option}} {{o.value|qtLiteral}}{% if loop.last %}){% endif %}{% endif %}
|
||||
{% endfor %}{% endif %}{% if c.attnotnull %}
|
||||
NOT NULL{% else %} NULL{% endif %}{% if c.typdefault %}
|
||||
NOT NULL{% else %} NULL{% endif %}{% if c.typdefault is defined and c.typdefault is not none %}
|
||||
DEFAULT {{c.typdefault}}{% endif %}{% if c.collname %}
|
||||
COLLATE {{c.collname}}{% endif %}
|
||||
{% if not loop.last %},
|
||||
|
@ -29,7 +29,7 @@ ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }}
|
||||
{% if loop.first %} OPTIONS ({% endif %}{% if not loop.first %}, {% endif %}{{o.option}} {{o.value|qtLiteral}}{% if loop.last %}){% endif %}{% endif %}
|
||||
{% endfor %}{% endif %}
|
||||
{% if c.attnotnull %} NOT NULL{% else %} NULL{% endif %}
|
||||
{% if c.typdefault %} DEFAULT {{c.typdefault}}{% endif %}
|
||||
{% if c.typdefault is defined and c.typdefault is not none %} DEFAULT {{c.typdefault}}{% endif %}
|
||||
{% if c.collname %} COLLATE {{c.collname}}{% endif %};
|
||||
{% endfor -%}
|
||||
{% for c in data.columns.changed %}
|
||||
@ -51,10 +51,10 @@ c.precision != o_data['columns'][c.attnum]['precision'] %}
|
||||
ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }}
|
||||
ALTER COLUMN {{conn|qtIdent(col_name)}} TYPE {{ conn|qtTypeIdent(c.datatype) }}{% if c.typlen %}({{c.typlen}}{% if c.precision %}, {{c.precision}}{% endif %}){% endif %}{% if c.isArrayType %}[]{% endif %};
|
||||
{% endif %}
|
||||
{% if c.typdefault != o_data['columns'][c.attnum]['typdefault'] %}
|
||||
{% if c.typdefault is defined and c.typdefault != o_data['columns'][c.attnum]['typdefault'] %}
|
||||
|
||||
ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }}
|
||||
ALTER COLUMN {{conn|qtIdent(col_name)}}{% if c.typdefault %} SET DEFAULT {{c.typdefault}}{% else %} DROP DEFAULT{% endif %};
|
||||
ALTER COLUMN {{conn|qtIdent(col_name)}}{% if c.typdefault is defined and c.typdefault != '' %} SET DEFAULT {{c.typdefault}}{% else %} DROP DEFAULT{% endif %};
|
||||
{% endif %}
|
||||
{% if c.attstattarget != o_data['columns'][c.attnum]['attstattarget'] %}
|
||||
|
||||
|
@ -12,7 +12,7 @@ CREATE FOREIGN TABLE {{ conn|qtIdent(data.basensp, data.name) }}(
|
||||
{% if loop.first %} OPTIONS ({% endif %}{% if not loop.first %}, {% endif %}{{o.option}} {{o.value|qtLiteral}}{% if loop.last %}){% endif %}{% endif %}
|
||||
{% endfor %}{% endif %}
|
||||
{% if c.attnotnull %} NOT NULL{% else %} NULL{% endif %}
|
||||
{% if c.typdefault %} DEFAULT {{c.typdefault}}{% endif %}
|
||||
{% if c.typdefault is defined and c.typdefault is not none %} DEFAULT {{c.typdefault}}{% endif %}
|
||||
{% if c.collname %} COLLATE {{c.collname}}{% endif %}
|
||||
{% if not loop.last %},
|
||||
{% endif %}
|
||||
|
@ -29,7 +29,7 @@ ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }}
|
||||
{% if loop.first %} OPTIONS ({% endif %}{% if not loop.first %}, {% endif %}{{o.option}} {{o.value|qtLiteral}}{% if loop.last %}){% endif %}{% endif %}
|
||||
{% endfor %}{% endif %}
|
||||
{% if c.attnotnull %} NOT NULL{% else %} NULL{% endif %}
|
||||
{% if c.typdefault %} DEFAULT {{c.typdefault}}{% endif %}
|
||||
{% if c.typdefault is defined and c.typdefault is not none %} DEFAULT {{c.typdefault}}{% endif %}
|
||||
{% if c.collname %} COLLATE {{c.collname}}{% endif %};
|
||||
{% endif %}
|
||||
{% endfor -%}
|
||||
@ -52,10 +52,10 @@ c.precision != o_data['columns'][c.attnum]['precision'] %}
|
||||
ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }}
|
||||
ALTER COLUMN {{conn|qtIdent(col_name)}} TYPE {{ conn|qtTypeIdent(c.datatype) }}{% if c.typlen %}({{c.typlen}}{% if c.precision %}, {{c.precision}}{% endif %}){% endif %}{% if c.isArrayType %}[]{% endif %};
|
||||
{% endif %}
|
||||
{% if c.typdefault != o_data['columns'][c.attnum]['typdefault'] %}
|
||||
{% if c.typdefault is defined and c.typdefault != o_data['columns'][c.attnum]['typdefault'] %}
|
||||
|
||||
ALTER FOREIGN TABLE {{ conn|qtIdent(o_data.basensp, name) }}
|
||||
ALTER COLUMN {{conn|qtIdent(col_name)}}{% if c.typdefault %} SET DEFAULT {{c.typdefault}}{% else %} DROP DEFAULT{% endif %};
|
||||
ALTER COLUMN {{conn|qtIdent(col_name)}}{% if c.typdefault is defined and c.typdefault != '' %} SET DEFAULT {{c.typdefault}}{% else %} DROP DEFAULT{% endif %};
|
||||
{% endif %}
|
||||
{% if c.attstattarget != o_data['columns'][c.attnum]['attstattarget'] %}
|
||||
|
||||
|
@ -15,7 +15,7 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
|
||||
COLLATE {{data.collspcname}}{% endif %};
|
||||
{% endif %}
|
||||
{### Alter column default value ###}
|
||||
{% if data.defval and data.defval != o_data.defval %}
|
||||
{% if data.defval is defined and data.defval is not none and data.defval != '' and data.defval != o_data.defval %}
|
||||
ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
|
||||
ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} SET DEFAULT {{data.defval}};
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
|
||||
ADD COLUMN {{conn|qtIdent(data.name)}} {% if is_sql %}{{data.displaytypname}}{% else %}{{ GET_TYPE.CREATE_TYPE_SQL(conn, data.cltype, data.attlen, data.attprecision, data.hasSqrBracket) }}{% endif %}{% if data.collspcname %}
|
||||
COLLATE {{data.collspcname}}{% endif %}{% if data.attnotnull %}
|
||||
NOT NULL{% endif %}{% if data.defval %}
|
||||
NOT NULL{% endif %}{% if data.defval is defined and data.defval is not none %}
|
||||
DEFAULT {{data.defval}}{% endif %};
|
||||
|
||||
{% endif %}
|
||||
|
@ -15,7 +15,7 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
|
||||
COLLATE {{data.collspcname}}{% endif %};
|
||||
{% endif %}
|
||||
{### Alter column default value ###}
|
||||
{% if data.defval and data.defval != o_data.defval %}
|
||||
{% if data.defval is defined and data.defval is not none and data.defval != '' and data.defval != o_data.defval %}
|
||||
ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
|
||||
ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} SET DEFAULT {{data.defval}};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user