CiviForm Docs
HomeAboutContactNewsFAQ
  • CiviForm Docs
  • Overview
    • What is CiviForm?
    • How does CiviForm work?
    • Glossary
  • User Manual
    • CiviForm Admin Guide
      • CiviForm Admin training overview
      • How to navigate CiviForm
      • Working with programs
        • Create a program
        • Edit a program
        • Show or hide questions based on inputs
        • Manage program eligibility
        • Manage address & service area validation
        • Manage notifications
        • How to publish programs
        • Set a pre-screener
      • Working with questions
        • Manage questions
        • Question export settings
        • Universal and Primary Applicant Information questions
        • Using enumerator questions & screens in a program
      • Manage translations for programs & questions
      • Manage versions for programs & questions
      • Working with applications
        • Add statuses to a program
        • Download exported data
      • Role management
        • Manage Program Admins
        • Manage Trusted Intermediaries
      • Manage API keys
      • Using Markdown
      • Migrating programs between environments
    • Program Admin Guide
      • How to become a Program Admin
      • Review completed applications
    • Trusted Intermediary Guide
      • Apply to a program
    • Onboarding Guide
      • Organization assessment
      • Program assessment
      • Getting started with service design
      • Journey mapping
      • Discovery, eligibility, and intake
      • Consolidating questions across programs
      • Working with existing tools and processes
      • Working across jurisdictions
      • Data reporting and other integrations
      • Security and privacy considerations
      • Staffing overview
  • IT Manual
    • Technical Deployment Guide
      • Initial Deployment
        • Terraform deploy system
          • AWS Terraform deployment
        • Authentication setup
        • Email configuration
        • GIS Service configuration
      • Upgrading to a New Release
        • CiviForm server environment variables
          • v1.20.0
          • v1.20.1
          • v1.21.0
          • v1.22.0
          • v1.23.0
          • v1.23.1
          • v1.24.0
          • v1.24.1
          • v1.24.2
          • v1.25.0
          • v1.26.0
          • v1.27.0
          • v1.28.0
          • v1.29.0
          • v1.30.0
          • v1.30.1
          • v1.31.0
          • v1.33.0
          • v1.34.0
          • v1.34.1
          • v1.34.2
          • v1.35.0
          • v1.36.0
          • v1.37.0
          • v1.38.0
          • v1.38.1
          • v1.38.2
          • v1.39.0
          • v1.40.0
          • v1.41.0
          • v1.42.0
          • v1.43.0
          • v1.44.0
          • v1.45.0
          • v1.46.0
          • v1.47.0
          • v1.48.0
          • v1.49.0
          • v1.50.0
          • v1.51.0
          • v1.52.0
          • v1.53.0
          • v1.54.0
          • v1.55.0
          • v1.56.0
          • v1.56.1
          • v1.57.0
          • v1.58.0
          • v1.59.0
          • v1.60.0
          • v1.61.0
          • v1.62.0
          • v1.63.0
          • v2.0.0
          • v2.0.1
          • v2.0.2
          • v2.1.0
          • v2.10.0
          • v2.11.0
          • v2.12.0
          • v2.13.0
          • v2.14.0
          • v2.15.0
          • v2.16.0
          • v2.17.0
          • v2.18.0
          • v2.19.0
          • v2.2.0
          • v2.20.0
          • v2.21.0
          • v2.22.0
          • v2.23.0
          • v2.24.0
          • v2.25.0
          • v2.26.0
          • v2.27.0
          • v2.28.0
          • v2.29.0
          • v2.3.0
          • v2.30.0
          • v2.31.0
          • v2.32.0
          • v2.33.0
          • v2.34.0
          • v2.35.0
          • v2.36.0
          • v2.37.0
          • v2.38.0
          • v2.39.0
          • v2.4.0
          • v2.4.1
          • v2.4.2
          • v2.4.3
          • v2.5.0
          • v2.6.0
          • v2.7.0
          • v2.8.0
          • v2.9.0
      • Monitoring
      • Troubleshooting Production
      • Disaster Recovery
      • Database Disaster Recovery
      • Production Database Access
    • Infrastructure Requirements
    • Existing deployments
    • API Integration
      • Authentication
      • List applications
    • Testing & QA
      • Testing resources
      • SQL queries to look for missing questions
  • Governance & Management
    • Project Management
      • On Call Guide
    • Governance
      • Roles, Committees, & Responsibilities
      • Governance Processes
      • Development Principles
      • Communication
Powered by GitBook
On this page
  • Check Questions For Missing Enumerators
  • Check Programs for Missing Questions

Was this helpful?

Edit on GitHub
Export as PDF
  1. IT Manual
  2. Testing & QA

SQL queries to look for missing questions

Check Questions For Missing Enumerators

