Skip to content

Commit 8bdab35

Browse files
committed
- Fix ordering of program type to preserve view ordering
1 parent 34b0cc0 commit 8bdab35

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

tdrs-backend/plg/grafana_views/generate_views.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
query_template = """
1818
SELECT {fields}
19-
data_files.program_type,
2019
data_files.section,
2120
data_files.version,
2221
data_files.year,
2322
data_files.quarter,
2423
stt.name AS "STT", -- Select stt_name from the stts table
2524
stt.stt_code AS "STT_CODE", -- Select stt_code from the stts table
26-
stt.region_id AS "REGION" -- Select region from the stts table
25+
stt.region_id AS "REGION", -- Select region from the stts table
26+
data_files.program_type
2727
FROM {table} {record_type}
2828
INNER JOIN
2929
data_files_datafile data_files -- Join with data_files_datafile
@@ -34,18 +34,19 @@
3434
section, -- Select section
3535
year, -- Select fiscal_year
3636
quarter, -- Select fiscal_quarter
37-
MAX(version) AS version -- Get the maximum version for each group
37+
MAX(version) AS version, -- Get the maximum version for each group
38+
program_type -- Select program_type
3839
FROM
3940
data_files_datafile -- Subquery table
4041
GROUP BY
41-
stt_id, section, year, quarter -- Group by columns
42+
stt_id, program_type, section, year, quarter -- Group by columns
4243
) most_recent
4344
ON data_files.stt_id = most_recent.stt_id
44-
AND data_files.program_type = most_recent.program_type,
4545
AND data_files.section = most_recent.section
4646
AND data_files.version = most_recent.version
4747
AND data_files.year = most_recent.year
4848
AND data_files.quarter = most_recent.quarter
49+
AND data_files.program_type = most_recent.program_type
4950
INNER JOIN
5051
stts_stt stt -- Join with the stts table (aliased as stt)
5152
ON data_files.stt_id = stt.id -- Join condition to match stt_id

0 commit comments

Comments
 (0)