Ensure that the user will be able to modify the start value of the Identity column. Fixes #5632

This commit is contained in:
Rahul Shirsat 2020-07-29 16:22:11 +05:30 committed by Akshay Joshi
parent 287a6628ed
commit 74fd5dfe96
22 changed files with 429 additions and 100 deletions

1
.gitignore vendored
View File

@ -50,3 +50,4 @@ web/yarn-error.log
auditjs.html
auditpy.txt
/venv/
.scannerwork/

View File

@ -24,5 +24,6 @@ Bug fixes
| `Issue #4810 <https://redmine.postgresql.org/issues/4810>`_ - Fixed an issue where the user is not able to save the new row if the table is empty.
| `Issue #5490 <https://redmine.postgresql.org/issues/5490>`_ - Make the runtime configuration dialog non-modal.
| `Issue #5632 <https://redmine.postgresql.org/issues/5632>`_ - Ensure that the user will be able to modify the start value of the Identity column.
| `Issue #5646 <https://redmine.postgresql.org/issues/5646>`_ - Ensure that RLS Policy node should be searchable using search object.
| `Issue #5708 <https://redmine.postgresql.org/issues/5708>`_ - Correct TLS certificate filename in the container deployment docs.

View File

@ -604,6 +604,8 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
gettext("Could not find the column on the server.")
)
old_data = dict(res['rows'][0])
if 'seqcycle' in old_data and old_data['seqcycle'] is False:
old_data['seqcycle'] = None
# We will add table & schema as well
old_data = column_utils.column_formatter(
self.conn, tid, clid, old_data)

View File

