Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MaarchCourrier
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maarch
MaarchCourrier
Commits
004bcbc5
Commit
004bcbc5
authored
2 years ago
by
Jean-Laurent DUZANT
Browse files
Options
Downloads
Patches
Plain Diff
FIX #19580 TIME 0 add comments && replace chrono_id_seq to chrono_seq_name
parent
08f6bb76
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
migration/21.03/210321.sql
+17
-9
17 additions, 9 deletions
migration/21.03/210321.sql
with
17 additions
and
9 deletions
migration/21.03/210321.sql
+
17
−
9
View file @
004bcbc5
...
...
@@ -6,34 +6,42 @@
-- --
-- *************************************************************************--
-- Create a sequence and set value for each chronos found in parameters table
DO
$$
DECLARE
last_chrono
text
;
chrono
record
;
chrono_
id_
seq
text
;
chrono_seq
_name
text
;
BEGIN
-- Loop through each chrono found in parameters table
FOR
chrono
IN
(
SELECT
id
,
param_value_int
as
value
FROM
parameters
WHERE
id
LIKE
'chrono_%'
)
LOOP
chrono_
id_
seq
:
=
CONCAT
(
chrono
.
id
,
'_seq'
);
chrono_seq
_name
:
=
CONCAT
(
chrono
.
id
,
'_seq'
);
IF
NOT
EXISTS
(
SELECT
0
FROM
pg_class
where
relname
=
chrono_id_seq
)
THEN
EXECUTE
'CREATE SEQUENCE '
||
chrono_id_seq
||
' INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1;'
;
-- Check if sequence exist, if not create
IF
NOT
EXISTS
(
SELECT
0
FROM
pg_class
where
relname
=
chrono_seq_name
)
THEN
EXECUTE
'CREATE SEQUENCE '
||
chrono_seq_name
||
' INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1;'
;
END
IF
;
EXECUTE
'SELECT setVal(
''
'
||
chrono_id_seq
||
'
''
,'
||
chrono
.
value
||
',false)'
;
-- Set sequence value
EXECUTE
'SELECT setVal(
''
'
||
chrono_seq_name
||
'
''
,'
||
chrono
.
value
||
',false)'
;
END
LOOP
;
END
$$
;
CREATE
OR
REPLACE
FUNCTION
public
.
increase_chrono
(
chrono_id_seq
text
,
chrono_id_name
text
)
returns
table
(
chrono_id
bigint
)
as
$$
-- Create a sequence for chronos and update value in parameters table
CREATE
OR
REPLACE
FUNCTION
public
.
increase_chrono
(
chrono_seq_name
text
,
chrono_id_name
text
)
returns
table
(
chrono_id
bigint
)
as
$$
DECLARE
retval
bigint
;
BEGIN
IF
NOT
EXISTS
(
SELECT
0
FROM
pg_class
where
relname
=
chrono_id_seq
)
THEN
EXECUTE
'CREATE SEQUENCE '
||
chrono_id_seq
||
' INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1;'
;
-- Check if sequence exist, if not create
IF
NOT
EXISTS
(
SELECT
0
FROM
pg_class
where
relname
=
chrono_seq_name
)
THEN
EXECUTE
'CREATE SEQUENCE '
||
chrono_seq_name
||
' INCREMENT 1 MINVALUE 100 MAXVALUE 9223372036854775807 START 100 CACHE 1;'
;
END
IF
;
-- Check if chrono exist in parameters table, if not create
IF
NOT
EXISTS
(
SELECT
0
FROM
parameters
where
id
=
chrono_id_name
)
THEN
EXECUTE
'INSERT INTO parameters (id, param_value_int) VALUES (
''
'
||
chrono_id_name
||
'
''
, 1)'
;
END
IF
;
SELECT
nextval
(
chrono_id_seq
)
INTO
retval
;
-- Get next value of sequence, update the value in parameters table before returning the value
SELECT
nextval
(
chrono_seq_name
)
INTO
retval
;
UPDATE
parameters
set
param_value_int
=
retval
WHERE
id
=
chrono_id_name
;
RETURN
QUERY
SELECT
retval
;
END
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment