Added unlogged option while creating a sequence. #6376

pull/6596/head
Pravesh Sharma 2023-07-27 17:37:22 +05:30 committed by GitHub
parent a460644ae8
commit 5c2d242ff8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 1035 additions and 6 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 122 KiB

View File

@ -52,10 +52,12 @@ Use the fields in the *Definition* tab to define the sequence:
to be preallocated and stored in memory for faster access. The minimum value
is 1 (only one value can be generated at a time, i.e., no cache), and this is
also the default.
* Move the *Cycled* switch to the *Yes* position to allow the sequence to wrap
* Move the switch next to *Cycled* towards the *right position* to allow the sequence to wrap
around when the MAXVALUE or the MINVALUE has been reached by an ascending or
descending sequence respectively. If the limit is reached, the next number
generated will be the MINVALUE or MAXVALUE, respectively. The default is *No*.
* Move the switch next to *Unlogged?* towards the *right position* to make the sequence Unlogged.
The default is *No*. This option is available only on PostgreSQL 15 and above.
* The *OWNED BY* option causes the sequence to be associated with a specific
table column, such that if that column (or its whole table) is dropped, the
sequence will be automatically dropped as well. The specified table must have

View File

@ -89,6 +89,7 @@ export default class SequenceSchema extends BaseUISchema {
maximum: undefined,
cache: undefined,
cycled: undefined,
relpersistence: undefined,
relacl: [],
securities: [],
...initValues,
@ -154,6 +155,10 @@ export default class SequenceSchema extends BaseUISchema {
}, {
id: 'cycled', label: gettext('Cycled'), type: 'switch',
mode: ['properties', 'create', 'edit'], group: gettext('Definition'),
}, {
id: 'relpersistence', label: gettext('Unlogged?'), type: 'switch',
mode: ['properties', 'create', 'edit'], group: gettext('Definition'),
min_version: 150000,
}, {
type: 'nested-fieldset', label: gettext('Owned By'), group: gettext('Definition'),
schema: this.ownedSchemaObj,

View File

@ -0,0 +1,18 @@
CREATE {% if data.relpersistence %}UNLOGGED {% endif %}SEQUENCE{% if add_not_exists_clause %} IF NOT EXISTS{% endif %} {{ conn|qtIdent(data.schema, data.name) }}{% if data.increment is defined and data.cycled %}
CYCLE{% endif %}{% if data.increment is defined %}
INCREMENT {{data.increment|int}}{% endif %}{% if data.start is defined %}
START {{data.start|int}}{% elif data.current_value is defined %}
START {{data.current_value|int}}{% endif %}{% if data.minimum is defined %}
MINVALUE {{data.minimum|int}}{% endif %}{% if data.maximum is defined %}
MAXVALUE {{data.maximum|int}}{% endif %}{% if data.cache is defined and data.cache|int(-1) > -1%}
CACHE {{data.cache|int}}{% endif %}{% if data.owned_table is defined and data.owned_table != None and data.owned_column is defined and data.owned_column != None %}
OWNED BY {{ conn|qtIdent(data.owned_table) }}.{{ conn|qtIdent(data.owned_column) }}{% endif %};

View File

@ -0,0 +1,23 @@
{% if scid %}
SELECT
cl.oid as oid,
cl.relname as name,
nsp.nspname as schema,
pg_catalog.pg_get_userbyid(cl.relowner) AS seqowner,
description as comment,
pg_catalog.array_to_string(cl.relacl::text[], ', ') as acl,
(SELECT pg_catalog.array_agg(provider || '=' || label) FROM pg_catalog.pg_seclabels sl1 WHERE sl1.objoid=cl.oid) AS securities,
depcl.relname AS owned_table,
att.attname AS owned_column,
(CASE WHEN cl.relpersistence = 'u' THEN true ELSE false END) AS relpersistence
FROM pg_catalog.pg_class cl
LEFT OUTER JOIN pg_catalog.pg_namespace nsp ON cl.relnamespace = nsp.oid
LEFT OUTER JOIN pg_catalog.pg_description des ON (des.objoid=cl.oid
AND des.classoid='pg_class'::regclass)
LEFT OUTER JOIN pg_catalog.pg_depend dep ON (dep.objid=cl.oid and deptype = 'a')
LEFT JOIN pg_catalog.pg_attribute att ON dep.refobjid=att.attrelid AND dep.refobjsubid=att.attnum
LEFT JOIN pg_catalog.pg_class depcl ON depcl.oid = att.attrelid
WHERE cl.relkind = 'S' AND cl.relnamespace = {{scid}}::oid
{% if seid %}AND cl.oid = {{seid}}::oid {% endif %}
ORDER BY cl.relname
{% endif %}

View File

@ -0,0 +1,113 @@
{% import 'macros/schemas/security.macros' as SECLABEL %}
{% import 'macros/schemas/privilege.macros' as PRIVILEGE %}
{% if data %}
{% if data.name != o_data.name %}
ALTER SEQUENCE IF EXISTS {{ conn|qtIdent(o_data.schema, o_data.name) }}
RENAME TO {{ conn|qtIdent(data.name) }};
{% endif %}
{% if data.seqowner and data.seqowner != o_data.seqowner %}
ALTER SEQUENCE IF EXISTS {{ conn|qtIdent(o_data.schema, data.name) }}
OWNER TO {{ conn|qtIdent(data.seqowner) }};
{% endif %}
{% if (data.owned_table == None) and (data.owned_column == None) %}
ALTER SEQUENCE IF EXISTS {{ conn|qtIdent(o_data.schema, data.name) }}
OWNED BY NONE;
{% elif (data.owned_table is defined or data.owned_column is defined) and (data.owned_table != o_data.owned_table or data.owned_column != o_data.owned_column) %}
ALTER SEQUENCE IF EXISTS {{ conn|qtIdent(o_data.schema, data.name) }}
OWNED BY {% if data.owned_table is defined %}{{ conn|qtIdent(data.owned_table) }}{% else %}{{ conn|qtIdent(o_data.owned_table) }}{% endif %}.{% if data.owned_column is defined %}{{ conn|qtIdent(data.owned_column) }}{% else %}{{ conn|qtIdent(o_data.owned_column) }}{% endif %};
{% endif %}
{% if data.current_value is defined %}
{% set seqname = conn|qtIdent(o_data.schema, data.name) %}
SELECT setval({{ seqname|qtLiteral(conn) }}, {{ data.current_value }}, true);
{% endif %}
{% if data.relpersistence in [True, False] and data.relpersistence != o_data.relpersistence %}
ALTER SEQUENCE IF EXISTS {{ conn|qtIdent(o_data.schema, data.name) }}
SET {% if data.relpersistence %}UNLOGGED{% else %}LOGGED{% endif %};
{% endif %}
{% set defquery = '' %}
{% if data.increment is defined %}
{% set defquery = defquery+'\n INCREMENT '+data.increment|string %}
{% endif %}
{% if data.start is defined %}
{% set defquery = defquery+'\n START '+data.start|string %}
{% endif %}
{% if data.minimum is defined %}
{% set defquery = defquery+'\n MINVALUE '+data.minimum|string %}
{% endif %}
{% if data.maximum is defined %}
{% set defquery = defquery+'\n MAXVALUE '+data.maximum|string %}
{% endif %}
{% if data.cache is defined %}
{% set defquery = defquery+'\n CACHE '+data.cache|string %}
{% endif %}
{% if data.cycled == True %}
{% set defquery = defquery+'\n CYCLE' %}
{% elif data.cycled == False %}
{% set defquery = defquery+'\n NO CYCLE' %}
{% endif %}
{% if defquery and defquery != '' %}
ALTER SEQUENCE IF EXISTS {{ conn|qtIdent(o_data.schema, data.name) }}{{ defquery }};
{% endif %}
{% if data.schema and data.schema != o_data.schema %}
ALTER SEQUENCE IF EXISTS {{ conn|qtIdent(o_data.schema, data.name) }}
SET SCHEMA {{ conn|qtIdent(data.schema) }};
{% set seqname = conn|qtIdent(data.schema, data.name) %}
{% set schema = data.schema %}
{% else %}
{% set seqname = conn|qtIdent(o_data.schema, data.name) %}
{% set schema = o_data.schema %}
{% endif %}
{% if data.comment is defined and data.comment != o_data.comment %}
COMMENT ON SEQUENCE {{ seqname }}
IS {{ data.comment|qtLiteral(conn) }};
{% endif %}
{% if data.securities and data.securities|length > 0 %}
{% set seclabels = data.securities %}
{% if 'deleted' in seclabels and seclabels.deleted|length > 0 %}
{% for r in seclabels.deleted %}
{{ SECLABEL.UNSET(conn, 'SEQUENCE', data.name, r.provider, schema) }}
{% endfor %}
{% endif %}
{% if 'added' in seclabels and seclabels.added|length > 0 %}
{% for r in seclabels.added %}
{{ SECLABEL.SET(conn, 'SEQUENCE', data.name, r.provider, r.label, schema) }}
{% endfor %}
{% endif %}
{% if 'changed' in seclabels and seclabels.changed|length > 0 %}
{% for r in seclabels.changed %}
{{ SECLABEL.SET(conn, 'SEQUENCE', data.name, r.provider, r.label, schema) }}
{% endfor %}
{% endif %}
{% endif %}
{% if data.relacl %}
{% if 'deleted' in data.relacl %}
{% for priv in data.relacl.deleted %}
{{ PRIVILEGE.UNSETALL(conn, 'SEQUENCE', priv.grantee, data.name, schema) }}
{% endfor %}
{% endif %}
{% if 'changed' in data.relacl %}
{% for priv in data.relacl.changed %}
{% if priv.grantee != priv.old_grantee %}
{{ PRIVILEGE.UNSETALL(conn, 'SEQUENCE', priv.old_grantee, data.name, schema) }}
{% else %}
{{ PRIVILEGE.UNSETALL(conn, 'SEQUENCE', priv.grantee, data.name, schema) }}
{% endif %}
{{ PRIVILEGE.SET(conn, 'SEQUENCE', priv.grantee, data.name, priv.without_grant, priv.with_grant, schema) }}
{% endfor %}
{% endif %}
{% if 'added' in data.relacl %}
{% for priv in data.relacl.added %}
{{ PRIVILEGE.SET(conn, 'SEQUENCE', priv.grantee, data.name, priv.without_grant, priv.with_grant, schema) }}
{% endfor %}
{% endif %}
{% endif %}
{% endif %}

View File

@ -0,0 +1,13 @@
-- SEQUENCE: public.Seq1_$%{}[]()&*^!@"'`\/#
-- DROP SEQUENCE IF EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#";
CREATE SEQUENCE IF NOT EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#"
INCREMENT 5
START 5
MINVALUE 5
MAXVALUE 999
CACHE 1;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO postgres;

View File

@ -0,0 +1,2 @@
ALTER SEQUENCE IF EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#"
SET LOGGED;

View File

@ -0,0 +1,13 @@
-- SEQUENCE: public.Seq1_$%{}[]()&*^!@"'`\/#
-- DROP SEQUENCE IF EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#";
CREATE UNLOGGED SEQUENCE IF NOT EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#"
INCREMENT 5
START 5
MINVALUE 5
MAXVALUE 999
CACHE 1;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO postgres;

View File

@ -0,0 +1,2 @@
ALTER SEQUENCE IF EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#"
SET UNLOGGED;

View File

@ -0,0 +1,13 @@
-- SEQUENCE: public.Seq1_$%{}[]()&*^!@"'`\/#
-- DROP SEQUENCE IF EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#";
CREATE UNLOGGED SEQUENCE IF NOT EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#"
INCREMENT 5
START 5
MINVALUE 5
MAXVALUE 999
CACHE 1;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO postgres;

View File

@ -0,0 +1,9 @@
CREATE UNLOGGED SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
INCREMENT 5
START 5
MINVALUE 5
MAXVALUE 999
CACHE 1;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO postgres;

View File

@ -0,0 +1,352 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Table for Owned By",
"endpoint": "NODE-table.obj",
"sql_endpoint": "NODE-table.sql_id",
"data": {
"name": "tableforownedby",
"columns": [
{
"name": "col1",
"cltype": "integer",
"is_primary_key": true
},
{
"name": "col2",
"cltype": "text"
},
{
"name": "col3",
"cltype": "integer"
}
],
"is_partitioned": false,
"schema": "public",
"spcname": "pg_default"
},
"store_object_id": true
},
{
"type": "create",
"name": "Create Sequence",
"endpoint": "NODE-sequence.obj",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#",
"seqowner": "postgres",
"schema": "public",
"increment": "5",
"start": "5",
"maximum": "999",
"minimum": "5",
"cache": "1",
"cycled": false,
"relacl": [],
"securities": []
},
"expected_sql_file": "create_sequence.sql",
"expected_msql_file": "create_sequence_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence comment",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"comment": "Some comment"
},
"expected_sql_file": "alter_seq_comment.sql",
"expected_msql_file": "alter_seq_comment_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence properties",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"current_value": "7", "increment": "12", "minimum": "2", "maximum": "9992", "cache": "2", "cycled": true
},
"expected_sql_file": "alter_seq_props.sql",
"expected_msql_file": "alter_seq_props_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence add privileges",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"sql_endpoint": "NODE-sequence.sql_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relacl": {
"added":[{
"grantee": "PUBLIC",
"grantor": "postgres",
"privileges":[{
"privilege_type": "r",
"privilege": true,
"with_grant": false
},{
"privilege_type": "U",
"privilege": true,
"with_grant": false
},{
"privilege_type": "w",
"privilege": true,
"with_grant": false
}]
}]
}
},
"expected_sql_file": "alter_seq_privs_add.sql",
"expected_msql_file": "alter_seq_privs_add_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence update privileges",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relacl": {
"changed":[{
"grantee": "PUBLIC",
"grantor": "postgres",
"privileges":[{
"privilege_type": "r",
"privilege": true,
"with_grant": false
}]
}]
}
},
"expected_sql_file": "alter_seq_privs_update.sql",
"expected_msql_file": "alter_seq_privs_update_msql.sql"
},
{
"type": "alter",
"name": "Alter Sequence remove partial privileges",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relacl": {
"deleted":[{
"grantee": "PUBLIC",
"grantor": "postgres",
"privileges":[{
"privilege_type": "r",
"privilege": true,
"with_grant": false
}]
}]
}
}
},
{
"type": "alter",
"name": "Alter Sequence change grantee in privileges",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relacl": {
"changed":[{
"grantee": "PUBLIC",
"grantor": "postgres",
"old_grantee": "postgres",
"privileges":[{
"privilege_type": "r",
"privilege": true,
"with_grant": false
}]
}]
}
},
"expected_sql_file": "alter_seq_change_grantee_privs.sql",
"expected_msql_file": "alter_seq_change_grantee_privs_msql.sql"
},
{
"type": "alter",
"name": "Alter Sequence remove privileges",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relacl": {
"deleted":[{
"grantee": "PUBLIC",
"grantor": "postgres",
"privileges":[{
"privilege_type": "r",
"privilege": true,
"with_grant": false
},{
"privilege_type": "U",
"privilege": true,
"with_grant": false
},{
"privilege_type": "w",
"privilege": true,
"with_grant": false
}]
}]
}
},
"expected_sql_file": "alter_seq_privs_remove.sql",
"expected_msql_file": "alter_seq_privs_remove_msql.sql"
}, {
"type": "delete",
"name": "Drop sequence",
"endpoint": "NODE-sequence.delete_id",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#"
}
}, {
"type": "create",
"name": "Create Sequence with Negative value",
"endpoint": "NODE-sequence.obj",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#",
"seqowner": "postgres",
"schema": "public",
"increment": "-5",
"start": "-30",
"maximum": "-10",
"minimum": "-40",
"cache": "1",
"cycled": false,
"relacl": [],
"securities": []
},
"expected_sql_file": "create_negative_sequence.sql",
"expected_msql_file": "create_negative_sequence_msql.sql"
}, {
"type": "alter",
"name": "Alter Sequence properties with negative value",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"increment": "-7", "minimum": "-35", "maximum": "-15"
},
"expected_sql_file": "alter_neg_seq_props.sql",
"expected_msql_file": "alter_neg_seq_props_msql.sql"
}, {
"type": "delete",
"name": "Drop negative sequence",
"endpoint": "NODE-sequence.delete_id",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#"
}
},
{
"type": "create",
"name": "Create Sequence with Owned By",
"endpoint": "NODE-sequence.obj",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#",
"seqowner": "postgres",
"schema": "public",
"increment": "5",
"start": "5",
"maximum": "999",
"minimum": "5",
"cache": "1",
"cycled": false,
"owned_table": "tableforownedby",
"owned_column": "col1",
"relacl": [],
"securities": []
},
"expected_sql_file": "create_sequence_ownedby.sql",
"expected_msql_file": "create_sequence_ownedby_msql.sql"
}, {
"type": "alter",
"name": "Alter Sequence owned by column",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"owned_column": "col2"
},
"expected_sql_file": "alter_ownedby_column.sql",
"expected_msql_file": "alter_ownedby_column_msql.sql"
}, {
"type": "alter",
"name": "Alter Sequence remove owned by",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"maximum": "900"
},
"expected_sql_file": "alter_ownedby_remove.sql",
"expected_msql_file": "alter_ownedby_remove_msql.sql"
}, {
"type": "delete",
"name": "Drop owned by sequence",
"endpoint": "NODE-sequence.delete_id",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#"
}
}, {
"type": "create",
"name": "Create unlogged sequence",
"endpoint": "NODE-sequence.obj",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#",
"seqowner": "postgres",
"schema": "public",
"increment": "5",
"start": "5",
"maximum": "999",
"minimum": "5",
"cache": "1",
"cycled": false,
"relpersistence": true,
"relacl": [],
"securities": []
},
"expected_sql_file": "create_unlogged_sequence.sql",
"expected_msql_file": "create_unlogged_sequence_msql.sql"
}, {
"type": "alter",
"name": "Alter sequence set logged",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relpersistence": false
},
"expected_sql_file": "alter_seq_set_logged.sql",
"expected_msql_file": "alter_seq_set_logged_msql.sql"
}, {
"type": "alter",
"name": "Alter sequence set unlogged",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relpersistence": true
},
"expected_sql_file": "alter_seq_set_unlogged.sql",
"expected_msql_file": "alter_seq_set_unlogged_msql.sql"
}, {
"type": "delete",
"name": "Drop unlogged sequence",
"endpoint": "NODE-sequence.delete_id",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#"
}
}
]
}