@ -599,10 +599,8 @@ define('pgadmin.node.column', [
visible: 'isTypeIdentity',
},{
id: 'seqstart', label: gettext('Start'), type: 'int',
mode: ['properties', 'create'], group: gettext('Constraints'),
mode: ['properties', 'create', 'edit'], group: gettext('Constraints'),
disabled: function(m) {
if (!m.isNew())
return true;
let isIdentity = m.get('attidentity');
if(!_.isUndefined(isIdentity) && !_.isNull(isIdentity) && !_.isEmpty(isIdentity))
return false;

View File

@ -2,7 +2,7 @@ ALTER TABLE testschema."table_2_$%{}[]()&*^!@""'`\/#"
RENAME "col_5_$%{}[]()&*^!@""'`\/#" TO "new_col_5_$%{}[]()&*^!@""'`\/#";
ALTER TABLE testschema."table_2_$%{}[]()&*^!@""'`\/#"
ALTER COLUMN "new_col_5_$%{}[]()&*^!@""'`\/#" SET CYCLE SET INCREMENT 2 SET MINVALUE 1 SET MAXVALUE 200 SET CACHE 2 ;
ALTER COLUMN "new_col_5_$%{}[]()&*^!@""'`\/#" SET CYCLE SET INCREMENT 2 SET MINVALUE 1 SET MAXVALUE 200 SET CACHE 2;
COMMENT ON COLUMN testschema."table_2_$%{}[]()&*^!@""'`\/#"."new_col_5_$%{}[]()&*^!@""'`\/#"
IS 'Comment for alter';
IS 'Comment for alter';

View File

@ -0,0 +1,2 @@
ALTER TABLE testschema."table_2_$%{}[]()&*^!@""'`\/#"
ALTER COLUMN "col_6_$%{}[]()&*^!@""'`\/#" SET CYCLE SET INCREMENT 3 RESTART SET START 3 SET MINVALUE 3 SET MAXVALUE 30 SET CACHE 3;

View File

@ -0,0 +1,9 @@
-- Column: testschema."table_2_$%{}[]()&*^!@""'`\/#"."col_6_$%{}[]()&*^!@""'`\/#"
-- ALTER TABLE testschema."table_2_$%{}[]()&*^!@""'`\/#" DROP COLUMN "col_6_$%{}[]()&*^!@""'`\/#";
ALTER TABLE testschema."table_2_$%{}[]()&*^!@""'`\/#"
ADD COLUMN "col_6_$%{}[]()&*^!@""'`\/#" bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( CYCLE INCREMENT 3 START 3 MINVALUE 3 MAXVALUE 30 CACHE 3 );
COMMENT ON COLUMN testschema."table_2_$%{}[]()&*^!@""'`\/#"."col_6_$%{}[]()&*^!@""'`\/#"
IS 'demo comments';

View File

@ -0,0 +1,2 @@
ALTER TABLE testschema."table_2_$%{}[]()&*^!@""'`\/#"
ALTER COLUMN "col_6_$%{}[]()&*^!@""'`\/#" SET GENERATED ALWAYS SET NO CYCLE RESTART SET START 2;

View File

@ -0,0 +1,9 @@
-- Column: testschema."table_2_$%{}[]()&*^!@""'`\/#"."col_6_$%{}[]()&*^!@""'`\/#"
-- ALTER TABLE testschema."table_2_$%{}[]()&*^!@""'`\/#" DROP COLUMN "col_6_$%{}[]()&*^!@""'`\/#";
ALTER TABLE testschema."table_2_$%{}[]()&*^!@""'`\/#"
ADD COLUMN "col_6_$%{}[]()&*^!@""'`\/#" bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 2 MINVALUE 1 MAXVALUE 10 CACHE 1 );
COMMENT ON COLUMN testschema."table_2_$%{}[]()&*^!@""'`\/#"."col_6_$%{}[]()&*^!@""'`\/#"
IS 'demo comments';

View File

@ -0,0 +1,5 @@
ALTER TABLE testschema."table_2_$%{}[]()&*^!@""'`\/#"
ADD COLUMN "col_6_$%{}[]()&*^!@""'`\/#" bigint(None, None) NOT NULL GENERATED BY DEFAULT AS IDENTITY ( CYCLE INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 10 CACHE 1 );
COMMENT ON COLUMN testschema."table_2_$%{}[]()&*^!@""'`\/#"."col_6_$%{}[]()&*^!@""'`\/#"
IS 'demo comments';

View File

@ -0,0 +1,9 @@
-- Column: testschema."table_2_$%{}[]()&*^!@""'`\/#"."col_6_$%{}[]()&*^!@""'`\/#"
-- ALTER TABLE testschema."table_2_$%{}[]()&*^!@""'`\/#" DROP COLUMN "col_6_$%{}[]()&*^!@""'`\/#";
ALTER TABLE testschema."table_2_$%{}[]()&*^!@""'`\/#"
ADD COLUMN "col_6_$%{}[]()&*^!@""'`\/#" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( CYCLE INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 10 CACHE 1 );
COMMENT ON COLUMN testschema."table_2_$%{}[]()&*^!@""'`\/#"."col_6_$%{}[]()&*^!@""'`\/#"
IS 'demo comments';

View File

@ -22,15 +22,15 @@
"data": {
"name": "col_1_$%{}[]()&*^!@\"'`\\/#",
"description": "Comment for create",
"cltype":"bigint",
"attacl":[],
"is_primary_key":false,
"attnotnull":true,
"attlen":null,
"attprecision":null,
"attoptions":[],
"seclabels":[],
"defval":"1"
"cltype": "bigint",
"attacl": [],
"is_primary_key": false,
"attnotnull": true,
"attlen": null,
"attprecision": null,
"attoptions": [],
"seclabels": [],
"defval": "1"
},
"expected_sql_file": "create_column_int.sql",
"expected_msql_file": "create_column_int.msql"
@ -45,8 +45,37 @@
"attnum": 1,
"name": "new_col_1_$%{}[]()&*^!@\"'`\\/#",
"description": "Comment for alter",
"cltype":"real",
"attacl":{"added":[{"grantee":"PUBLIC","grantor":"postgres","privileges":[{"privilege_type":"a","privilege":true,"with_grant":false},{"privilege_type":"r","privilege":true,"with_grant":false},{"privilege_type":"w","privilege":true,"with_grant":false},{"privilege_type":"x","privilege":true,"with_grant":false}]}]}
"cltype": "real",
"attacl": {
"added": [
{
"grantee": "PUBLIC",
"grantor": "postgres",
"privileges": [
{
"privilege_type": "a",
"privilege": true,
"with_grant": false
},
{
"privilege_type": "r",
"privilege": true,
"with_grant": false
},
{
"privilege_type": "w",
"privilege": true,
"with_grant": false
},
{
"privilege_type": "x",
"privilege": true,
"with_grant": false
}
]
}
]
}
},
"expected_sql_file": "alter_column_int.sql",
"expected_msql_file": "alter_column_int.msql"
@ -69,16 +98,16 @@
"data": {
"name": "col_2_$%{}[]()&*^!@\"'`\\/#",
"description": "Comment for create",
"cltype":"character varying",
"cltype": "character varying",
"collspcname": "pg_catalog.\"C\"",
"attacl":[],
"is_primary_key":false,
"attnotnull":false,
"attlen":"50",
"attprecision":null,
"attoptions":[],
"seclabels":[],
"defval":null
"attacl": [],
"is_primary_key": false,
"attnotnull": false,
"attlen": "50",
"attprecision": null,
"attoptions": [],
"seclabels": [],
"defval": null
},
"expected_sql_file": "create_column_char.sql",
"expected_msql_file": "create_column_char.msql"
@ -96,8 +125,32 @@
"attstattarget": "5",
"attstorage": "p",
"description": "Comment for alter",
"cltype":"character",
"attacl":{"added":[{"grantee":"PUBLIC","grantor":"postgres","privileges":[{"privilege_type":"a","privilege":true,"with_grant":false},{"privilege_type":"r","privilege":true,"with_grant":false},{"privilege_type":"x","privilege":true,"with_grant":false}]}]}
"cltype": "character",
"attacl": {
"added": [
{
"grantee": "PUBLIC",
"grantor": "postgres",
"privileges": [
{
"privilege_type": "a",
"privilege": true,
"with_grant": false
},
{
"privilege_type": "r",
"privilege": true,
"with_grant": false
},
{
"privilege_type": "x",
"privilege": true,
"with_grant": false
}
]
}
]
}
},
"expected_sql_file": "alter_column_char.sql",
"expected_msql_file": "alter_column_char.msql"
@ -120,22 +173,22 @@
"data": {
"name": "col_3_$%{}[]()&*^!@\"'`\\/#",
"description": "Comment for create",
"cltype":"bigint",
"attacl":[],
"is_primary_key":false,
"attnotnull":true,
"attlen":null,
"attprecision":null,
"attoptions":[],
"seclabels":[],
"attidentity":"a",
"seqincrement":"1",
"seqstart":"1",
"seqmin":"1",
"seqmax":"99999",
"seqcache":"10",
"seqcycle":true,
"colconstype":"i"
"cltype": "bigint",
"attacl": [],
"is_primary_key": false,
"attnotnull": true,
"attlen": null,
"attprecision": null,
"attoptions": [],
"seclabels": [],
"attidentity": "a",
"seqincrement": "1",
"seqstart": "1",
"seqmin": "1",
"seqmax": "99999",
"seqcache": "10",
"seqcycle": true,
"colconstype": "i"
},
"expected_sql_file": "create_column_int_identity.sql",
"expected_msql_file": "create_column_int_identity.msql"
@ -150,7 +203,31 @@
"attnum": 3,
"name": "new_col_3_$%{}[]()&*^!@\"'`\\/#",
"description": "Comment for alter",
"attacl":{"added":[{"grantee":"PUBLIC","grantor":"postgres","privileges":[{"privilege_type":"a","privilege":true,"with_grant":false},{"privilege_type":"r","privilege":true,"with_grant":false},{"privilege_type":"x","privilege":true,"with_grant":false}]}]}
"attacl": {
"added": [
{
"grantee": "PUBLIC",
"grantor": "postgres",
"privileges": [
{
"privilege_type": "a",
"privilege": true,
"with_grant": false
},
{
"privilege_type": "r",
"privilege": true,
"with_grant": false
},
{
"privilege_type": "x",
"privilege": true,
"with_grant": false
}
]
}
]
}
},
"expected_sql_file": "alter_column_identity.sql",
"expected_msql_file": "alter_column_identity.msql"
@ -177,7 +254,6 @@
"name": "new_col_3_$%{}[]()&*^!@\"'`\\/#"
}
},
{
"type": "create",
"name": "Create Column (Numeric type with Length Precision & Variables)",
@ -187,17 +263,22 @@
"data": {
"name": "col_4_$%{}[]()&*^!@\"'`\\/#",
"description": "Comment for create",
"min_val":0,
"max_val":1000,
"cltype":"numeric",
"attacl":[],
"is_primary_key":false,
"attnotnull":true,
"attlen":"10",
"attprecision":"5",
"attidentity":"a",
"attoptions":[{"name":"n_distinct","value":"1"}],
"seclabels":[]
"min_val": 0,
"max_val": 1000,
"cltype": "numeric",
"attacl": [],
"is_primary_key": false,
"attnotnull": true,
"attlen": "10",
"attprecision": "5",
"attidentity": "a",
"attoptions": [
{
"name": "n_distinct",
"value": "1"
}
],
"seclabels": []
},
"expected_sql_file": "create_column_numeric.sql",
"expected_msql_file": "create_column_numeric.msql"
@ -211,10 +292,39 @@
"data": {
"name": "new_col_4_$%{}[]()&*^!@\"'`\\/#",
"attnum": 4,
"attlen":"15",
"attprecision":"6",
"attlen": "15",
"attprecision": "6",
"description": "Comment for alter",
"attacl":{"added":[{"grantee":"PUBLIC","grantor":"postgres","privileges":[{"privilege_type":"a","privilege":true,"with_grant":false},{"privilege_type":"r","privilege":true,"with_grant":false},{"privilege_type":"w","privilege":true,"with_grant":false},{"privilege_type":"x","privilege":true,"with_grant":false}]}]}
"attacl": {
"added": [
{
"grantee": "PUBLIC",
"grantor": "postgres",
"privileges": [
{
"privilege_type": "a",
"privilege": true,
"with_grant": false
},
{
"privilege_type": "r",
"privilege": true,
"with_grant": false
},
{
"privilege_type": "w",
"privilege": true,
"with_grant": false
},
{
"privilege_type": "x",
"privilege": true,
"with_grant": false
}
]
}
]
}
},
"expected_sql_file": "alter_column_numeric.sql",
"expected_msql_file": "alter_column_numeric.msql"
@ -227,7 +337,7 @@
"msql_endpoint": "NODE-column.msql_id",
"data": {
"attnum": 3,
"attlen":""
"attlen": ""
},
"expected_sql_file": "alter_column_remove_length.sql",
"expected_msql_file": "alter_column_remove_length.msql"
@ -241,7 +351,6 @@
"name": "new_col_4_$%{}[]()&*^!@\"'`\\/#"
}
},
{
"type": "create",
"name": "Create Column with identity (Generated by default)",
@ -251,22 +360,22 @@
"data": {
"name": "col_5_$%{}[]()&*^!@\"'`\\/#",
"description": "Comment for create",
"cltype":"bigint",
"attacl":[],
"is_primary_key":false,
"attnotnull":true,
"attlen":null,
"attprecision":null,
"attoptions":[],
"seclabels":[],
"attidentity":"d",
"seqincrement":"1",
"seqstart":"1",
"seqmin":"1",
"seqmax":"99999",
"seqcache":"10",
"seqcycle":true,
"colconstype":"i"
"cltype": "bigint",
"attacl": [],
"is_primary_key": false,
"attnotnull": true,
"attlen": null,
"attprecision": null,
"attoptions": [],
"seclabels": [],
"attidentity": "d",
"seqincrement": "1",
"seqstart": "1",
"seqmin": "1",
"seqmax": "99999",
"seqcache": "10",
"seqcycle": true,
"colconstype": "i"
},
"expected_sql_file": "create_column_int_identity_by_default.sql",
"expected_msql_file": "create_column_int_identity_by_default.msql"
@ -281,11 +390,11 @@
"attnum": 5,
"name": "new_col_5_$%{}[]()&*^!@\"'`\\/#",
"description": "Comment for alter",
"seqincrement":"2",
"seqmax":"200",
"seqcache":"2",
"seqcycle":true,
"seqmin":"1"
"seqincrement": "2",
"seqmax": "200",
"seqcache": "2",
"seqcycle": true,
"seqmin": "1"
},
"expected_sql_file": "alter_column_identity_by_default.sql",
"expected_msql_file": "alter_column_identity_by_default.msql"
@ -311,6 +420,78 @@
"data": {
"name": "new_col_5_$%{}[]()&*^!@\"'`\\/#"
}
},
{
"type": "create",
"name": "Create Column with identity (BY DEFAULT) for combination of identity options & initiate START",
"endpoint": "NODE-column.obj",
"sql_endpoint": "NODE-column.sql_id",
"msql_endpoint": "NODE-column.msql",
"data": {
"name": "col_6_$%{}[]()&*^!@\"'`\\/#",
"cltype": "bigint",
"attacl": [],
"description": "demo comments",
"is_primary_key": false,
"attnotnull": true,
"attlen": null,
"attprecision": null,
"attidentity": "d",
"seqincrement": "1",
"seqstart": "1",
"seqmin": "1",
"seqmax": "10",
"seqcache": "1",
"seqcycle": true,
"colconstype": "i",
"attoptions": [],
"seclabels": []
},
"expected_sql_file": "create_column_identity_for_restart_seq.sql",
"expected_msql_file": "create_column_identity_for_restart_seq.msql"
},
{
"type": "alter",
"name": "Alter identity Column (BY DEFAULT) to ALWAYS & Update START",
"endpoint": "NODE-column.obj_id",
"sql_endpoint": "NODE-column.sql_id",
"msql_endpoint": "NODE-column.msql_id",
"data": {
"attnotnull": true,
"attidentity": "a",
"seqstart": 2,
"seqcycle": false
},
"expected_sql_file": "alter_column_identity_for_restart_seq.sql",
"expected_msql_file": "alter_column_identity_for_restart_seq.msql"
},
{
"type": "alter",
"name": "Alter identity Column (ALWAYS) for combination of identity options & Update START",
"endpoint": "NODE-column.obj_id",
"sql_endpoint": "NODE-column.sql_id",
"msql_endpoint": "NODE-column.msql_id",
"data": {
"attnum": 9,
"attidentity": "a",
"seqincrement": "3",
"seqstart": "3",
"seqmin": "3",
"seqmax": "30",
"seqcache": "3",
"seqcycle": true
},
"expected_sql_file": "alter_column_identity_for_comb_start_seq.sql",
"expected_msql_file": "alter_column_identity_for_comb_start_seq.msql"
},
{
"type": "delete",
"name": "Drop Column with identity (ALWAYS)",
"endpoint": "NODE-column.obj_id",
"sql_endpoint": "NODE-column.sql_id",
"data": {
"name": "col_6_$%{}[]()&*^!@\"'`\\/#"
}
}
]
}

