Zalámané SQL, aby se dalo číst
This commit is contained in:
parent
ba546353d8
commit
3815b5a8a8
1 changed files with 143 additions and 5 deletions
|
@ -721,8 +721,35 @@ class Migration(migrations.Migration):
|
|||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cisla', to='seminar.Rocnik', verbose_name='ročník'),
|
||||
),
|
||||
migrations.RunSQL(
|
||||
sql="\ncreate view seminar_body_za_cislo as\n select\n sr.cislo_body_id || '-' || sr.resitel_id as id,\n sr.cislo_body_id as cislo_id,\n sr.resitel_id as resitel_id,\n sum(sr.body) as body\n from seminar_reseni as sr\n group by sr.cislo_body_id, sr.resitel_id\n order by body desc;\n\ncreate view seminar_body_k_cislu as\n select\n akt_c.id || '-' || min_bzc.resitel_id as id,\n akt_c.id as cislo_id,\n min_bzc.resitel_id as resitel_id,\n max(akt_bzc.body) as body,\n sum(min_bzc.body) as body_celkem\n from ((seminar_cisla as akt_c\n inner join seminar_cisla as min_c on min_c.rocnik_id = akt_c.rocnik_id and akt_c.cislo >= min_c.cislo)\n inner join seminar_body_za_cislo as min_bzc on min_c.id = min_bzc.cislo_id)\n left outer join seminar_body_za_cislo as akt_bzc on akt_bzc.cislo_id = akt_c.id and akt_bzc.resitel_id = min_bzc.resitel_id \n group by akt_c.id, min_bzc.resitel_id, akt_bzc.resitel_id\n order by body_celkem desc;\n",
|
||||
reverse_sql='\ndrop view seminar_body_k_cislu;\ndrop view seminar_body_za_cislo;\n',
|
||||
sql="
|
||||
create view seminar_body_za_cislo as
|
||||
select
|
||||
sr.cislo_body_id || '-' || sr.resitel_id as id,
|
||||
sr.cislo_body_id as cislo_id,
|
||||
sr.resitel_id as resitel_id,
|
||||
sum(sr.body) as body
|
||||
from seminar_reseni as sr
|
||||
group by sr.cislo_body_id, sr.resitel_id
|
||||
order by body desc;
|
||||
|
||||
create view seminar_body_k_cislu as
|
||||
select
|
||||
akt_c.id || '-' || min_bzc.resitel_id as id,
|
||||
akt_c.id as cislo_id,
|
||||
min_bzc.resitel_id as resitel_id,
|
||||
max(akt_bzc.body) as body,
|
||||
sum(min_bzc.body) as body_celkem
|
||||
from ((seminar_cisla as akt_c
|
||||
inner join seminar_cisla as min_c on min_c.rocnik_id = akt_c.rocnik_id and akt_c.cislo >= min_c.cislo)
|
||||
inner join seminar_body_za_cislo as min_bzc on min_c.id = min_bzc.cislo_id)
|
||||
left outer join seminar_body_za_cislo as akt_bzc on akt_bzc.cislo_id = akt_c.id and akt_bzc.resitel_id = min_bzc.resitel_id
|
||||
group by akt_c.id, min_bzc.resitel_id, akt_bzc.resitel_id
|
||||
order by body_celkem desc;
|
||||
",
|
||||
reverse_sql='
|
||||
drop view seminar_body_k_cislu;
|
||||
drop view seminar_body_za_cislo;
|
||||
',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='reseni',
|
||||
|
@ -956,7 +983,31 @@ class Migration(migrations.Migration):
|
|||
field=models.DecimalField(blank=True, decimal_places=1, max_digits=8, null=True, verbose_name='body'),
|
||||
),
|
||||
migrations.RunSQL(
|
||||
sql="\ncreate view seminar_body_za_cislo as\n select\n sr.cislo_body_id || '-' || sr.resitel_id as id,\n sr.cislo_body_id as cislo_id,\n sr.resitel_id as resitel_id,\n sum(sr.body) as body\n from seminar_reseni as sr\n group by sr.cislo_body_id, sr.resitel_id\n order by body desc;\n\ncreate view seminar_body_k_cislu as\n select\n akt_c.id || '-' || min_bzc.resitel_id as id,\n akt_c.id as cislo_id,\n min_bzc.resitel_id as resitel_id,\n max(akt_bzc.body) as body,\n sum(min_bzc.body) as body_celkem\n from ((seminar_cisla as akt_c\n inner join seminar_cisla as min_c on min_c.rocnik_id = akt_c.rocnik_id and akt_c.cislo >= min_c.cislo)\n inner join seminar_body_za_cislo as min_bzc on min_c.id = min_bzc.cislo_id)\n left outer join seminar_body_za_cislo as akt_bzc on akt_bzc.cislo_id = akt_c.id and akt_bzc.resitel_id = min_bzc.resitel_id \n group by akt_c.id, min_bzc.resitel_id, akt_bzc.resitel_id\n order by body_celkem desc;\n",
|
||||
sql="
|
||||
create view seminar_body_za_cislo as
|
||||
select
|
||||
sr.cislo_body_id || '-' || sr.resitel_id as id,
|
||||
sr.cislo_body_id as cislo_id,
|
||||
sr.resitel_id as resitel_id,
|
||||
sum(sr.body) as body
|
||||
from seminar_reseni as sr
|
||||
group by sr.cislo_body_id, sr.resitel_id
|
||||
order by body desc;
|
||||
|
||||
create view seminar_body_k_cislu as
|
||||
select
|
||||
akt_c.id || '-' || min_bzc.resitel_id as id,
|
||||
akt_c.id as cislo_id,
|
||||
min_bzc.resitel_id as resitel_id,
|
||||
max(akt_bzc.body) as body,
|
||||
sum(min_bzc.body) as body_celkem
|
||||
from ((seminar_cisla as akt_c
|
||||
inner join seminar_cisla as min_c on min_c.rocnik_id = akt_c.rocnik_id and akt_c.cislo >= min_c.cislo)
|
||||
inner join seminar_body_za_cislo as min_bzc on min_c.id = min_bzc.cislo_id)
|
||||
left outer join seminar_body_za_cislo as akt_bzc on akt_bzc.cislo_id = akt_c.id and akt_bzc.resitel_id = min_bzc.resitel_id
|
||||
group by akt_c.id, min_bzc.resitel_id, akt_bzc.resitel_id
|
||||
order by body_celkem desc;
|
||||
",
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Novinky',
|
||||
|
@ -1007,10 +1058,97 @@ class Migration(migrations.Migration):
|
|||
field=models.CharField(choices=[(b'jarni', 'Jarní soustředění'), (b'podzimni', 'Podzimní soustředění'), (b'vikend', 'Víkendový sraz')], default=b'podzimni', max_length=16, verbose_name='typ akce'),
|
||||
),
|
||||
migrations.RunSQL(
|
||||
sql="\ndrop view seminar_body_k_cislu;\ndrop view seminar_body_za_cislo;\n\ncreate view seminar_body_za_cislo as\n select\n seminar_reseni.cislo_body_id || '-' || seminar_reseni.resitel_id as id,\n seminar_reseni.cislo_body_id as cislo_id,\n seminar_reseni.resitel_id as resitel_id,\n seminar_cisla.cislo as cislo,\n seminar_cisla.rocnik_id as rocnik_id,\n seminar_rocniky.rocnik as rocnik,\n seminar_cisla.verejna_vysledkovka as verejna_vysledkovka,\n sum(seminar_reseni.body) as body\n from\n seminar_reseni\n inner join seminar_cisla on seminar_reseni.cislo_body_id = seminar_cisla.id\n inner join seminar_rocniky on seminar_cisla.rocnik_id = seminar_rocniky.id\n group by seminar_reseni.cislo_body_id, seminar_reseni.resitel_id, seminar_cisla.cislo,\n seminar_cisla.rocnik_id, seminar_rocniky.rocnik, seminar_cisla.verejna_vysledkovka\n order by body desc;\n\ncreate view seminar_body_k_cislu_rocnik as\n select\n akt_body.id as id,\n akt_body.cislo_id as cislo_id,\n akt_body.resitel_id as resitel_id,\n akt_body.body as body,\n sum(min_body.body) as body_celkem\n from\n seminar_body_za_cislo as akt_body\n inner join seminar_body_za_cislo as min_body on\n (akt_body.resitel_id = min_body.resitel_id and\n (akt_body.rocnik = min_body.rocnik and akt_body.cislo >= min_body.cislo)\n )\n group by akt_body.id, akt_body.cislo_id, akt_body.resitel_id, akt_body.body\n order by body_celkem desc;\n\ncreate view seminar_body_k_cislu_odjakziva as\n select\n akt_body.id as id,\n akt_body.cislo_id as cislo_id,\n akt_body.resitel_id as resitel_id,\n akt_body.body as body,\n sum(min_body.body) as body_celkem\n from\n seminar_body_za_cislo as akt_body\n inner join seminar_body_za_cislo as min_body on\n (akt_body.resitel_id = min_body.resitel_id and\n ((akt_body.rocnik = min_body.rocnik and akt_body.cislo >= min_body.cislo) or\n (akt_body.rocnik < min_body.rocnik)\n )\n )\n group by akt_body.id, akt_body.cislo_id, akt_body.resitel_id, akt_body.body\n order by body_celkem desc;\n\n",
|
||||
sql="
|
||||
drop view seminar_body_k_cislu;
|
||||
drop view seminar_body_za_cislo;
|
||||
|
||||
create view seminar_body_za_cislo as
|
||||
select
|
||||
seminar_reseni.cislo_body_id || '-' || seminar_reseni.resitel_id as id,
|
||||
seminar_reseni.cislo_body_id as cislo_id,
|
||||
seminar_reseni.resitel_id as resitel_id,
|
||||
seminar_cisla.cislo as cislo,
|
||||
seminar_cisla.rocnik_id as rocnik_id,
|
||||
seminar_rocniky.rocnik as rocnik,
|
||||
seminar_cisla.verejna_vysledkovka as verejna_vysledkovka,
|
||||
sum(seminar_reseni.body) as body
|
||||
from
|
||||
seminar_reseni
|
||||
inner join seminar_cisla on seminar_reseni.cislo_body_id = seminar_cisla.id
|
||||
inner join seminar_rocniky on seminar_cisla.rocnik_id = seminar_rocniky.id
|
||||
group by seminar_reseni.cislo_body_id, seminar_reseni.resitel_id, seminar_cisla.cislo,
|
||||
seminar_cisla.rocnik_id, seminar_rocniky.rocnik, seminar_cisla.verejna_vysledkovka
|
||||
order by body desc;
|
||||
|
||||
create view seminar_body_k_cislu_rocnik as
|
||||
select
|
||||
akt_body.id as id,
|
||||
akt_body.cislo_id as cislo_id,
|
||||
akt_body.resitel_id as resitel_id,
|
||||
akt_body.body as body,
|
||||
sum(min_body.body) as body_celkem
|
||||
from
|
||||
seminar_body_za_cislo as akt_body
|
||||
inner join seminar_body_za_cislo as min_body on
|
||||
(akt_body.resitel_id = min_body.resitel_id and
|
||||
(akt_body.rocnik = min_body.rocnik and akt_body.cislo >= min_body.cislo)
|
||||
)
|
||||
group by akt_body.id, akt_body.cislo_id, akt_body.resitel_id, akt_body.body
|
||||
order by body_celkem desc;
|
||||
|
||||
create view seminar_body_k_cislu_odjakziva as
|
||||
select
|
||||
akt_body.id as id,
|
||||
akt_body.cislo_id as cislo_id,
|
||||
akt_body.resitel_id as resitel_id,
|
||||
akt_body.body as body,
|
||||
sum(min_body.body) as body_celkem
|
||||
from
|
||||
seminar_body_za_cislo as akt_body
|
||||
inner join seminar_body_za_cislo as min_body on
|
||||
(akt_body.resitel_id = min_body.resitel_id and
|
||||
((akt_body.rocnik = min_body.rocnik and akt_body.cislo >= min_body.cislo) or
|
||||
(akt_body.rocnik < min_body.rocnik)
|
||||
)
|
||||
)
|
||||
group by akt_body.id, akt_body.cislo_id, akt_body.resitel_id, akt_body.body
|
||||
order by body_celkem desc;
|
||||
|
||||
",
|
||||
),
|
||||
migrations.RunSQL(
|
||||
sql="\n\ndrop view seminar_body_k_cislu_rocnik;\ncreate view seminar_body_k_cislu_rocnik as\n select\n seminar_cisla.id || '-' || min_body.resitel_id as id,\n seminar_cisla.id as cislo_id,\n min_body.resitel_id as resitel_id,\n sum(min_body.body) as body\n from\n seminar_cisla\n inner join seminar_body_za_cislo as min_body on\n (min_body.rocnik_id = seminar_cisla.rocnik_id and seminar_cisla.cislo >= min_body.cislo)\n group by seminar_cisla.id, min_body.resitel_id\n order by body desc;\n\ndrop view seminar_body_k_cislu_odjakziva;\ncreate view seminar_body_k_cislu_odjakziva as\n select\n seminar_cisla.id || '-' || min_body.resitel_id as id,\n seminar_cisla.id as cislo_id,\n min_body.resitel_id as resitel_id,\n sum(min_body.body) as body\n from\n seminar_cisla\n inner join seminar_rocniky on\n (seminar_cisla.rocnik_id = seminar_rocniky.id)\n inner join seminar_body_za_cislo as min_body on\n (min_body.rocnik_id = seminar_cisla.rocnik_id and seminar_cisla.cislo >= min_body.cislo) or\n (min_body.rocnik < seminar_rocniky.rocnik)\n group by seminar_cisla.id, min_body.resitel_id\n order by body desc;\n",
|
||||
sql="
|
||||
drop view seminar_body_k_cislu_rocnik;
|
||||
create view seminar_body_k_cislu_rocnik as
|
||||
select
|
||||
seminar_cisla.id || '-' || min_body.resitel_id as id,
|
||||
seminar_cisla.id as cislo_id,
|
||||
min_body.resitel_id as resitel_id,
|
||||
sum(min_body.body) as body
|
||||
from
|
||||
seminar_cisla
|
||||
inner join seminar_body_za_cislo as min_body on
|
||||
(min_body.rocnik_id = seminar_cisla.rocnik_id and seminar_cisla.cislo >= min_body.cislo)
|
||||
group by seminar_cisla.id, min_body.resitel_id
|
||||
order by body desc;
|
||||
|
||||
drop view seminar_body_k_cislu_odjakziva;
|
||||
create view seminar_body_k_cislu_odjakziva as
|
||||
select
|
||||
seminar_cisla.id || '-' || min_body.resitel_id as id,
|
||||
seminar_cisla.id as cislo_id,
|
||||
min_body.resitel_id as resitel_id,
|
||||
sum(min_body.body) as body
|
||||
from
|
||||
seminar_cisla
|
||||
inner join seminar_rocniky on
|
||||
(seminar_cisla.rocnik_id = seminar_rocniky.id)
|
||||
inner join seminar_body_za_cislo as min_body on
|
||||
(min_body.rocnik_id = seminar_cisla.rocnik_id and seminar_cisla.cislo >= min_body.cislo) or
|
||||
(min_body.rocnik < seminar_rocniky.rocnik)
|
||||
group by seminar_cisla.id, min_body.resitel_id
|
||||
order by body desc;
|
||||
",
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='VysledkyCelkemKCislu',
|
||||
|
|
Loading…
Reference in a new issue