View File

@ -0,0 +1,13 @@
-- SEQUENCE: public.Seq1_$%{}[]()&*^!@"'`\/#
-- DROP SEQUENCE IF EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#";
CREATE SEQUENCE IF NOT EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#"
INCREMENT 5
START 5
MINVALUE 5
MAXVALUE 999
CACHE 1;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO enterprisedb;

View File

@ -0,0 +1,2 @@
ALTER SEQUENCE IF EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#"
SET LOGGED;

View File

@ -0,0 +1,13 @@
-- SEQUENCE: public.Seq1_$%{}[]()&*^!@"'`\/#
-- DROP SEQUENCE IF EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#";
CREATE UNLOGGED SEQUENCE IF NOT EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#"
INCREMENT 5
START 5
MINVALUE 5
MAXVALUE 999
CACHE 1;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO enterprisedb;

View File

@ -0,0 +1,2 @@
ALTER SEQUENCE IF EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#"
SET UNLOGGED;

View File

@ -0,0 +1,13 @@
-- SEQUENCE: public.Seq1_$%{}[]()&*^!@"'`\/#
-- DROP SEQUENCE IF EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#";
CREATE UNLOGGED SEQUENCE IF NOT EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#"
INCREMENT 5
START 5
MINVALUE 5
MAXVALUE 999
CACHE 1;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO enterprisedb;