View File

@ -2,7 +2,7 @@ ALTER TABLE testschema."table_3_$%{}[]()&*^!@""'`\/#"
RENAME "col_9_$%{}[]()&*^!@""'`\/#" TO "new_col_9_$%{}[]()&*^!@""'`\/#";
ALTER TABLE testschema."table_3_$%{}[]()&*^!@""'`\/#"
ALTER COLUMN "new_col_9_$%{}[]()&*^!@""'`\/#" SET CYCLE SET INCREMENT 2 SET MINVALUE 1 SET MAXVALUE 200 SET CACHE 2 ;
ALTER COLUMN "new_col_9_$%{}[]()&*^!@""'`\/#" SET CYCLE SET INCREMENT 2 SET MINVALUE 1 SET MAXVALUE 200 SET CACHE 2;
COMMENT ON COLUMN testschema."table_3_$%{}[]()&*^!@""'`\/#"."new_col_9_$%{}[]()&*^!@""'`\/#"
IS 'Comment for alter';
IS 'Comment for alter';

View File

@ -0,0 +1,2 @@
ALTER TABLE testschema."table_3_$%{}[]()&*^!@""'`\/#"
ALTER COLUMN "col_6_$%{}[]()&*^!@""'`\/#" SET CYCLE SET INCREMENT 3 RESTART SET START 3 SET MINVALUE 3 SET MAXVALUE 30 SET CACHE 3;