This query checks if active version questions are bound to enumerators that are missing. The is_enumerator_missing column will be true if the enumerator does not exist in the questions table.

select
    v.id as versions_id,
    v.lifecycle_stage as versions_lifecycle_stage,
    q.id as questions_id,
    q.name as question_name,
    q.question_type,
    q.enumerator_id,
    case when eq.id is null then true else false end as is_enumerator_missing
from questions as q
inner join versions_questions as vq
    on vq.questions_id = q.id
inner join versions as v
    on vq.versions_id = v.id
left join questions as eq
    on q.enumerator_id = eq.id
where q.enumerator_id is not null
and eq.id is null
and v.lifecycle_stage = 'active'
order by v.id desc

Check Programs for Missing Questions

This query flattens out the program block_definitions json. The debug_notes column will provide a message describing problems that were found.

The query debug_notes currently checks if

  • questionDefinition points to a question that doesn't exist

  • questionDefinition enumerator points to a question that doesn't exist

  • hidePredicate points to a question that doesn't exist

with program_definitions as
(
    select
        v.id as versions_id,
        v.lifecycle_stage as versions_lifecycle_stage,
        p.id as programs_id, 
        p.name as programs_name,
        cast(jsonb_array_elements(p.block_definitions)->>'id' as bigint) as block_definitions_id,
        jsonb_array_elements(p.block_definitions)->>'name' as block_definitions_name,
        cast(jsonb_array_elements(p.block_definitions)->>'repeaterId' as bigint) as block_definitions_repeaterId,
        cast(jsonb_array_elements(p.block_definitions)->'hidePredicate'->'rootNode'->'node'->'questionId' as bigint) as hidePredicate_questionId,
        cast(jsonb_array_elements(jsonb_array_elements(p.block_definitions)->'questionDefinitions')->>'id' as bigint) as questionDefinitions_id,
        cast(jsonb_array_elements(jsonb_array_elements(p.block_definitions)->'questionDefinitions')->>'optional' as bool) as questionDefinitions_optional
        --jsonb_array_elements(p.block_definitions)->'optionalPredicate' as optionalPredicate,
    from programs as p
    inner join versions_programs as vp
        on p.id = vp.programs_id
    inner join versions as v
        on v.id = vp.versions_id
),
program_questions_expanded as
(
    select 
        pd.versions_id, 
        pd.versions_lifecycle_stage,
        pd.programs_id, 
        pd.programs_name, 
    
        -- Block Definition Questions
        pd.block_definitions_id, 
        pd.block_definitions_name, 
        pd.block_definitions_repeaterId, 
        pd.questionDefinitions_id, 
        pd.questionDefinitions_optional,
        qd.id as questions_id, 
        qd.name as questions_name, 
        qd.question_type, 
        case when pd.questionDefinitions_id is not null and qd.id is null 
            then concat('No question found for id "', pd.questionDefinitions_id, '". ') 
            else null 
        end as questionDefinitions_debug_notes,
    
        -- Enumerator
        qd.enumerator_id,
        qe.name as enumerator_questions_name,
        case when qd.enumerator_id is not null and qe.id is null 
            then concat('No question found for enumerator id "', qd.enumerator_id, '". ') 
            else null 
        end as questionDefinitions_enumerator_debug_notes,
    
        -- HidePredicate
        pd.hidePredicate_questionId, 
        qh.name as hidePredicate_name,
        qh.question_type as hidePredicate_question_type,
        case when pd.hidePredicate_questionId is not null and qh.id is null 
            then concat('No question found for hidePredicate question id "', pd.hidePredicate_questionId, '". ') 
            else null 
        end as hidePredicate_debug_notes
    from program_definitions as pd
    left join questions as qd
        on qd.id = pd.questiondefinitions_id
    left join questions as qe
        on qe.id = qd.enumerator_id
    left join questions as qh
       on qh.id = pd.hidepredicate_questionid
)

select
    versions_id, 
    versions_lifecycle_stage,
    programs_id, 
    programs_name, 
    block_definitions_id, 
    block_definitions_name, 
    block_definitions_repeaterId, 
    questionDefinitions_id, 
    questionDefinitions_optional,
    questions_id, 
    questions_name, 
    question_type, 
    enumerator_id,
    enumerator_questions_name,
    hidePredicate_questionId,
    hidePredicate_name,
    hidePredicate_question_type,
    nullif(concat(
        questionDefinitions_debug_notes,
        questionDefinitions_enumerator_debug_notes,
        hidePredicate_debug_notes
    ), '')  as debug_notes
from program_questions_expanded    
where versions_lifecycle_stage = 'active'
--and programs_name = 'Utility Discount Program - Extended'
order by versions_id desc, programs_name, block_definitions_id
PreviousTesting resourcesNextProject Management

Last updated 2 years ago

Was this helpful?