corrected view for calculation of camp beds, see #12
This commit is contained in:
parent
f467d21d53
commit
30e07c4bc7
@ -22,7 +22,7 @@ apply plugin: 'java'
|
|||||||
apply plugin: 'maven-publish'
|
apply plugin: 'maven-publish'
|
||||||
|
|
||||||
group = 'de.jottyfan'
|
group = 'de.jottyfan'
|
||||||
version = '2024.02.23'
|
version = '2024.03.07'
|
||||||
|
|
||||||
description = """COJooq"""
|
description = """COJooq"""
|
||||||
|
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
begin;
|
|
||||||
|
|
||||||
alter table camp.t_camp add column beds_male integer not null default 0;
|
|
||||||
alter table camp.t_camp add column beds_female integer not null default 0;
|
|
||||||
alter table camp.t_camp add column blocked_beds_male integer not null default 0;
|
|
||||||
alter table camp.t_camp add column blocked_beds_female integer not null default 0;
|
|
||||||
|
|
||||||
create or replace view camp.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,
|
|
||||||
c.beds_female,
|
|
||||||
c.beds_male,
|
|
||||||
c.blocked_beds_female,
|
|
||||||
c.blocked_beds_male,
|
|
||||||
count(mp.pk) as used_beds_male,
|
|
||||||
count(fp.pk) as used_beds_female
|
|
||||||
from camp.t_camp c
|
|
||||||
left join camp.t_location l on c.fk_location = l.pk
|
|
||||||
left join camp.t_person mp on mp.fk_camp = c.pk
|
|
||||||
and mp.accept = true
|
|
||||||
and mp.sex = 'male'::camp.enum_sex
|
|
||||||
and mp.camprole = 'student'::camp.enum_camprole
|
|
||||||
left join camp.t_person fp on fp.fk_camp = c.pk
|
|
||||||
and fp.accept = true
|
|
||||||
and fp.sex = 'female'::camp.enum_sex
|
|
||||||
and fp.camprole = 'student'::camp.enum_camprole
|
|
||||||
group by c.pk, c.depart, c.name, c.arrive, l.name, c.min_age, c.max_age, l.url, c.price, c.countries,
|
|
||||||
c.fk_document, c.beds_female, c.beds_male, c.blocked_beds_female, c.blocked_beds_male;
|
|
||||||
|
|
||||||
create or replace view camp.v_version as
|
|
||||||
select '2024.02'::text as version;
|
|
||||||
|
|
||||||
drop schema public;
|
|
||||||
alter schema camp rename to public;
|
|
||||||
|
|
||||||
commit;
|
|
6
src/main/resources/upgrade_2024-03-07.sql
Normal file
6
src/main/resources/upgrade_2024-03-07.sql
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
begin;
|
||||||
|
|
||||||
|
\i views/camp.sql
|
||||||
|
\i views/version.sql
|
||||||
|
|
||||||
|
commit;
|
@ -1,33 +1,38 @@
|
|||||||
create view public.v_camp as
|
create or replace view public.v_camp as
|
||||||
select c.pk,
|
with fbeds(used_beds_female, fk_camp) as (
|
||||||
(c.depart < now()) as is_over,
|
select count(1), fk_camp
|
||||||
c.name,
|
from t_person
|
||||||
c.arrive,
|
where accept = true
|
||||||
c.depart,
|
and sex = 'female'
|
||||||
date_part('isoyear'::text, c.arrive) as year,
|
and camprole = 'student'
|
||||||
l.name as location_name,
|
group by fk_camp
|
||||||
c.min_age,
|
), mbeds(used_beds_male, fk_camp) as (
|
||||||
c.max_age,
|
select count(1), fk_camp
|
||||||
l.url,
|
from t_person
|
||||||
c.price,
|
where accept = true
|
||||||
c.countries,
|
and sex = 'male'
|
||||||
c.fk_document,
|
and camprole = 'student'
|
||||||
c.beds_female,
|
group by fk_camp
|
||||||
c.beds_male,
|
) select c.pk,
|
||||||
c.blocked_beds_female,
|
(c.depart < now()) as is_over,
|
||||||
c.blocked_beds_male,
|
c.name,
|
||||||
count(mp.pk) as used_beds_male,
|
c.arrive,
|
||||||
count(fp.pk) as used_beds_female
|
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,
|
||||||
|
c.beds_female,
|
||||||
|
c.beds_male,
|
||||||
|
c.blocked_beds_female,
|
||||||
|
c.blocked_beds_male,
|
||||||
|
mbeds.used_beds_male,
|
||||||
|
fbeds.used_beds_female
|
||||||
from public.t_camp c
|
from public.t_camp c
|
||||||
left join public.t_location l on c.fk_location = l.pk
|
left join public.t_location l on c.fk_location = l.pk
|
||||||
left join public.t_person mp on mp.fk_camp = c.pk
|
left join mbeds on mbeds.fk_camp = c.pk
|
||||||
and mp.accept = true
|
left join fbeds on fbeds.fk_camp = c.pk;
|
||||||
and mp.sex = 'male'::enum_sex
|
|
||||||
and mp.camprole = 'student'::enum_camprole
|
|
||||||
left join public.t_person fp on fp.fk_camp = c.pk
|
|
||||||
and fp.accept = true
|
|
||||||
and fp.sex = 'female'::enum_sex
|
|
||||||
and fp.camprole = 'student'::enum_camprole
|
|
||||||
group by c.pk, c.depart, c.name, c.arrive, l.name, c.min_age, c.max_age, l.url, c.price, c.countries,
|
|
||||||
c.fk_document, c.beds_female, c.beds_male, c.blocked_beds_female, c.blocked_beds_male;
|
|
||||||
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
create view public.v_version as
|
create or replace view public.v_version as
|
||||||
select '2024.02'::text as version;
|
select '2024.03.07'::text as version;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user