View File

@ -0,0 +1,9 @@
-- Column: testschema."table_3_$%{}[]()&*^!@""'`\/#"."col_6_$%{}[]()&*^!@""'`\/#"
-- ALTER TABLE testschema."table_3_$%{}[]()&*^!@""'`\/#" DROP COLUMN "col_6_$%{}[]()&*^!@""'`\/#";
ALTER TABLE testschema."table_3_$%{}[]()&*^!@""'`\/#"
ADD COLUMN "col_6_$%{}[]()&*^!@""'`\/#" bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( CYCLE INCREMENT 3 START 3 MINVALUE 3 MAXVALUE 30 CACHE 3 );
COMMENT ON COLUMN testschema."table_3_$%{}[]()&*^!@""'`\/#"."col_6_$%{}[]()&*^!@""'`\/#"
IS 'demo comments';

View File

@ -0,0 +1,2 @@
ALTER TABLE testschema."table_3_$%{}[]()&*^!@""'`\/#"
ALTER COLUMN "col_6_$%{}[]()&*^!@""'`\/#" SET GENERATED ALWAYS SET NO CYCLE RESTART SET START 2;

View File

@ -0,0 +1,9 @@
-- Column: testschema."table_3_$%{}[]()&*^!@""'`\/#"."col_6_$%{}[]()&*^!@""'`\/#"
-- ALTER TABLE testschema."table_3_$%{}[]()&*^!@""'`\/#" DROP COLUMN "col_6_$%{}[]()&*^!@""'`\/#";
ALTER TABLE testschema."table_3_$%{}[]()&*^!@""'`\/#"
ADD COLUMN "col_6_$%{}[]()&*^!@""'`\/#" bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 2 MINVALUE 1 MAXVALUE 10 CACHE 1 );
COMMENT ON COLUMN testschema."table_3_$%{}[]()&*^!@""'`\/#"."col_6_$%{}[]()&*^!@""'`\/#"
IS 'demo comments';

