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
4fe0c39f
Commit
4fe0c39f
authored
2 years ago
by
Jean-Laurent DUZANT
Browse files
Options
Downloads
Patches
Plain Diff
FIX #19580 TIME 0 add change migration file name
parent
89c536d5
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/20.10/201020.sql
+51
-0
51 additions, 0 deletions
migration/20.10/201020.sql
with
51 additions
and
0 deletions
migration/20.10/201020.sql
0 → 100644
+
51
−
0
View file @
4fe0c39f
-- *************************************************************************--
-- --
-- --
-- Model migration script - 20.10.20 to 20.10.21 --
-- --
-- --
-- *************************************************************************--
-- Create a sequence and set value for each chronos found in parameters table
DO
$$
DECLARE
last_chrono
text
;
chrono
record
;
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_seq_name
:
=
CONCAT
(
chrono
.
id
,
'_seq'
);
-- 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
;
-- Set sequence value
EXECUTE
'SELECT setVal(
''
'
||
chrono_seq_name
||
'
''
,'
||
chrono
.
value
||
',false)'
;
END
LOOP
;
END
$$
;
-- 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
-- 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
;
-- 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
;
-- 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
;
$$
LANGUAGE
plpgsql
;
UPDATE
parameters
SET
param_value_string
=
'20.10.13'
WHERE
id
=
'database_version'
;
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