-
Notifications
You must be signed in to change notification settings - Fork 650
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unlogged option while creating a sequence. #6376
- Loading branch information
1 parent
52643a5
commit aa9e5ca
Showing
22 changed files
with
1,035 additions
and
6 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...ver_groups/servers/databases/schemas/sequences/templates/sequences/sql/15_plus/create.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %}; | ||
|
23 changes: 23 additions & 0 deletions
23
...groups/servers/databases/schemas/sequences/templates/sequences/sql/15_plus/properties.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %} |
113 changes: 113 additions & 0 deletions
113
...ver_groups/servers/databases/schemas/sequences/templates/sequences/sql/15_plus/update.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %} |
13 changes: 13 additions & 0 deletions
13
...rver_groups/servers/databases/schemas/sequences/tests/pg/15_plus/alter_seq_set_logged.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
2 changes: 2 additions & 0 deletions
2
...groups/servers/databases/schemas/sequences/tests/pg/15_plus/alter_seq_set_logged_msql.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER SEQUENCE IF EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#" | ||
SET LOGGED; |
13 changes: 13 additions & 0 deletions
13
...er_groups/servers/databases/schemas/sequences/tests/pg/15_plus/alter_seq_set_unlogged.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
2 changes: 2 additions & 0 deletions
2
...oups/servers/databases/schemas/sequences/tests/pg/15_plus/alter_seq_set_unlogged_msql.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER SEQUENCE IF EXISTS public."Seq1_$%{}[]()&*^!@""'`\/#" | ||
SET UNLOGGED; |
13 changes: 13 additions & 0 deletions
13
..._groups/servers/databases/schemas/sequences/tests/pg/15_plus/create_unlogged_sequence.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
9 changes: 9 additions & 0 deletions
9
...ps/servers/databases/schemas/sequences/tests/pg/15_plus/create_unlogged_sequence_msql.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
Oops, something went wrong.