View File

@ -0,0 +1,5 @@
ALTER TABLE testschema."table_3_$%{}[]()&*^!@""'`\/#"
ADD COLUMN "col_6_$%{}[]()&*^!@""'`\/#" bigint(None, None) NOT NULL GENERATED BY DEFAULT AS IDENTITY ( CYCLE INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 10 CACHE 1 );
COMMENT ON COLUMN testschema."table_3_$%{}[]()&*^!@""'`\/#"."col_6_$%{}[]()&*^!@""'`\/#"
IS 'demo comments';

View File

@ -0,0 +1,9 @@
-- Column: testschema."table_3_$%{}[]()&*^!@""'`\/#"."col_6_$%{}[]()&*^!@""'`\/#"
-- ALTER TABLE testschema."table_3_$%{}[]()&*^!@""'`\/#" DROP COLUMN "col_6_$%{}[]()&*^!@""'`\/#";
ALTER TABLE testschema."table_3_$%{}[]()&*^!@""'`\/#"
ADD COLUMN "col_6_$%{}[]()&*^!@""'`\/#" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( CYCLE INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 10 CACHE 1 );
COMMENT ON COLUMN testschema."table_3_$%{}[]()&*^!@""'`\/#"."col_6_$%{}[]()&*^!@""'`\/#"
IS 'demo comments';