View File

@ -0,0 +1,9 @@
CREATE UNLOGGED SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
INCREMENT 5
START 5
MINVALUE 5
MAXVALUE 999
CACHE 1;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO enterprisedb;

View File

@ -0,0 +1,350 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Table for Owned By",
"endpoint": "NODE-table.obj",
"sql_endpoint": "NODE-table.sql_id",
"data": {
"name": "tableforownedby",
"columns": [
{
"name": "col1",
"cltype": "integer",
"is_primary_key": true
},
{
"name": "col2",
"cltype": "text"
},
{
"name": "col3",
"cltype": "integer"
}
],
"is_partitioned": false,
"schema": "public",
"spcname": "pg_default"
},
"store_object_id": true
},
{
"type": "create",
"name": "Create Sequence",
"endpoint": "NODE-sequence.obj",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#",
"seqowner": "enterprisedb",
"schema": "public",
"increment": "5",
"start": "5",
"maximum": "999",
"minimum": "5",
"cache": "1",
"cycled": false,
"relacl": [],
"securities": []
},
"expected_sql_file": "create_sequence.sql",
"expected_msql_file": "create_sequence_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence comment",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"comment": "Some comment"
},
"expected_sql_file": "alter_seq_comment.sql",
"expected_msql_file": "alter_seq_comment_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence properties",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"current_value": "7", "increment": "12", "minimum": "2", "maximum": "9992", "cache": "2", "cycled": true
},
"expected_sql_file": "alter_seq_props.sql",
"expected_msql_file": "alter_seq_props_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence add privileges",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relacl": {
"added":[{
"grantee": "PUBLIC",
"grantor": "enterprisedb",
"privileges":[{
"privilege_type": "r",
"privilege": true,
"with_grant": false
},{
"privilege_type": "U",
"privilege": true,
"with_grant": false
},{
"privilege_type": "w",
"privilege": true,
"with_grant": false
}]
}]
}
},
"expected_sql_file": "alter_seq_privs_add.sql",
"expected_msql_file": "alter_seq_privs_add_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence update privileges",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relacl": {
"changed":[{
"grantee": "PUBLIC",
"grantor": "enterprisedb",
"privileges":[{
"privilege_type": "r",
"privilege": true,
"with_grant": false
}]
}]
}
},
"expected_sql_file": "alter_seq_privs_update.sql",
"expected_msql_file": "alter_seq_privs_update_msql.sql"
},
{
"type": "alter",
"name": "Alter Sequence remove partial privileges",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relacl": {
"deleted":[{
"grantee": "PUBLIC",
"grantor": "enterprisedb",
"privileges":[{
"privilege_type": "r",
"privilege": true,
"with_grant": false
}]
}]
}
}
},
{
"type": "alter",
"name": "Alter Sequence change grantee in privileges",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relacl": {
"changed":[{
"grantee": "PUBLIC",
"grantor": "enterprisedb",
"old_grantee": "enterprisedb",
"privileges":[{
"privilege_type": "r",
"privilege": true,
"with_grant": false
}]
}]
}
},
"expected_sql_file": "alter_seq_change_grantee_privs.sql",
"expected_msql_file": "alter_seq_change_grantee_privs_msql.sql"
},
{
"type": "alter",
"name": "Alter Sequence remove privileges",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relacl": {
"deleted":[{
"grantee": "PUBLIC",
"grantor": "enterprisedb",
"privileges":[{
"privilege_type": "r",
"privilege": true,
"with_grant": false
},{
"privilege_type": "U",
"privilege": true,
"with_grant": false
},{
"privilege_type": "w",
"privilege": true,
"with_grant": false
}]
}]
}
},
"expected_sql_file": "alter_seq_privs_remove.sql",
"expected_msql_file": "alter_seq_privs_remove_msql.sql"
}, {
"type": "delete",
"name": "Drop sequence",
"endpoint": "NODE-sequence.delete_id",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#"
}
}, {
"type": "create",
"name": "Create Sequence with Negative value",
"endpoint": "NODE-sequence.obj",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#",
"seqowner": "enterprisedb",
"schema": "public",
"increment": "-5",
"start": "-30",
"maximum": "-10",
"minimum": "-40",
"cache": "1",
"cycled": false,
"relacl": [],
"securities": []
},
"expected_sql_file": "create_negative_sequence.sql",
"expected_msql_file": "create_negative_sequence_msql.sql"
}, {
"type": "alter",
"name": "Alter Sequence properties with negative value",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"increment": "-7", "minimum": "-35", "maximum": "-15"
},
"expected_sql_file": "alter_neg_seq_props.sql",
"expected_msql_file": "alter_neg_seq_props_msql.sql"
}, {
"type": "delete",
"name": "Drop negative sequence",
"endpoint": "NODE-sequence.delete_id",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#"
}
},
{
"type": "create",
"name": "Create Sequence with Owned By",
"endpoint": "NODE-sequence.obj",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#",
"seqowner": "enterprisedb",
"schema": "public",
"increment": "5",
"start": "5",
"maximum": "999",
"minimum": "5",
"cache": "1",
"cycled": false,
"owned_table": "tableforownedby",
"owned_column": "col1",
"relacl": [],
"securities": []
},
"expected_sql_file": "create_sequence_ownedby.sql",
"expected_msql_file": "create_sequence_ownedby_msql.sql"
}, {
"type": "alter",
"name": "Alter Sequence owned by column",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"owned_column": "col2"
},
"expected_sql_file": "alter_ownedby_column.sql",
"expected_msql_file": "alter_ownedby_column_msql.sql"
}, {
"type": "alter",
"name": "Alter Sequence remove owned by",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"maximum": "900"
},
"expected_sql_file": "alter_ownedby_remove.sql",
"expected_msql_file": "alter_ownedby_remove_msql.sql"
}, {
"type": "delete",
"name": "Drop owned by sequence",
"endpoint": "NODE-sequence.delete_id",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#"
}
}, {
"type": "create",
"name": "Create unlogged sequence",
"endpoint": "NODE-sequence.obj",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#",
"seqowner": "enterprisedb",
"schema": "public",
"increment": "5",
"start": "5",
"maximum": "999",
"minimum": "5",
"cache": "1",
"cycled": false,
"relpersistence": true,
"relacl": [],
"securities": []
},
"expected_sql_file": "create_unlogged_sequence.sql",
"expected_msql_file": "create_unlogged_sequence_msql.sql"
}, {
"type": "alter",
"name": "Alter sequence set logged",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relpersistence": false
},
"expected_sql_file": "alter_seq_set_logged.sql",
"expected_msql_file": "alter_seq_set_logged_msql.sql"
}, {
"type": "alter",
"name": "Alter sequence set unlogged",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relpersistence": true
},
"expected_sql_file": "alter_seq_set_unlogged.sql",
"expected_msql_file": "alter_seq_set_unlogged_msql.sql"
}, {
"type": "delete",
"name": "Drop unlogged sequence",
"endpoint": "NODE-sequence.delete_id",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#"
}
}
]
}

