preparation for bed overview
This commit is contained in:
7
src/main/resources/enums/camprole.sql
Normal file
7
src/main/resources/enums/camprole.sql
Normal file
@ -0,0 +1,7 @@
|
||||
create type public.enum_camprole as enum (
|
||||
'student',
|
||||
'teacher',
|
||||
'director',
|
||||
'feeder',
|
||||
'observer'
|
||||
);
|
5
src/main/resources/enums/document.sql
Normal file
5
src/main/resources/enums/document.sql
Normal file
@ -0,0 +1,5 @@
|
||||
create type public.enum_document as enum (
|
||||
'camppass',
|
||||
'location',
|
||||
'camp'
|
||||
);
|
6
src/main/resources/enums/filetype.sql
Normal file
6
src/main/resources/enums/filetype.sql
Normal file
@ -0,0 +1,6 @@
|
||||
create type public.enum_filetype as enum (
|
||||
'pdf',
|
||||
'png',
|
||||
'jpg'
|
||||
);
|
||||
|
4
src/main/resources/enums/module.sql
Normal file
4
src/main/resources/enums/module.sql
Normal file
@ -0,0 +1,4 @@
|
||||
create type public.enum_module as enum (
|
||||
'registration',
|
||||
'business'
|
||||
);
|
8
src/main/resources/enums/role.sql
Normal file
8
src/main/resources/enums/role.sql
Normal file
@ -0,0 +1,8 @@
|
||||
create type public.enum_role as enum (
|
||||
'subscriber',
|
||||
'registrator',
|
||||
'businessman',
|
||||
'admin',
|
||||
'campadmin',
|
||||
'registratoradmin'
|
||||
);
|
4
src/main/resources/enums/sex.sql
Normal file
4
src/main/resources/enums/sex.sql
Normal file
@ -0,0 +1,4 @@
|
||||
create type public.enum_sex as enum (
|
||||
'male',
|
||||
'female'
|
||||
);
|
40
src/main/resources/setup.sql
Normal file
40
src/main/resources/setup.sql
Normal file
@ -0,0 +1,40 @@
|
||||
begin;
|
||||
\i enums/camprole.sql
|
||||
\i enums/document.sql
|
||||
\i enums/filetype.sql
|
||||
\i enums/module.sql
|
||||
\i enums/role.sql
|
||||
\i enums/sex.sql
|
||||
|
||||
\i tables/document.sql
|
||||
\i tables/documentrole.sql
|
||||
\i tables/location.sql
|
||||
\i tables/profile.sql
|
||||
\i tables/camp.sql
|
||||
\i tables/campdocument.sql
|
||||
\i tables/campprofile.sql
|
||||
\i tables/person.sql
|
||||
\i tables/persondocument.sql
|
||||
\i tables/profilerole.sql
|
||||
\i tables/rss.sql
|
||||
\i tables/sales.sql
|
||||
\i tables/salescontenttype.sql
|
||||
\i tables/salescontent.sql
|
||||
|
||||
\i views/adult.sql
|
||||
\i views/sales.sql
|
||||
\i views/budget.sql
|
||||
\i views/camp.sql
|
||||
\i views/camp_budget.sql
|
||||
\i views/camp_budget_year.sql
|
||||
\i views/campdocument.sql
|
||||
\i views/camprole.sql
|
||||
\i views/document.sql
|
||||
\i views/dsgvo_delete_candidate.sql
|
||||
\i views/feeder.sql
|
||||
\i views/profile.sql
|
||||
\i views/registration.sql
|
||||
\i views/role.sql
|
||||
\i views/version.sql
|
||||
|
||||
commit;
|
18
src/main/resources/tables/camp.sql
Normal file
18
src/main/resources/tables/camp.sql
Normal file
@ -0,0 +1,18 @@
|
||||
create table public.t_camp (
|
||||
pk integer not null primary key generated always as identity,
|
||||
name text not null,
|
||||
arrive timestamp without time zone not null,
|
||||
depart timestamp without time zone not null,
|
||||
fk_location integer not null references public.t_location(pk),
|
||||
min_age integer not null,
|
||||
max_age integer not null,
|
||||
price text,
|
||||
countries text,
|
||||
fk_document integer references public.t_document(pk),
|
||||
lock_sales boolean default false not null,
|
||||
fk_profile integer not null references public.t_profile(pk),
|
||||
beds_male integer default 0,
|
||||
beds_female integer default 0,
|
||||
blocked_beds_male integer default 0,
|
||||
blocked_beds_female integer default 0
|
||||
);
|
6
src/main/resources/tables/campdocument.sql
Normal file
6
src/main/resources/tables/campdocument.sql
Normal file
@ -0,0 +1,6 @@
|
||||
create table public.t_campdocument (
|
||||
pk integer not null primary key generated always as identity,
|
||||
fk_camp integer not null references public.t_camp(pk),
|
||||
fk_document integer not null references public.t_document(pk),
|
||||
unique (fk_camp, fk_document)
|
||||
);
|
7
src/main/resources/tables/campprofile.sql
Normal file
7
src/main/resources/tables/campprofile.sql
Normal file
@ -0,0 +1,7 @@
|
||||
create table public.t_campprofile (
|
||||
pk integer not null primary key generated always as identity,
|
||||
fk_profile integer not null references public.t_profile(pk),
|
||||
fk_camp integer not null references public.t_camp(pk),
|
||||
module public.enum_module not null,
|
||||
unique (fk_profile, fk_camp, module)
|
||||
);
|
7
src/main/resources/tables/document.sql
Normal file
7
src/main/resources/tables/document.sql
Normal file
@ -0,0 +1,7 @@
|
||||
create table public.t_document (
|
||||
pk integer not null primary key generated always as identity,
|
||||
doctype public.enum_document,
|
||||
name text unique,
|
||||
document text,
|
||||
filetype public.enum_filetype
|
||||
);
|
6
src/main/resources/tables/documentrole.sql
Normal file
6
src/main/resources/tables/documentrole.sql
Normal file
@ -0,0 +1,6 @@
|
||||
create table public.t_documentrole (
|
||||
pk integer not null primary key generated always as identity,
|
||||
fk_document integer not null references public.t_document(pk),
|
||||
camprole public.enum_camprole not null,
|
||||
unique (fk_document, camprole)
|
||||
);
|
6
src/main/resources/tables/location.sql
Normal file
6
src/main/resources/tables/location.sql
Normal file
@ -0,0 +1,6 @@
|
||||
create table public.t_location (
|
||||
pk integer not null primary key generated always as identity,
|
||||
name text not null,
|
||||
url text,
|
||||
fk_document integer references public.t_document(pk)
|
||||
);
|
23
src/main/resources/tables/person.sql
Normal file
23
src/main/resources/tables/person.sql
Normal file
@ -0,0 +1,23 @@
|
||||
create table public.t_person (
|
||||
pk integer not null primary key generated always as identity,
|
||||
forename text,
|
||||
surname text,
|
||||
street text,
|
||||
zip text,
|
||||
city text,
|
||||
phone text,
|
||||
birthdate date,
|
||||
camprole public.enum_camprole,
|
||||
email text,
|
||||
fk_camp integer references public.t_camp(pk),
|
||||
fk_profile integer references public.t_profile(pk),
|
||||
accept boolean,
|
||||
created timestamp without time zone default now(),
|
||||
sex public.enum_sex,
|
||||
fk_registrator integer references public.t_profile(pk),
|
||||
paid numeric(7,2),
|
||||
comment text,
|
||||
consent_catalog_photo boolean default false not null,
|
||||
required_price numeric(7,2),
|
||||
unique (forename, surname, birthdate, fk_camp)
|
||||
);
|
8
src/main/resources/tables/persondocument.sql
Normal file
8
src/main/resources/tables/persondocument.sql
Normal file
@ -0,0 +1,8 @@
|
||||
create table public.t_persondocument (
|
||||
pk integer not null primary key generated always as identity,
|
||||
fk_person integer not null references public.t_person(pk),
|
||||
name text,
|
||||
document text,
|
||||
filetype public.enum_filetype,
|
||||
unique (fk_person, name)
|
||||
);
|
9
src/main/resources/tables/profile.sql
Normal file
9
src/main/resources/tables/profile.sql
Normal file
@ -0,0 +1,9 @@
|
||||
create table public.t_profile (
|
||||
pk integer not null primary key generated always as identity,
|
||||
forename text,
|
||||
surname text,
|
||||
username text not null unique,
|
||||
password text,
|
||||
duedate timestamp without time zone default (now() + '1 year'::interval),
|
||||
uuid text not null unique
|
||||
);
|
5
src/main/resources/tables/profilerole.sql
Normal file
5
src/main/resources/tables/profilerole.sql
Normal file
@ -0,0 +1,5 @@
|
||||
create table public.t_profilerole (
|
||||
fk_profile integer not null references public.t_profile(pk),
|
||||
role public.enum_role not null,
|
||||
unique (fk_profile, role)
|
||||
);
|
6
src/main/resources/tables/rss.sql
Normal file
6
src/main/resources/tables/rss.sql
Normal file
@ -0,0 +1,6 @@
|
||||
create table public.t_rss (
|
||||
pk integer not null primary key generated always as identity,
|
||||
msg text,
|
||||
regdate timestamp without time zone default now(),
|
||||
recipient text
|
||||
);
|
13
src/main/resources/tables/sales.sql
Normal file
13
src/main/resources/tables/sales.sql
Normal file
@ -0,0 +1,13 @@
|
||||
create table public.t_sales (
|
||||
pk integer not null primary key generated always as identity,
|
||||
trader text,
|
||||
fk_camp integer not null references public.t_camp(pk),
|
||||
provider text,
|
||||
cash numeric(11,2) not null,
|
||||
buydate timestamp without time zone,
|
||||
recipenumber text,
|
||||
recipeshot bytea,
|
||||
recipenote text,
|
||||
incredients text,
|
||||
recipefilename text
|
||||
);
|
5
src/main/resources/tables/salescontent.sql
Normal file
5
src/main/resources/tables/salescontent.sql
Normal file
@ -0,0 +1,5 @@
|
||||
create table public.t_salescontent (
|
||||
fk_sales integer not null references public.t_sales(pk),
|
||||
fk_salescontenttype text not null references public.t_salescontenttype(name),
|
||||
unique (fk_sales, fk_salescontenttype)
|
||||
);
|
3
src/main/resources/tables/salescontenttype.sql
Normal file
3
src/main/resources/tables/salescontenttype.sql
Normal file
@ -0,0 +1,3 @@
|
||||
create table public.t_salescontenttype (
|
||||
name text not null primary key
|
||||
);
|
7
src/main/resources/views/adult.sql
Normal file
7
src/main/resources/views/adult.sql
Normal file
@ -0,0 +1,7 @@
|
||||
create view public.v_adult as
|
||||
select age((t_person.birthdate)::timestamp with time zone) as age,
|
||||
t_person.forename,
|
||||
t_person.surname,
|
||||
t_person.camprole,
|
||||
(age((t_person.birthdate)::timestamp with time zone) > '18 years'::interval) as adult
|
||||
from public.t_person;
|
8
src/main/resources/views/budget.sql
Normal file
8
src/main/resources/views/budget.sql
Normal file
@ -0,0 +1,8 @@
|
||||
create view public.v_budget as
|
||||
select sum(v_sales.cash) as budget,
|
||||
v_sales.fk_camp,
|
||||
v_sales.name,
|
||||
v_sales.location,
|
||||
v_sales.year
|
||||
from public.v_sales
|
||||
group by v_sales.fk_camp, v_sales.name, v_sales.location, v_sales.year;
|
16
src/main/resources/views/camp.sql
Normal file
16
src/main/resources/views/camp.sql
Normal file
@ -0,0 +1,16 @@
|
||||
create view public.v_camp as
|
||||
select c.pk,
|
||||
(c.depart < now()) as is_over,
|
||||
c.name,
|
||||
c.arrive,
|
||||
c.depart,
|
||||
date_part('isoyear'::text, c.arrive) as year,
|
||||
l.name as location_name,
|
||||
c.min_age,
|
||||
c.max_age,
|
||||
l.url,
|
||||
c.price,
|
||||
c.countries,
|
||||
c.fk_document
|
||||
from (public.t_camp c
|
||||
left join public.t_location l on ((c.fk_location = l.pk)));
|
18
src/main/resources/views/camp_budget.sql
Normal file
18
src/main/resources/views/camp_budget.sql
Normal file
@ -0,0 +1,18 @@
|
||||
create view public.v_camp_budget as
|
||||
with x(money, camp) as (
|
||||
select coalesce(t_person.paid, 0.0) as cash,
|
||||
t_person.fk_camp
|
||||
from public.t_person
|
||||
union all
|
||||
select (t_sales.cash * ('-1'::integer)::numeric),
|
||||
t_sales.fk_camp
|
||||
from public.t_sales
|
||||
)
|
||||
select sum(x.money) as budget,
|
||||
c.pk as fk_camp,
|
||||
c.name as camp_name,
|
||||
date_part('year'::text, c.arrive) as year
|
||||
from (x
|
||||
left join public.t_camp c on ((c.pk = x.camp)))
|
||||
group by c.pk, c.name, c.arrive
|
||||
order by c.arrive;
|
6
src/main/resources/views/camp_budget_year.sql
Normal file
6
src/main/resources/views/camp_budget_year.sql
Normal file
@ -0,0 +1,6 @@
|
||||
create view public.v_camp_budget_year as
|
||||
select sum(v_camp_budget.budget) as sum,
|
||||
v_camp_budget.year
|
||||
from public.v_camp_budget
|
||||
group by v_camp_budget.year
|
||||
order by v_camp_budget.year;
|
12
src/main/resources/views/campdocument.sql
Normal file
12
src/main/resources/views/campdocument.sql
Normal file
@ -0,0 +1,12 @@
|
||||
create view public.v_campdocument as
|
||||
select cd.fk_camp,
|
||||
c.name as campname,
|
||||
c.arrive,
|
||||
cd.fk_document,
|
||||
d.document,
|
||||
d.name as documentname,
|
||||
d.doctype,
|
||||
d.filetype
|
||||
from ((public.t_campdocument cd
|
||||
left join public.t_camp c on ((c.pk = cd.fk_camp)))
|
||||
left join public.t_document d on ((d.pk = cd.fk_document)));
|
2
src/main/resources/views/camprole.sql
Normal file
2
src/main/resources/views/camprole.sql
Normal file
@ -0,0 +1,2 @@
|
||||
create view public.v_camprole as
|
||||
select unnest(enum_range(null::public.enum_camprole)) as name;
|
10
src/main/resources/views/document.sql
Normal file
10
src/main/resources/views/document.sql
Normal file
@ -0,0 +1,10 @@
|
||||
create view public.v_document as
|
||||
select d.pk,
|
||||
d.doctype,
|
||||
d.name,
|
||||
d.document,
|
||||
d.filetype,
|
||||
string_agg((r.camprole)::text, ','::text) as roles
|
||||
from (public.t_document d
|
||||
left join public.t_documentrole r on ((r.fk_document = d.pk)))
|
||||
group by d.pk, d.doctype, d.name, d.document, d.filetype;
|
13
src/main/resources/views/dsgvo_delete_candidate.sql
Normal file
13
src/main/resources/views/dsgvo_delete_candidate.sql
Normal file
@ -0,0 +1,13 @@
|
||||
create view public.v_dsgvo_delete_candidate as
|
||||
select p.pk as fk_person,
|
||||
p.forename,
|
||||
p.surname,
|
||||
p.fk_camp,
|
||||
age((p.birthdate)::timestamp with time zone) as age,
|
||||
p.camprole,
|
||||
c.name,
|
||||
c.year,
|
||||
c.is_over
|
||||
from (public.t_person p
|
||||
left join public.v_camp c on ((c.pk = p.fk_camp)))
|
||||
where (age((p.birthdate)::timestamp with time zone) > '21 years'::interval);
|
15
src/main/resources/views/feeder.sql
Normal file
15
src/main/resources/views/feeder.sql
Normal file
@ -0,0 +1,15 @@
|
||||
create view public.v_feeder as
|
||||
select t_person.forename,
|
||||
t_person.surname,
|
||||
t_person.street,
|
||||
t_person.zip,
|
||||
t_person.city,
|
||||
t_person.phone,
|
||||
age(c.arrive, (t_person.birthdate)::timestamp without time zone) as age,
|
||||
t_person.email,
|
||||
t_person.sex,
|
||||
c.name,
|
||||
date_part('year'::text, c.arrive) as year
|
||||
from (public.t_person
|
||||
left join public.t_camp c on ((c.pk = t_person.fk_camp)))
|
||||
where (t_person.camprole = 'feeder'::public.enum_camprole);
|
12
src/main/resources/views/profile.sql
Normal file
12
src/main/resources/views/profile.sql
Normal file
@ -0,0 +1,12 @@
|
||||
create view public.v_profile as
|
||||
select t_profile.pk,
|
||||
t_profile.forename,
|
||||
t_profile.surname,
|
||||
t_profile.username,
|
||||
t_profile.password,
|
||||
t_profile.uuid,
|
||||
array_agg(t_profilerole.role) as roles
|
||||
from (public.t_profile
|
||||
left join public.t_profilerole on ((t_profilerole.fk_profile = t_profile.pk)))
|
||||
where (t_profile.duedate > now())
|
||||
group by t_profile.pk, t_profile.forename, t_profile.surname, t_profile.username, t_profile.password;
|
14
src/main/resources/views/registration.sql
Normal file
14
src/main/resources/views/registration.sql
Normal file
@ -0,0 +1,14 @@
|
||||
create view public.v_registration as
|
||||
select p.pk,
|
||||
p.forename,
|
||||
p.surname,
|
||||
p.street,
|
||||
p.zip,
|
||||
p.city,
|
||||
p.phone,
|
||||
p.birthdate,
|
||||
p.camprole,
|
||||
p.email,
|
||||
(c.name || date_part('isoyear'::text, c.arrive)) as campname
|
||||
from public.t_person p
|
||||
left join public.t_camp c on c.pk = p.fk_camp;
|
2
src/main/resources/views/role.sql
Normal file
2
src/main/resources/views/role.sql
Normal file
@ -0,0 +1,2 @@
|
||||
create view public.v_role as
|
||||
select unnest(enum_range(null::public.enum_role)) as unnest;
|
22
src/main/resources/views/sales.sql
Normal file
22
src/main/resources/views/sales.sql
Normal file
@ -0,0 +1,22 @@
|
||||
create view public.v_sales as
|
||||
select s.pk,
|
||||
s.trader,
|
||||
c.pk as fk_camp,
|
||||
c.name,
|
||||
l.pk as fk_location,
|
||||
l.name as location,
|
||||
s.incredients,
|
||||
date_part('isoyear'::text, c.arrive) as year,
|
||||
s.pk as fk_sales,
|
||||
s.provider,
|
||||
s.cash,
|
||||
s.buydate,
|
||||
s.recipenumber,
|
||||
s.recipeshot,
|
||||
s.recipenote,
|
||||
array_agg(t.fk_salescontenttype) as content
|
||||
from (((public.t_sales s
|
||||
left join public.t_camp c on ((c.pk = s.fk_camp)))
|
||||
left join public.t_location l on ((l.pk = c.fk_location)))
|
||||
left join public.t_salescontent t on ((t.fk_sales = s.pk)))
|
||||
group by s.pk, s.trader, c.pk, c.name, l.pk, l.name, s.incredients, (date_part('isoyear'::text, c.arrive)), s.provider, s.cash, s.buydate, s.recipenumber, s.recipeshot;
|
2
src/main/resources/views/version.sql
Normal file
2
src/main/resources/views/version.sql
Normal file
@ -0,0 +1,2 @@
|
||||
create view public.v_version as
|
||||
select '2024.02'::text as version;
|
Reference in New Issue
Block a user