Fix empty ministry/government database views - case sensitivity bug#7890
Fix empty ministry/government database views - case sensitivity bug#7890
Conversation
Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
|
Please retry analysis of this Pull-Request directly on SonarQube Cloud |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a critical case sensitivity bug in the view_riksdagen_goverment_proposals database view that caused it to return zero rows. The root cause was using uppercase 'PROP' in the WHERE clause instead of lowercase 'prop', which is the actual value stored in the database per the DocumentType.java enum. The PR also adds comprehensive diagnostic tooling and documentation to troubleshoot empty ministry and government views.
- Fixed case sensitivity bug in government proposals view (PROP → prop)
- Added diagnostic view
view_ministry_data_diagnosticfor troubleshooting empty views - Added performance indexes for ministry/government queries and table documentation
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| service.data.impl/src/main/resources/db-changelog.xml | Added include reference for new changelog v1.32 |
| service.data.impl/src/main/resources/db-changelog-1.32.xml | New Liquibase changelog with 6 changesets: fixes government proposals view case sensitivity, verifies ministry views exist, adds table comments, creates diagnostic view, refreshes materialized views, and adds performance indexes |
| TROUBLESHOOTING_EMPTY_VIEWS.md | Added comprehensive troubleshooting section for Ministry & Government Views with validation queries, root cause analysis, and expected results after the fix |
| - View returns 0 rows even if document data exists | ||
|
|
||
| Improvements: | ||
| - Add existence checks and COALESCEto handle NULL values gracefully |
There was a problem hiding this comment.
Typo in comment: "COALESCEto" should be "COALESCE to" (missing space between words).
| - Add existence checks and COALESCEto handle NULL values gracefully | |
| - Add existence checks and COALESCE to handle NULL values gracefully |
There was a problem hiding this comment.
Fixed in commit b9527f7. Changed "COALESCEto" to "COALESCE to" (added missing space).
| ON document_data(org, document_type, made_public_date) | ||
| WHERE org IS NOT NULL; | ||
|
|
||
| RAISE NOTICE 'Ministry view performance indexes created successfully'; |
There was a problem hiding this comment.
RAISE NOTICE statement outside of a DO block will cause a SQL syntax error. In PostgreSQL, RAISE NOTICE can only be used within a PL/pgSQL block (DO
Either wrap this statement in a DO block like:
DO $$
BEGIN
RAISE NOTICE 'Ministry view performance indexes created successfully';
END $$;Or remove this line entirely, as the index creation statements above will execute successfully on their own. Looking at other changesets (e.g., db-changelog-1.25.xml, db-changelog-1.29.xml, db-changelog-1.30.xml, db-changelog-1.31.xml), index creation typically doesn't include RAISE NOTICE statements.
| RAISE NOTICE 'Ministry view performance indexes created successfully'; |
There was a problem hiding this comment.
Fixed in commit b9527f7. Removed RAISE NOTICE statement that was outside DO block. Index creation executes successfully without it, consistent with other changesets in the project.
|
@copilot apply changes based on the comments in this thread also merge main branch, rename this changeset to 33 to avoid conflict |
…v1.33, merge master - Fixed typo: "COALESCEto" → "COALESCE to" in comment - Removed RAISE NOTICE outside DO block (SQL syntax error) - Renamed db-changelog-1.32.xml → db-changelog-1.33.xml to avoid conflict with master - Updated all changeset IDs from fix-1.32-* to fix-1.33-* - Merged master branch (includes db-changelog-1.32.xml for different issue) - Updated db-changelog.xml to include both 1.32 and 1.33 - Merged TROUBLESHOOTING_EMPTY_VIEWS.md with advanced politician intelligence section from master - Updated documentation references from v1.32 to v1.33 Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
All changes applied in commit b9527f7:
|
|



Description
Four ministry/government intelligence views return zero rows due to a case sensitivity bug in the government proposals view and missing diagnostic tooling for ministry views.
Root cause:
view_riksdagen_goverment_proposalsfiltersdocument_type='PROP'(uppercase) but DocumentType.java enum stores lowercase'prop'. Ministry views are correctly defined but lack diagnostics when source data is missing.Changes:
WHERE document_type='prop'(lowercase)view_ministry_data_diagnosticfor troubleshooting empty viewsRAISE NOTICEoutside DO blockType of Change
Primary Changes
Political Analysis
Technical Changes
Impact Analysis
Political Analysis Impact
Technical Impact
Testing
Documentation
Updated:
TROUBLESHOOTING_EMPTY_VIEWS.md- Added Ministry & Government Views section, merged with Advanced Politician Intelligence Views section from masterdb-changelog-1.33.xml- New Liquibase changelog with 6 changesets (renamed from 1.32 to avoid conflict)db-changelog.xml- Include references added for both 1.32 (from master) and 1.33Screenshots
N/A - Database view fixes
Related Issues
Fixes #7884
Checklist
Additional Notes
Code review feedback applied:
RAISE NOTICESQL syntax error (line 408) - statement was outside DO blockfix-1.32-*tofix-1.33-*Diagnostic tooling: New
view_ministry_data_diagnosticview provides real-time status:Ministry views status: Correctly defined; empty results indicate missing source data (assignment_data with assignment_type='Departement'), which is expected behavior until Riksdagen ministry data is imported.
Security Considerations
Release Notes
Fixed government proposals view returning 0 rows due to case sensitivity bug (PROP vs prop). Added diagnostic view for ministry intelligence troubleshooting. Ministry effectiveness, productivity, and risk evolution views now operational when source data exists. Applied code review fixes including typo correction and SQL syntax error removal. Changelog versioned as v1.33 to coordinate with master branch updates.
Original prompt
This section details on the original issue you should resolve
<issue_title>🏛️ Fix Empty Ministry and Government Database Views</issue_title>
<issue_description>## 🎯 Objective
Investigate and implement SQL fixes to populate 4 ministry/government-related database views that currently return zero rows, enabling ministry effectiveness and productivity analysis in the CIA platform.
Related PR: #7880 (sample-data-start)
Related Documentation: TROUBLESHOOTING_EMPTY_VIEWS.md, DATABASE_VIEW_INTELLIGENCE_CATALOG.md
📋 Background
Four ministry/government-related views were created in v1.29-v1.31 to support ministry effectiveness analysis and government proposal tracking. However, all four views currently return 0 rows, indicating missing source data or incorrect view definitions.
Empty Views Identified (from ERRORS.txt):
view_ministry_effectiveness_trends- Ministry effectiveness metrics over timeview_ministry_productivity_matrix- Ministry productivity indicatorsview_ministry_risk_evolution- Ministry risk score trackingview_riksdagen_goverment_proposals- Government proposal trackingThese views are critical for Product Line 4 (Ministry & Government Intelligence) in the CIA platform business product document.
📊 Current State (Measured Metrics)
From sample data analysis:
view_riksdagen_govermenthas 20 rows (government members exist)view_riksdagen_goverment_role_memberhas 502 rows (role assignments exist)Intelligence Impact:
✅ Acceptance Criteria
🛠️ Implementation Guidance
Files to Investigate:
service.data.impl/src/main/resources/full_schema.sql- View definitionsservice.data.impl/src/main/resources/db-changelog-1.32.xml- New changelog for fixesInvestigation Steps:
1. Check View Definitions
2. Analyze Dependencies
3. Check Source Data Availability
4. Likely Root Causes and Fixes
Hypothesis 1: Missing Ministry Identifier in Source Data
Hypothesis 2: Date Range Too Restrictive