-
Notifications
You must be signed in to change notification settings - Fork 0
/
002_create_version_management.sql
62 lines (52 loc) · 3.29 KB
/
002_create_version_management.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/***
* ██████╗ █████╗ ████████╗ █████╗ ██████╗ █████╗ ███████╗███████╗ ██╗ ██╗███████╗██████╗ ███████╗██╗ ██████╗ ███╗ ██╗
* ██╔══██╗██╔══██╗╚══██╔══╝██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔════╝ ██║ ██║██╔════╝██╔══██╗██╔════╝██║██╔═══██╗████╗ ██║
* ██║ ██║███████║ ██║ ███████║██████╔╝███████║███████╗█████╗ ██║ ██║█████╗ ██████╔╝███████╗██║██║ ██║██╔██╗ ██║
* ██║ ██║██╔══██║ ██║ ██╔══██║██╔══██╗██╔══██║╚════██║██╔══╝ ╚██╗ ██╔╝██╔══╝ ██╔══██╗╚════██║██║██║ ██║██║╚██╗██║
* ██████╔╝██║ ██║ ██║ ██║ ██║██████╔╝██║ ██║███████║███████╗ ╚████╔╝ ███████╗██║ ██║███████║██║╚██████╔╝██║ ╚████║
* ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚══════╝╚══════╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝
*
*/
create table __version
(
version_id int generated always as identity not null primary key,
component text not null default 'main',
version text not null,
title text not null,
description text,
execution_started timestamptz not null default now(),
execution_finished timestamptz
);
create unique index uq_version on __version (component, version);
create function start_version_update(_version text, _title text, _description text default null,
_component text default 'main')
returns setof __version
language sql
as
$$
insert into __version(component, version, title, description)
VALUES (_component, _version, _title, _description)
returning *;
$$;
create function stop_version_update(_version text, _component text default 'main')
returns setof __version
language sql
as
$$
update __version
set execution_finished = now()
where component = _component
and version = _version
returning *;
$$;
create function check_version(_version text, _component text default 'main')
returns bool
language sql
cost 1
as
$$
select exists(select
from __version
where component = _component
and version = _version);
$$;