View File

@ -448,7 +448,78 @@
"data": {
"name": "new_col_9_$%{}[]()&*^!@\"'`\\/#"
}
},
{
"type": "create",
"name": "Create Column with identity (BY DEFAULT) for combination of identity options & initiate START",
"endpoint": "NODE-column.obj",
"sql_endpoint": "NODE-column.sql_id",
"msql_endpoint": "NODE-column.msql",
"data": {
"name": "col_6_$%{}[]()&*^!@\"'`\\/#",
"cltype": "bigint",
"attacl": [],
"description": "demo comments",
"is_primary_key": false,
"attnotnull": true,
"attlen": null,
"attprecision": null,
"attidentity": "d",
"seqincrement": "1",
"seqstart": "1",
"seqmin": "1",
"seqmax": "10",
"seqcache": "1",
"seqcycle": true,
"colconstype": "i",
"attoptions": [],
"seclabels": []
},
"expected_sql_file": "create_column_identity_for_restart_seq.sql",
"expected_msql_file": "create_column_identity_for_restart_seq.msql"
},
{
"type": "alter",
"name": "Alter identity Column (BY DEFAULT) to ALWAYS & Update START",
"endpoint": "NODE-column.obj_id",
"sql_endpoint": "NODE-column.sql_id",
"msql_endpoint": "NODE-column.msql_id",
"data": {
"attnotnull": true,
"attidentity": "a",
"seqstart": 2,
"seqcycle": false
},
"expected_sql_file": "alter_column_identity_for_restart_seq.sql",
"expected_msql_file": "alter_column_identity_for_restart_seq.msql"
},
{
"type": "alter",
"name": "Alter identity Column (ALWAYS) for combination of identity options & Update START",
"endpoint": "NODE-column.obj_id",
"sql_endpoint": "NODE-column.sql_id",
"msql_endpoint": "NODE-column.msql_id",
"data": {
"attnum": 9,
"attidentity": "a",
"seqincrement": "3",
"seqstart": "3",
"seqmin": "3",
"seqmax": "30",
"seqcache": "3",
"seqcycle": true
},
"expected_sql_file": "alter_column_identity_for_comb_start_seq.sql",
"expected_msql_file": "alter_column_identity_for_comb_start_seq.msql"
},
{
"type": "delete",
"name": "Drop Column with identity (ALWAYS)",
"endpoint": "NODE-column.obj_id",
"sql_endpoint": "NODE-column.sql_id",
"data": {
"name": "col_6_$%{}[]()&*^!@\"'`\\/#"
}
}
]
}

