diff --git a/.gitignore b/.gitignore index 4deab7fc2..47dca977c 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,4 @@ web/yarn-error.log auditjs.html auditpy.txt /venv/ +.scannerwork/ \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/__init__.py index 780c4d148..789376a6e 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/__init__.py @@ -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) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/static/js/column.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/static/js/column.js index 698a63939..dea984e81 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/static/js/column.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/static/js/column.js @@ -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; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/alter_column_identity_by_default.msql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/alter_column_identity_by_default.msql index 15266762f..7a46497d9 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/alter_column_identity_by_default.msql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/alter_column_identity_by_default.msql @@ -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'; \ No newline at end of file + IS 'Comment for alter'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/alter_column_identity_for_comb_start_seq.msql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/alter_column_identity_for_comb_start_seq.msql new file mode 100644 index 000000000..6eede13ba --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/alter_column_identity_for_comb_start_seq.msql @@ -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; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/alter_column_identity_for_comb_start_seq.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/alter_column_identity_for_comb_start_seq.sql new file mode 100644 index 000000000..5aecdbec8 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/alter_column_identity_for_comb_start_seq.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/alter_column_identity_for_restart_seq.msql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/alter_column_identity_for_restart_seq.msql new file mode 100644 index 000000000..402c270cf --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/alter_column_identity_for_restart_seq.msql @@ -0,0 +1,2 @@ +ALTER TABLE testschema."table_2_$%{}[]()&*^!@""'`\/#" + ALTER COLUMN "col_6_$%{}[]()&*^!@""'`\/#" SET GENERATED ALWAYS SET NO CYCLE RESTART SET START 2; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/alter_column_identity_for_restart_seq.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/alter_column_identity_for_restart_seq.sql new file mode 100644 index 000000000..79cba6ad2 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/alter_column_identity_for_restart_seq.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/create_column_identity_for_restart_seq.msql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/create_column_identity_for_restart_seq.msql new file mode 100644 index 000000000..4a39d912a --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/create_column_identity_for_restart_seq.msql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/create_column_identity_for_restart_seq.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/create_column_identity_for_restart_seq.sql new file mode 100644 index 000000000..987bd6106 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/create_column_identity_for_restart_seq.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/test.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/test.json index 0bc46de20..0cdab1700 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/test.json +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/10_plus/test.json @@ -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_$%{}[]()&*^!@\"'`\\/#" + } } ] } diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/alter_column_identity_by_default.msql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/alter_column_identity_by_default.msql index 78cda16ed..6c00ace62 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/alter_column_identity_by_default.msql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/alter_column_identity_by_default.msql @@ -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'; \ No newline at end of file + IS 'Comment for alter'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/alter_column_identity_for_comb_start_seq.msql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/alter_column_identity_for_comb_start_seq.msql new file mode 100644 index 000000000..ad78f916e --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/alter_column_identity_for_comb_start_seq.msql @@ -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; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/alter_column_identity_for_comb_start_seq.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/alter_column_identity_for_comb_start_seq.sql new file mode 100644 index 000000000..55c46ed20 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/alter_column_identity_for_comb_start_seq.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/alter_column_identity_for_restart_seq.msql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/alter_column_identity_for_restart_seq.msql new file mode 100644 index 000000000..603dcec8e --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/alter_column_identity_for_restart_seq.msql @@ -0,0 +1,2 @@ +ALTER TABLE testschema."table_3_$%{}[]()&*^!@""'`\/#" + ALTER COLUMN "col_6_$%{}[]()&*^!@""'`\/#" SET GENERATED ALWAYS SET NO CYCLE RESTART SET START 2; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/alter_column_identity_for_restart_seq.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/alter_column_identity_for_restart_seq.sql new file mode 100644 index 000000000..75589761f --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/alter_column_identity_for_restart_seq.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/create_column_identity_for_restart_seq.msql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/create_column_identity_for_restart_seq.msql new file mode 100644 index 000000000..897636899 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/create_column_identity_for_restart_seq.msql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/create_column_identity_for_restart_seq.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/create_column_identity_for_restart_seq.sql new file mode 100644 index 000000000..6c827598b --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/create_column_identity_for_restart_seq.sql @@ -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'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/test.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/test.json index 227a1d006..98d701fda 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/test.json +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/12_plus/test.json @@ -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_$%{}[]()&*^!@\"'`\\/#" + } } - ] } diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/test_column_put.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/test_column_put.py index bfdcef2eb..48b4cac81 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/test_column_put.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/tests/test_column_put.py @@ -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', diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/10_plus/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/10_plus/update.sql index 6bf17eb33..75c76cc44 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/10_plus/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/10_plus/update.sql @@ -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 ###} -{% 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) %} +{% 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 %}{% 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###}