View File

@ -17,6 +17,7 @@ from pgadmin.browser.server_groups.servers.databases.tests import utils as \
from pgadmin.utils.route import BaseTestGenerator
from regression import parent_node_dict
from regression.python_test_utils import test_utils as utils
from pgadmin.utils import server_utils
class SequenceAddTestCase(BaseTestGenerator):
@ -27,6 +28,7 @@ class SequenceAddTestCase(BaseTestGenerator):
'Create sequence with positive values',
dict(
url='/browser/sequence/obj/',
inventory_data={},
# Valid optional data
data={
"cache": "1",
@ -44,6 +46,7 @@ class SequenceAddTestCase(BaseTestGenerator):
'Create sequence with negative values',
dict(
url='/browser/sequence/obj/',
inventory_data={},
# Valid optional data
data={
"cache": "1",
@ -56,23 +59,54 @@ class SequenceAddTestCase(BaseTestGenerator):
"start": "-30"
}
)
),
(
'Create unlogged sequence',
dict(
url='/browser/sequence/obj/',
inventory_data={
"server_min_version": 150000,
"skip_msg": "Unlogged sequences is not supported by \
PG/PPAS 15.0 and below"
},
# Valid optional data
data={
"cache": "1",
"cycled": True,
"increment": "1",
"maximum": "100000",
"minimum": "1",
"name": "test_sequence_add_%s" % (str(uuid.uuid4())[1:8]),
"securities": [],
"start": "100",
"relpersistence": True
}
)
)
]
def setUp(self):
super().setUp()
def runTest(self):
"""This function will add sequence(s) under schema node."""
db_name = parent_node_dict["database"][-1]["db_name"]
schema_info = parent_node_dict["schema"][-1]
self.server_id = schema_info["server_id"]
if "server_min_version" in self.inventory_data:
server_con = server_utils.connect_server(self, self.server_id)
if not server_con["info"] == "Server connected.":
raise Exception("Could not connect to server to add "
"sequence.")
if server_con["data"]["version"] < \
self.inventory_data["server_min_version"]:
self.skipTest(self.inventory_data["skip_msg"])
db_name = parent_node_dict["database"][-1]["db_name"]
self.db_id = schema_info["db_id"]
db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
self.server_id, self.db_id)
if not db_con['data']["connected"]:
raise Exception("Could not connect to database to add sequence.")
schema_id = schema_info["schema_id"]
self.schema_id = schema_info["schema_id"]
schema_name = schema_info["schema_name"]
schema_response = schema_utils.verify_schemas(self.server,
db_name,
@ -112,10 +146,12 @@ class SequenceAddTestCase(BaseTestGenerator):
self.data.update(common_data)
def runTest(self):
"""This function will add sequence(s) under schema node."""
response = self.tester.post(
self.url + str(utils.SERVER_GROUP) + '/' +
str(self.server_id) + '/' + str(self.db_id) +
'/' + str(schema_id) + '/',
'/' + str(self.schema_id) + '/',
data=json.dumps(self.data),
content_type='html/json')
self.assertEqual(response.status_code, 200)

View File

@ -18,6 +18,7 @@ from pgadmin.utils.route import BaseTestGenerator
from regression import parent_node_dict
from regression.python_test_utils import test_utils as utils
from . import utils as sequence_utils
from pgadmin.utils import server_utils
class SequencePutTestCase(BaseTestGenerator):
@ -27,6 +28,7 @@ class SequencePutTestCase(BaseTestGenerator):
('Alter positive sequence comment, increment, max and min value',
dict(
url='/browser/sequence/obj/',
inventory_data={},
data={
"comment": "This is sequence update comment",
"increment": "5",
@ -38,6 +40,7 @@ class SequencePutTestCase(BaseTestGenerator):
('Alter negative sequence comment, increment, max and min value',
dict(
url='/browser/sequence/obj/',
inventory_data={},
data={
"comment": "This is sequence update comment",
"increment": "-7",
@ -45,6 +48,19 @@ class SequencePutTestCase(BaseTestGenerator):
"minimum": "-35",
},
positive_seq=False
)),
('Alter sequence set unlogged',
dict(
url='/browser/sequence/obj/',
inventory_data={
"server_min_version": 150000,
"skip_msg": "Unlogged sequences is not \
supported by PG/PPAS 15.0 and below"
},
data={
"relpersistence": True
},
positive_seq=True
))
]
@ -53,6 +69,16 @@ class SequencePutTestCase(BaseTestGenerator):
self.db_name = parent_node_dict["database"][-1]["db_name"]
schema_info = parent_node_dict["schema"][-1]
self.server_id = schema_info["server_id"]
if "server_min_version" in self.inventory_data:
server_con = server_utils.connect_server(self, self.server_id)
if not server_con["info"] == "Server connected.":
raise Exception("Could not connect to server to add "
"sequence.")
if server_con["data"]["version"] < \
self.inventory_data["server_min_version"]:
self.skipTest(self.inventory_data["skip_msg"])
self.db_id = schema_info["db_id"]
db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
self.server_id, self.db_id)