version: 2

models:
  - name: dim_school
    description: Canonical school dimension — one row per active URN
    columns:
      - name: urn
        tests: [not_null, unique]
      - name: school_name
        tests: [not_null]
      - name: phase
        tests: [not_null]
      - name: status
        tests:
          - accepted_values:
              values: ["Open"]

  - name: dim_location
    description: School location dimension with PostGIS geometry
    columns:
      - name: urn
        tests:
          - not_null
          - unique
          - relationships:
              to: ref('dim_school')
              field: urn
      - name: postcode
        tests: [not_null]

  - name: map_school_lineage
    description: Predecessor/successor lineage map
    columns:
      - name: urn
        tests: [not_null]

  - name: fact_ks2_performance
    description: KS2 attainment — one row per URN per year
    columns:
      - name: urn
        tests: [not_null]
      - name: year
        tests: [not_null]
    tests:
      - unique:
          column_name: "urn || '-' || year"

  - name: fact_ks4_performance
    description: KS4 attainment — one row per URN per year
    columns:
      - name: urn
        tests: [not_null]
      - name: year
        tests: [not_null]
    tests:
      - unique:
          column_name: "urn || '-' || year"

  - name: fact_ofsted_inspection
    description: Full Ofsted inspection history
    columns:
      - name: urn
        tests: [not_null]
      - name: inspection_date
        tests: [not_null]

  - name: fact_pupil_characteristics
    description: Pupil demographics — one row per URN per year
    columns:
      - name: urn
        tests: [not_null]
      - name: year
        tests: [not_null]

  - name: fact_admissions
    description: School admissions — one row per URN per year
    columns:
      - name: urn
        tests: [not_null]
      - name: year
        tests: [not_null]

  - name: fact_finance
    description: School financial data — one row per URN per year
    columns:
      - name: urn
        tests: [not_null]
      - name: year
        tests: [not_null]

  - name: fact_parent_view
    description: Parent View survey responses
    columns:
      - name: urn
        tests: [not_null]

  - name: fact_deprivation
    description: IDACI deprivation index — one row per URN
    columns:
      - name: urn
        tests: [not_null, unique]
