File: v16-dem-identity-dynamic.sql

package info (click to toggle)
gnumed-server 22.31-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 46,268 kB
  • sloc: sql: 1,217,633; python: 15,878; sh: 1,590; makefile: 20
file content (52 lines) | stat: -rw-r--r-- 1,366 bytes parent folder | download | duplicates (7)
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
-- ==============================================================
-- GNUmed database schema change script
--
-- License: GPL v2 or later
-- Author: Karsten Hilbert
--
-- ==============================================================
\set ON_ERROR_STOP 1

-- --------------------------------------------------------------
-- .dob
update dem.identity set
	dob = null,
	comment = coalesce(comment || '; ', '') || 'DOB-in-future (' || to_char(dob, 'Dy, YYYY-MM-DD, HH24:MI:SS.MS') || ') set to NULL'
where
	dob > now()
;


\unset ON_ERROR_STOP
alter table dem.identity drop constraint dem_identity_sane_dob cascade;
\set ON_ERROR_STOP 1

alter table dem.identity
	add constraint dem_identity_sane_dob
		check (
			(dob is NULL)
				or
			(dob <= now())
		);

-- --------------------------------------------------------------
-- .dod
\unset ON_ERROR_STOP
alter table dem.identity drop constraint identity_check cascade;
alter table dem.identity drop constraint dem_identity_sane_dod cascade;
\set ON_ERROR_STOP 1

alter table dem.identity
	add constraint dem_identity_sane_dod
		check (
			(deceased is NULL)
				or
			(dob is NULL)
				or
			(deceased >= dob)
		);

-- --------------------------------------------------------------
select gm.log_script_insertion('v16-dem-identity-dynamic.sql', 'v16');

-- ==============================================================