Browse Source

Fix program sequences db view

master
Alex Mikhalev 4 years ago
parent
commit
7efb3b81bd
  1. 8
      src/database/migrations/0006-fix_view_program_seq-down.sql
  2. 15
      src/database/migrations/0006-fix_view_program_seq-up.sql
  3. 1
      src/database/migrations/mod.rs

8
src/database/migrations/0006-fix_view_program_seq-down.sql

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
DROP VIEW program_sequences;
CREATE VIEW program_sequences AS
SELECT psi.program_id program_id,
json_group_array(json_object(
'section_id', psi.section_id,
'duration', psi.duration)) sequence
FROM program_sequence_items as psi;

15
src/database/migrations/0006-fix_view_program_seq-up.sql

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
DROP VIEW program_sequences;
CREATE VIEW program_sequences AS
WITH psi_sorted AS (
SELECT psi.program_id program_id,
json_object(
'section_id', psi.section_id,
'duration', psi.duration)
obj
FROM program_sequence_items AS psi
ORDER BY psi.program_id, psi.seq_num)
SELECT psi_sorted.program_id program_id,
json_group_array(json(psi_sorted.obj)) sequence
FROM psi_sorted
GROUP BY psi_sorted.program_id;

1
src/database/migrations/mod.rs

@ -17,6 +17,7 @@ pub fn create_migrations() -> Migrations { @@ -17,6 +17,7 @@ pub fn create_migrations() -> Migrations {
migs.add(include_file_migration!(3, "0003-table_programs"));
migs.add(include_file_migration!(4, "0004-program_rows"));
migs.add(include_file_migration!(5, "0005-view_program_sequence"));
migs.add(include_file_migration!(6, "0006-fix_view_program_seq"));
// INSERT MIGRATION ABOVE -- DO NOT EDIT THIS COMMENT
migs
}
Loading…
Cancel
Save