View File

@ -47,6 +47,7 @@ class ColumnPutTestCase(BaseTestGenerator):
'seqmin': 1,
'seqmax': 10,
'seqcache': 1,
'colconstype': 'i',
'seqcycle': True
})),
('Edit column to Identity column as Default', dict(
@ -63,6 +64,7 @@ class ColumnPutTestCase(BaseTestGenerator):
'seqmin': 2,
'seqmax': 2000,
'seqcache': 1,
'colconstype': 'i',
'seqcycle': True
})),
('Edit column Drop Identity by changing constraint type to NONE',

View File

@ -38,6 +38,9 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} {% if data.attnotnull %}SET{% else %}DROP{% endif %} NOT NULL;
{% endif %}
{% if data.seqincrement or (data.seqcycle or (data.seqcycle == False and data.seqcycle != o_data.seqcycle)) or data.seqincrement or data.seqstart or data.seqmin or data.seqmax or data.seqcache %}
{% set attidentity_params = true %}{% else %}
{% set attidentity_params = false %}{% endif %}
{### Alter column - add identity ###}
{% if data.colconstype == 'i' and 'attidentity' in data and o_data.attidentity == '' and data.attidentity != o_data.attidentity %}
ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
@ -51,24 +54,22 @@ MINVALUE {{data.seqmin|int}} {% endif %}{% if data.seqmax is defined and data.se
MAXVALUE {{data.seqmax|int}} {% endif %}{% if data.seqcache is defined and data.seqcache|int(-1) > -1%}
CACHE {{data.seqcache|int}} {% endif %}
{% if data.seqincrement or data.seqcycle or data.seqincrement or data.seqstart or data.seqmin or data.seqmax or data.seqcache %}){% endif %};
{% endif %}
{### Alter column - change identity ###}
{### Alter column - change identity - sequence options ###}
{% elif 'attidentity' in data or attidentity_params %}
{% if 'attidentity' in data and data.attidentity != '' and o_data.attidentity != '' and data.attidentity != o_data.attidentity %}
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 GENERATED {% if data.attidentity == 'a' %}ALWAYS{% else%}BY DEFAULT{% endif %};
{% endif %}
{### Alter column - change identity - sequence options ###}
{% if 'attidentity' not in data and (data.seqincrement or data.seqcycle or data.seqincrement or data.seqstart or data.seqmin or data.seqmax or data.seqcache) %}
ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} SET GENERATED {% if data.attidentity == 'a' %}ALWAYS{% else%}BY DEFAULT{% endif %}{% if attidentity_params is false %};{% else %}{% endif %}
{% else %}
ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}} {% else %}{{conn|qtTypeIdent(o_data.name)}} {% endif %}
{% if data.seqcycle %}
SET CYCLE {% endif %}{% if data.seqincrement is defined and data.seqincrement|int(-1) > -1 %}
SET INCREMENT {{data.seqincrement|int}} {% endif %}{% if data.seqstart is defined and data.seqstart|int(-1) > -1%}
SET START {{data.seqstart|int}} {% endif %}{% if data.seqmin is defined and data.seqmin|int(-1) > -1%}
SET MINVALUE {{data.seqmin|int}} {% endif %}{% if data.seqmax is defined and data.seqmax|int(-1) > -1%}
SET MAXVALUE {{data.seqmax|int}} {% endif %}{% if data.seqcache is defined and data.seqcache|int(-1) > -1%}
SET CACHE {{data.seqcache|int}} {% endif %};
ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %}{% endif %}
{% if data.seqcycle %} SET CYCLE{% elif (data.seqcycle == False and o_data.seqcycle and data.seqcycle != o_data.seqcycle) %} SET NO CYCLE{% endif %}
{% if data.seqincrement is defined and data.seqincrement|int(-1) > -1 %} SET INCREMENT {{data.seqincrement|int}}{% endif %}
{% if data.seqstart is defined and data.seqstart|int(-1) > -1%} RESTART SET START {{data.seqstart|int}}{% endif %}
{% if data.seqmin is defined and data.seqmin|int(-1) > -1%} SET MINVALUE {{data.seqmin|int}}{% endif %}
{% if data.seqmax is defined and data.seqmax|int(-1) > -1%} SET MAXVALUE {{data.seqmax|int}}{% endif %}
{% if data.seqcache is defined and data.seqcache|int(-1) > -1%} SET CACHE {{data.seqcache|int}}{% endif %}{% if attidentity_params is true %};{% endif %}
{% endif %}
{### Alter column - drop identity when column constraint is changed###}