What if

What if: Renaming user_services public.organizations.organization_name to name

Broken: 23 certified dashboards, 167 charts, 33 datasets. Broken 23, Safe 27.

Answered offline in 1.06 s from the map built 2026-11-12 (50 published and certified dashboards). Same rules as a release check, with column lineage.

Dashboards (most used first)

DashboardVerdictCharts it touches
Finance DashboardBrokenBudget Utilization, Net Working Capital vs Gross Working Capital, Total Account Receivable
IncidentsBrokenBreakdown of Incident Categories, Breakdown of Incidents by Project, Incidents Details, Incidents Over Time, Incidents by Category Count +2
WHS&E DashboardBrokenIncidents by Status, Incidents by Type, Incidents by Type/Status, No. of Sign In to Site, Site Attendance (No. of Sign-Ins)
List of SubcontractorsBrokenInvitee ORGs
Site AttendanceBrokenAttendance Per Org Per Month, Attendance Per Org Per Week, Daily, Man Count Line Chart
Defects LeaderboardBroken# of Open Defects, Average Days to Close, Defects Leaderboard by Person (Raised Most Defects), Defects by Building, Overdue % +2
Signed Into Site vs Prestart CheckBrokenPrestart
Expiring SWMS & InsurancesBrokenInsurance Renewal Queue (Next 30 Days), Insurances Expiring in 30 Days, Insurances by Expiry Status, SWMS Renewal Queue (Next 30 Days), SWMS by Expiry Status +1
Subcontractor StatisticsBrokenCompleted Permits, Inspection Details, Inspection Pivot Table, Meeting Details, Number Permits Completed by Date +2
Observations - Detailed ViewBrokenObservations - Detailed View
Injury LeaderboardBrokenInjury Leaderboard, Injury Leaderboard Comparison
Payment RunBrokenPayment Run
Safety Management Plans (SMPs)BrokenSMP Pie, SMPs, SMPs Pending
InjuriesBrokenBreakdown of Injuries by Project, Breakdown of Injury Categories, Injuries Details, Injuries Over Time, Injury Category +3
Observations AdvancedBroken# of Observations, # of Observations Raised Over Time, # of Observations by Conformance, # of Observations by Priorities, # of Observations by Statuses +10
Site Management: Quality ObservationsBroken# of Overdue Quality Observations, # of Quality Observations, # of Quality Observations Raised Over Time, # of Quality Observations by Conformances, # of Quality Observations by Priorities +10
SurveysBrokenAnswer distribution per question, Avg response time by campaign, Campaign performance table, Chase-up list, Comments table +16
Blacklist & WarningsBrokenBlacklist Leaderboard by Org, Top Reasons for Blacklisting, Total Active Blacklisted Personnel, Total Blacklisted Subcontractors, Total Blacklisted Workers +4
Observations - LeaderboardBrokenAvg Days to Close, Best Performing Projects, Leaderboard Observations, Leaderboard Timeline, Least Overdue Projects +3
Weekly InjuriesBrokenCause of Injuries, Current Week Ending, Injuries Per Subcontractor (All Sites), Injuries Per Subcontractor (All Sites) Previous Week, Injuries Per Subcontractor (All Sites) This Week +4
Equipment ServicingBroken# of After Next Month Equipment Servicing, # of Due After Next Month Equipment Servicing by Category, # of Due Today Equipment Servicing, # of Due Today Equipment Servicing by Category, # of Due in 24 Hours Equipment Servicing +17
Observations - Leaderboard by TypeBroken#1 Organization's Most Type, #2 Organization's Most Type, #3 Organization's Most Type, #4 Organization's Most Type, #5 Organization's Most Type +1
Vendor RatingsBrokenVendor Rating Comments, Vendor Ratings Summary

Why: the path to each dashboard

  • Finance Dashboard (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → project_services.user_schema.organizations → project_services.reporting.mv_ar_monthly → dataset "DATASET_Total Accounts Receivable" → 3 chart(s)
  • Incidents (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → dataset "incidents" → 7 chart(s)
  • WHS&E Dashboard (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → dataset "incidents" → 5 chart(s)
  • List of Subcontractors (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → project_services.user_schema.organizations → project_services.reporting.mv_invitee_orgs → dataset "DATASET_Invitee ORGs" → 1 chart(s)
  • Site Attendance (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → dataset "DATASET_Attendance Per Org Per Week" → 4 chart(s)
  • Defects Leaderboard (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → site_management_services.public.mv_defect_by_type → dataset "DATASET_MV Defect By Type" → 7 chart(s)
  • Signed Into Site vs Prestart Check (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → site_management_services.public.mv_prestart → dataset "DATASET_Prestart" → 1 chart(s)
  • Expiring SWMS & Insurances (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → dataset "DATASET_Expiring SWMS" → 6 chart(s)
  • Subcontractor Statistics (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → dataset "DATASET_Total Workers" → 7 chart(s)
  • Observations - Detailed View (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → site_management_services.public.mv_obs_detail → dataset "DATASET_Observations - Detailed View" → 1 chart(s)
  • Injury Leaderboard (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → dataset "DATASET_Injury Leaderboard" → 3 chart(s)
  • Payment Run (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → project_services.user_schema.organizations → project_services.reporting.mv_weekly_payment_run → dataset "DATASET_Weekly Payment Run" → 1 chart(s)
  • Safety Management Plans (SMPs) (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → dataset "DATASET_SELECT * FROM smp" → 3 chart(s)
  • Injuries (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → dataset "injuries" → 8 chart(s)
  • Observations Advanced (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → dataset "DATASET_SELECT * FROM observations" → 15 chart(s)
  • Site Management: Quality Observations (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → dataset "DATASET_SELECT * FROM quality_observations" → 15 chart(s)
  • Surveys (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → dataset "DATASET_Survey Responses" → 21 chart(s)
  • Blacklist & Warnings (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → site_management_services.public.mv_blacklist_warnings → dataset "DATASET_Blacklist & Warnings" → 10 chart(s)
  • Observations - Leaderboard (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → dataset "DATASET_SELECT * FROM observations" → 8 chart(s)
  • Weekly Injuries (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → dataset "DATASET_SELECT * FROM injuries" → 11 chart(s)
  • Equipment Servicing (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → dataset "DATASET_SELECT * FROM equipments" → 22 chart(s)
  • Observations - Leaderboard by Type (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → site_management_services.user_schema.organizations → dataset "DATASET_Observations Type Rank" → 6 chart(s)
  • Vendor Ratings (Broken, high): renameColumn user_services.public.organizations column organization_name (renamed to name).
    • Path: user_services.public.organizations → project_services.user_schema.organizations → dataset "DATASET_Vendor Ratings" → 2 chart(s)

Where it appears (definitions only, no data)

  • materialized view project_services.reporting.mv_ar_monthly: o.organization_name,
  • dataset "incidents" (id 29): o.organization_name,
  • dataset "DATASET_Attendance Per Org Per Day" (id 53): o.organization_name, · u.project_id, u.project_uuid, o.organization_name, raw_date
  • materialized view project_services.reporting.mv_invitee_orgs: o_owner.organization_name AS inviter_org_name, · o_inv.organization_name AS invitee_org_name
  • dataset "DATASET_SYD List of Subcontractors" (id 197): o_owner.organization_name AS inviter_org_name, · o_inv.organization_name AS invitee_org_name
  • materialized view site_management_services.public.mv_defect_by_type: o.organization_name · ua.organization_name AS assign_to_organization_name, · uc.organization_name AS created_by_organization_name, (+1 more lines)
  • dataset "DATASET_Attendance Per Org Per Week" (id 51): o.organization_name, · organization_name, · project_id, project_uuid, organization_name, local_date (+3 more lines)
  • dataset "DATASET_Attendance Per Org Per Month" (id 52): o.organization_name, · ad.organization_name, · ad.project_id, ad.project_uuid, ad.organization_name, month_start
  • dataset "DATASET_All Site Attendance" (id 59): o.organization_name, · a.project_id, a.project_uuid, o.organization_name, raw_date
  • materialized view site_management_services.public.mv_prestart: o.organization_name,
  • dataset "DATASET_Expiring SWMS" (id 195): o.organization_name,
  • dataset "DATASET_Expiring Insurances" (id 196): o.organization_name,
  • … 19 more objects

Fix plan (a draft to discuss; the tool never applies anything)

  1. In project_services, point the foreign table at the new name so nothing above it changes: ALTER FOREIGN TABLE user_schema.organizations ALTER COLUMN organization_name OPTIONS (ADD column_name 'name'); (same release as the migration).
  2. In site_management_services, point the foreign table at the new name so nothing above it changes: ALTER FOREIGN TABLE user_schema.organizations ALTER COLUMN organization_name OPTIONS (ADD column_name 'name'); (same release as the migration).
  3. Safer alternative (expand/contract): add the new column, write both for one release, move reports, then drop the old one.

Fix drafts (SQL to review and run by hand; never applied by the tool)

Point foreign table project_services.user_schema.organizations at the new name (project_services; parses with sqlglot, uses the new name)

ALTER FOREIGN TABLE user_schema.organizations
  ALTER COLUMN organization_name OPTIONS (ADD column_name 'name');

Run in the same release as the migration. Every view, MV and dataset above it keeps working unchanged.

Point foreign table site_management_services.user_schema.organizations at the new name (site_management_services; parses with sqlglot, uses the new name)

ALTER FOREIGN TABLE user_schema.organizations
  ALTER COLUMN organization_name OPTIONS (ADD column_name 'name');

Run in the same release as the migration. Every view, MV and dataset above it keeps working unchanged.

Alternative: re-import the foreign tables instead (31 drafts)

Re-import project_services.user_schema.organizations (project_services; DDL, check by eye)

DROP FOREIGN TABLE user_schema.organizations;  -- add CASCADE only together with the view/MV drafts below
IMPORT FOREIGN SCHEMA public LIMIT TO (organizations)
  FROM SERVER user_srv INTO user_schema;

Brings in the new column name; the readers below must then use it.

Materialized view project_services.reporting.mv_weekly_payment_run: organization_name → name AS organization_name (project_services; parses with sqlglot, uses the new name)

DROP MATERIALIZED VIEW reporting.mv_weekly_payment_run;
CREATE MATERIALIZED VIEW reporting.mv_weekly_payment_run AS
 SELECT prj.id AS project_id,
    prj.uuid AS project_uuid,
    prj.title AS "Project",
    b.invoice_date AS "Invoice Date",
    b.invoice_claim_no AS "Invoice Number",
    b.invoice_uuid AS "Invoice UUID",
    COALESCE(sub_org.name, b.supplier_name) AS "Vendor",
    b.invoice_type AS "Invoice Type",
    b.payment_amount_excl_gst AS "Payment Amount (excl. GST)",
    b.po_number AS "PO / Contract Number",
    b.po_contract_description AS "PO / Contract Description",
    b.po_cost_committed AS "PO / Contract Value",
    b.po_cost_committed - b.po_amount_approved AS "Contract/PO Balance",
        CASE
            WHEN b.po_amount_approved <> 0::numeric THEN b.po_cost_committed / b.po_amount_approved * 100::numeric
            ELSE NULL::numeric
        END AS "% of Completion",
    concat_ws(' '::text, NULLIF(au.first_name::text, ''::text), NULLIF(au.last_name::text, ''::text)) AS "End Approver"
   FROM finance_schema.mv_payment_run_base b
     LEFT JOIN projects prj ON prj.id = b.project_id
     LEFT JOIN user_schema.users sub_user ON sub_user.id = b.subcontract_user_id
     LEFT JOIN user_schema.organizations sub_org ON sub_org.id = sub_user.organization_id
     LEFT JOIN reporting.mv_invoice_end_approver wea ON wea.invoice_uuid = b.invoice_uuid::text
     LEFT JOIN user_schema.users au ON au.uuid::text = wea.approved_by_uuid;;
-- then recreate its indexes and grants (see the production definition)

Keeps the MV's own column names, so everything above it is unchanged.

Materialized view project_services.reporting.mv_ar_monthly: organization_name → name AS organization_name (project_services; parses with sqlglot, uses the new name)

DROP MATERIALIZED VIEW reporting.mv_ar_monthly;
CREATE MATERIALIZED VIEW reporting.mv_ar_monthly AS
 WITH approved_claims_monthly AS (
         SELECT h.project_uuid::uuid AS project_uuid,
            date_trunc('month'::text, (h.meta ->> 'approved_rejected_date'::text)::timestamp with time zone) AS month_start,
            sum(COALESCE(NULLIF(h.meta ->> 'approved_total_invoice_variation'::text, ''::text)::numeric, 0::numeric)) AS total_accounts_receivable
           FROM finance_schema.head_contract_claim_histories h
          WHERE h.type::text = 'CLAIM'::text AND h.is_variation = false AND (h.meta ->> 'approval_status'::text) = 'APPROVED'::text AND (h.meta ->> 'approved_rejected_date'::text) IS NOT NULL
          GROUP BY h.project_uuid, (date_trunc('month'::text, (h.meta ->> 'approved_rejected_date'::text)::timestamp with time zone))
        )
 SELECT p.id AS project_id,
    p.uuid AS project_uuid,
    p.title,
    o.id AS organization_id,
    o.name AS organization_name,
    acm.month_start::date AS month_start_date,
    acm.total_accounts_receivable
   FROM approved_claims_monthly acm
     JOIN projects p ON p.uuid = acm.project_uuid
     JOIN user_schema.organizations o ON o.id = p.organization_id;;
-- then recreate its indexes and grants (see the production definition)

Keeps the MV's own column names, so everything above it is unchanged.

Materialized view project_services.reporting.mv_invitee_orgs: organization_name → name AS organization_name (project_services; parses with sqlglot, uses the new name)

DROP MATERIALIZED VIEW reporting.mv_invitee_orgs;
CREATE MATERIALIZED VIEW reporting.mv_invitee_orgs AS
 SELECT p.id AS project_id,
    p.uuid AS project_uuid,
    p.title AS project_title,
    p.organization_id AS inviter_org_id,
    o_owner.name AS inviter_org_name,
    ol.organization_id AS invitee_org_id,
    o_inv.name AS invitee_org_name
   FROM projects p
     JOIN user_schema.organizations o_owner ON o_owner.id = p.organization_id
     JOIN ( SELECT DISTINCT "organization-link".project_id,
            "organization-link".organization_id
           FROM user_schema."organization-link") ol ON ol.project_id = p.id
     JOIN user_schema.organizations o_inv ON o_inv.id = ol.organization_id
  WHERE ol.organization_id <> p.organization_id;;
-- then recreate its indexes and grants (see the production definition)

Keeps the MV's own column names, so everything above it is unchanged.

Dataset "DATASET_SYD List of Subcontractors" (id 197): SQL with organization_name → name AS organization_name (Superset; parses with sqlglot, uses the new name)

SELECT

        p.id                      AS project_id,

        p.uuid                    AS project_uuid,

        p.title                   AS project_title,

        p.organization_id         AS inviter_org_id,

        o_owner.name AS inviter_org_name,

        ol.organization_id        AS invitee_org_id,

        o_inv.name   AS invitee_org_name

    FROM public.projects p

    JOIN user_schema.organizations o_owner

      ON o_owner.id = p.organization_id

    JOIN (

        SELECT DISTINCT

            l.project_id,

            l.organization_id

        FROM user_schema."organization-link" l

        WHERE l.deleted_at IS NULL          -- link removed from the project

          AND l.is_archive IS NOT TRUE      -- contractor archived (NULL counts as active)

    ) ol

      ON ol.project_id = p.id

    JOIN user_schema.organizations o_inv

      ON o_inv.id = ol.organization_id

    WHERE ol.organization_id <> p.organization_id   -- exclude the project owner

Reads the foreign table itself.

Dataset "DATASET_Vendor Ratings" (id 164): SQL with organization_name → name AS organization_name (Superset; parses with sqlglot, uses the new name)

SELECT

    pvrr.*,

    pvrq.question,

    p.uuid AS project_uuid,

    p.title AS project_title,

    o.name AS organization_name,



    CONCAT_WS(' ', u_created.first_name, u_created.last_name) AS created_by_name,

    CONCAT_WS(' ', u_updated.first_name, u_updated.last_name) AS updated_by_name,



    pvrr.created_at AT TIME ZONE 'Australia/Sydney' AS created_at_sydney,

    pvrr.updated_at AT TIME ZONE 'Australia/Sydney' AS updated_at_sydney,



    c.comment,

    c.created_at AT TIME ZONE 'Australia/Sydney' AS comment_created_at_sydney,

    CONCAT_WS(' ', u_comment.first_name, u_comment.last_name) AS comment_created_by_name



FROM procurement_vendor_rating_records pvrr

LEFT JOIN procurement_vendor_rating_questions pvrq

    ON pvrr.question_id = pvrq.id

LEFT JOIN projects p

    ON pvrr.project_id = p.id

LEFT JOIN user_schema.organizations o

    ON pvrr.organization_uuid = o.uuid

LEFT JOIN user_schema.users u_created

    ON pvrr.created_by = u_created.id

LEFT JOIN user_schema.users u_updated

    ON pvrr.updated_by = u_updated.id

LEFT JOIN comment_schema.comments c

    ON pvrr.id = c.module_id

   AND c.module = 'VENDOR_RATING'

LEFT JOIN user_schema.users u_comment

    ON c.created_by = u_comment.id;

Reads the foreign table itself.

Re-import site_management_services.user_schema.organizations (site_management_services; DDL, check by eye)

DROP FOREIGN TABLE user_schema.organizations;  -- add CASCADE only together with the view/MV drafts below
IMPORT FOREIGN SCHEMA public LIMIT TO (organizations)
  FROM SERVER user_srv INTO user_schema;

Brings in the new column name; the readers below must then use it.

Materialized view site_management_services.public.mv_defect_by_type: organization_name → name AS organization_name (site_management_services; parses with sqlglot, uses the new name)

DROP MATERIALIZED VIEW public.mv_defect_by_type;
CREATE MATERIALIZED VIEW public.mv_defect_by_type AS
 WITH filtered_defects AS (
         SELECT d.id,
            d.project_id,
            d.priority,
            d.trade,
            d.status,
            d.assign_to_id,
            d.due_date,
            d.created_by,
            d.created_at,
            d.updated_at,
            d.last_fixed_at,
            d.last_fixed_by,
            d.type_id,
            d.area_name,
            d.building_id
           FROM defect_schema.defects d
          WHERE d.is_archive IS NOT TRUE
        ), needed_user_ids AS (
         SELECT filtered_defects.assign_to_id AS id
           FROM filtered_defects
          WHERE filtered_defects.assign_to_id IS NOT NULL
        UNION
         SELECT filtered_defects.created_by AS id
           FROM filtered_defects
          WHERE filtered_defects.created_by IS NOT NULL
        UNION
         SELECT filtered_defects.last_fixed_by AS id
           FROM filtered_defects
          WHERE filtered_defects.last_fixed_by IS NOT NULL
        ), user_dim AS (
         SELECT u.id,
            concat_ws(' '::text, u.first_name, u.last_name) AS full_name,
            o.name AS organization_name
           FROM user_schema.users u
             LEFT JOIN user_schema.organizations o ON o.id = u.organization_id
             JOIN needed_user_ids n ON n.id = u.id
        ), project_dim AS (
         SELECT p_1.id,
            p_1.uuid,
            p_1.title
           FROM project_schema.projects p_1
        ), defect_type_dim AS (
         SELECT dt_1.id,
            dt_1.name
           FROM defect_schema.defect_types dt_1
        )
 SELECT fd.id,
    fd.project_id,
        CASE
            WHEN fd.priority IS NULL THEN NULL::text
            ELSE upper(TRIM(BOTH FROM fd.priority))
        END AS priority,
    fd.trade,
    fd.status,
    fd.assign_to_id,
    (fd.due_date AT TIME ZONE 'Australia/Sydney'::text) AS due_date,
    fd.created_by,
    (fd.created_at AT TIME ZONE 'Australia/Sydney'::text) AS created_at,
    (fd.updated_at AT TIME ZONE 'Australia/Sydney'::text) AS updated_at,
    (fd.last_fixed_at AT TIME ZONE 'Australia/Sydney'::text) AS last_fixed_at,
    fd.last_fixed_by,
    fd.type_id,
    fd.area_name,
    fd.building_id,
    b.name AS building_name,
    p.uuid AS project_uuid,
    p.title AS project_title,
    ua.full_name AS assign_to_name,
    ua.organization_name AS assign_to_organization_name,
    uc.full_name AS created_by_name,
    uc.organization_name AS created_by_organization_name,
    ulf.full_name AS last_fixed_by_name,
    ulf.organization_name AS last_fixed_by_organization_name,
    dt.name AS defect_type_name
   FROM filtered_defects fd
     LEFT JOIN project_dim p ON p.id = fd.project_id
     LEFT JOIN defect_type_dim dt ON dt.id = fd.type_id
     LEFT JOIN defect_schema.buildings b ON b.id = fd.building_id
     LEFT JOIN user_dim ua ON ua.id = fd.assign_to_id
     LEFT JOIN user_dim uc ON uc.id = fd.created_by
     LEFT JOIN user_dim ulf ON ulf.id = fd.last_fixed_by;;
-- then recreate its indexes and grants (see the production definition)

Keeps the MV's own column names, so everything above it is unchanged.

Materialized view site_management_services.public.mv_blacklist_warnings: organization_name → name AS organization_name (site_management_services; parses with sqlglot, uses the new name)

DROP MATERIALIZED VIEW public.mv_blacklist_warnings;
CREATE MATERIALIZED VIEW public.mv_blacklist_warnings AS
 SELECT bw.id AS history_id,
    bw.uuid AS history_uuid,
    bw.organization_id AS history_organization_id,
    bw.organization_uuid AS history_organization_uuid,
    ow.name AS history_organization_name,
    bw.personnel_id AS history_personnel_id,
    bw.personnel_uuid AS history_personnel_uuid,
    TRIM(BOTH FROM concat(hp.first_name, ' ', hp.last_name)) AS history_personnel_name,
    opw.name AS history_personnel_organization_name,
    COALESCE(bw.project_id, bb.project_id) AS project_id,
    COALESCE(bw.project_uuid, bb.project_uuid) AS project_uuid,
    pw.title AS history_project_title,
    bw.breach_category_id AS history_breach_category_id,
    bw.breach_category_uuid AS history_breach_category_uuid,
    bcw.name AS history_breach_category_name,
    bw.description AS history_description,
    (bw.date_time AT TIME ZONE 'Australia/Sydney'::text) AS history_date_time,
    (bw.created_at AT TIME ZONE 'Australia/Sydney'::text) AS history_created_at,
    bw.created_by AS history_created_by,
    (bw.updated_at AT TIME ZONE 'Australia/Sydney'::text) AS history_updated_at,
    (bw.deleted_at AT TIME ZONE 'Australia/Sydney'::text) AS history_deleted_at,
    bw.status AS history_status,
    bb.id AS current_id,
    bb.uuid AS current_uuid,
    bb.organization_id AS current_organization_id,
    bb.organization_uuid AS current_organization_uuid,
    ob.name AS current_organization_name,
    bb.personnel_id AS current_personnel_id,
    bb.personnel_uuid AS current_personnel_uuid,
    TRIM(BOTH FROM concat(cp.first_name, ' ', cp.last_name)) AS current_personnel_name,
    opb.name AS current_personnel_organization_name,
    pb.title AS current_project_title,
    bb.breach_category_id AS current_breach_category_id,
    bb.breach_category_uuid AS current_breach_category_uuid,
    bcb.name AS current_breach_category_name,
    bb.description AS current_description,
    (bb.date_time AT TIME ZONE 'Australia/Sydney'::text) AS current_date_time,
    (bb.created_at AT TIME ZONE 'Australia/Sydney'::text) AS current_created_at,
    bb.created_by AS current_created_by,
    (bb.updated_at AT TIME ZONE 'Australia/Sydney'::text) AS current_updated_at,
    (bb.deleted_at AT TIME ZONE 'Australia/Sydney'::text) AS current_deleted_at,
    bb.status AS current_status,
    bb.is_warning AS current_is_warning
   FROM blackbook_warnings bw
     FULL JOIN blackbooks bb ON bw.uuid = bb.uuid
     LEFT JOIN breach_categories bcw ON bw.breach_category_id = bcw.id
     LEFT JOIN breach_categories bcb ON bb.breach_category_id = bcb.id
     LEFT JOIN user_schema.organizations ow ON bw.organization_id = ow.id
     LEFT JOIN user_schema.organizations ob ON bb.organization_id = ob.id
     LEFT JOIN project_schema.projects pw ON bw.project_id = pw.id
     LEFT JOIN project_schema.projects pb ON bb.project_id = pb.id
     LEFT JOIN personnels hp ON bw.personnel_id = hp.id
     LEFT JOIN user_schema.organizations opw ON hp.organisation_id = opw.id
     LEFT JOIN personnels cp ON bb.personnel_id = cp.id
     LEFT JOIN user_schema.organizations opb ON cp.organisation_id = opb.id
  WHERE bw.deleted_at IS NULL AND bb.deleted_at IS NULL;;
-- then recreate its indexes and grants (see the production definition)

Keeps the MV's own column names, so everything above it is unchanged.

Materialized view site_management_services.public.mv_obs_detail: organization_name → name AS organization_name (site_management_services; parses with sqlglot, uses the new name)

DROP MATERIALIZED VIEW public.mv_obs_detail;
CREATE MATERIALIZED VIEW public.mv_obs_detail AS
 WITH obs AS (
         SELECT observations.id,
            observations.uuid,
            observations.project_id,
            observations.title,
            observations.priority,
            observations.location,
            observations.type,
            observations.description,
            observations.status,
            observations.assign_to_id,
            observations.due_date,
            observations.created_by,
            observations.created_at,
            observations.updated_at,
            observations.organization_uuid,
            observations.organization_id,
            observations.building_id,
            observations.building_uuid,
            observations.area_name,
            observations.area_levels,
            observations.code,
            observations.meeting_inspection_item_uuid,
            observations.meeting_inspection_item_checklist_index,
            observations.conformance,
            observations.sub_type,
            observations.updated_by,
            observations.approve_signature,
            observations.approve_at,
            observations.approve_by,
            observations.corrective_action_required,
            observations.corrective_action_taken,
            observations.additional_evidence_of_corrective_action,
            observations.last_status_updated_at,
            observations.last_status_updated_by,
            observations.last_fixed_at,
            observations.last_fixed_by,
            observations.is_archive,
            observations.last_reminder_at
           FROM observations
          WHERE observations.is_archive = false
        ), needed_project_ids AS (
         SELECT DISTINCT obs.project_id
           FROM obs
          WHERE obs.project_id IS NOT NULL
        ), needed_org_ids AS (
         SELECT DISTINCT obs.organization_id
           FROM obs
          WHERE obs.organization_id IS NOT NULL
        ), needed_user_ids AS (
         SELECT DISTINCT obs.created_by AS user_id
           FROM obs
          WHERE obs.created_by IS NOT NULL
        UNION
         SELECT DISTINCT obs.assign_to_id
           FROM obs
          WHERE obs.assign_to_id IS NOT NULL
        ), projects_needed AS (
         SELECT p_1.id,
            p_1.uuid,
            p_1.title
           FROM project_schema.projects p_1
          WHERE (p_1.id IN ( SELECT needed_project_ids.project_id
                   FROM needed_project_ids))
        ), orgs_needed AS (
         SELECT org_1.id,
            org_1.name AS organization_name
           FROM user_schema.organizations org_1
          WHERE (org_1.id IN ( SELECT needed_org_ids.organization_id
                   FROM needed_org_ids))
        ), users_needed AS (
         SELECT u.id,
            u.first_name,
            u.last_name
           FROM user_schema.users u
          WHERE (u.id IN ( SELECT needed_user_ids.user_id
                   FROM needed_user_ids))
        )
 SELECT o.id,
    o.code,
    o.project_id,
    p.uuid AS project_uuid,
    p.title AS project_title,
    o.title AS observation_title,
    o.type,
    o.created_by,
    concat(uc.first_name, ' ', uc.last_name) AS created_by_name,
    o.assign_to_id,
    concat(ua.first_name, ' ', ua.last_name) AS assign_to_name,
    o.organization_id,
    org.organization_name,
    (o.due_date AT TIME ZONE 'Australia/Sydney'::text) AS due_date_sydney,
    (o.created_at AT TIME ZONE 'Australia/Sydney'::text) AS created_at_sydney,
    o.status
   FROM obs o
     LEFT JOIN projects_needed p ON p.id = o.project_id
     LEFT JOIN users_needed uc ON uc.id = o.created_by
     LEFT JOIN users_needed ua ON ua.id = o.assign_to_id
     LEFT JOIN orgs_needed org ON org.id = o.organization_id;;
-- then recreate its indexes and grants (see the production definition)

Keeps the MV's own column names, so everything above it is unchanged.

Materialized view site_management_services.public.mv_prestart: organization_name → name AS organization_name (site_management_services; parses with sqlglot, uses the new name)

DROP MATERIALIZED VIEW public.mv_prestart;
CREATE MATERIALIZED VIEW public.mv_prestart AS
 WITH target_meeting AS (
         SELECT mi.id AS meeting_id,
            mi.uuid AS meeting_uuid,
            mi.project_uuid,
            mi.code AS meeting_code,
            mt.name AS meeting_type_name,
            mi.title AS meeting_title,
            (mi.date_time AT TIME ZONE 'Australia/Sydney'::text)::date AS sydney_meeting_date,
            mi.attendees_list
           FROM meeting_inspections mi
             JOIN meeting_types mt ON mt.uuid = mi.type_uuid
          WHERE mi.source_type::text = 'MEETING'::text
        ), meeting_attendees AS (
         SELECT DISTINCT ON (tm.meeting_uuid, ((att.value ->> 'uuid'::text)::uuid)) tm.meeting_id,
            tm.meeting_uuid,
            tm.project_uuid,
            tm.meeting_code,
            tm.meeting_type_name,
            tm.meeting_title,
            tm.sydney_meeting_date,
            (att.value ->> 'uuid'::text)::uuid AS personnel_uuid,
            att.value ->> 'signature'::text AS attendee_signature
           FROM target_meeting tm
             CROSS JOIN LATERAL jsonb_array_elements(tm.attendees_list) att(value)
          WHERE (att.value ->> 'source'::text) = 'PERSONNEL'::text
          ORDER BY tm.meeting_uuid, ((att.value ->> 'uuid'::text)::uuid), (att.value ->> 'signature'::text) DESC
        ), signed_in AS (
         SELECT p_1.uuid AS personnel_uuid,
            a.project_id,
            a.project_uuid::uuid AS project_uuid,
            (a.datetime_in AT TIME ZONE 'Australia/Sydney'::text)::date AS sydney_signed_in_date
           FROM attendances a
             JOIN personnels p_1 ON p_1.id = a.personnel_id
          GROUP BY p_1.uuid, a.project_id, a.project_uuid, ((a.datetime_in AT TIME ZONE 'Australia/Sydney'::text)::date)
        ), organization_link AS (
         SELECT DISTINCT "organization-link".project_id,
            "organization-link".organization_id
           FROM user_schema."organization-link"
          WHERE "organization-link".is_archive IS FALSE
        )
 SELECT ma.sydney_meeting_date AS batch_sydney_date,
    proj.id AS project_id,
    proj.uuid AS project_uuid,
    proj.title AS project_title,
    o.name AS organization_name,
    p.id AS personnel_id,
    p.uuid AS personnel_uuid,
    p.personnel_id AS personnel_code,
    p.first_name,
    p.last_name,
    ma.meeting_type_name,
    ma.meeting_title,
    ma.meeting_code,
    ma.meeting_uuid,
        CASE
            WHEN COALESCE(ma.attendee_signature, ''::text) <> ''::text THEN true
            ELSE false
        END AS has_prestart,
        CASE
            WHEN si.personnel_uuid IS NOT NULL THEN true
            ELSE false
        END AS has_turnstile,
        CASE
            WHEN COALESCE(ma.attendee_signature, ''::text) <> ''::text AND si.personnel_uuid IS NOT NULL THEN 'GREEN'::text
            ELSE 'RED'::text
        END AS status
   FROM meeting_attendees ma
     JOIN project_schema.projects proj ON proj.uuid = ma.project_uuid
     JOIN personnels p ON p.uuid = ma.personnel_uuid
     LEFT JOIN signed_in si ON si.project_uuid = ma.project_uuid AND si.sydney_signed_in_date = ma.sydney_meeting_date AND si.personnel_uuid = ma.personnel_uuid
     LEFT JOIN organization_link ol ON ol.project_id = proj.id AND ol.organization_id = p.organisation_id
     LEFT JOIN user_schema.organizations o ON o.id = ol.organization_id
  ORDER BY ma.sydney_meeting_date DESC, ma.meeting_code DESC;;
-- then recreate its indexes and grants (see the production definition)

Keeps the MV's own column names, so everything above it is unchanged.

Dataset "incidents" (id 29): SQL with organization_name → name AS organization_name (Superset; parses with sqlglot, uses the new name)

SELECT

    i.id,

    i.uuid,

    i.organisation_uuid,

    i.project_uuid,

    i.incident_id,

    ic.name AS category_name,

    i.date_time,



    pu.personnel_uuid,



    o.name AS organization_name,



    i.category_uuid,

    i.sub_category_uuid,

    i.incident_contributor,

    i.incident_or_observe,

    i.additional_personnel,

    i.additional_equipment,

    i.additional_sds,

    i.additional_swms,

    i.images_uuid,

    i.status,

    CASE i.status

        WHEN 'PENDING'  THEN 'Draft'

        WHEN 'OPEN'     THEN 'Open'

        WHEN 'REVIEW'   THEN 'Under Investigation'

        WHEN 'APPROVED' THEN 'Approved & Closed'

        WHEN 'DECLINED' THEN 'Declined'

        ELSE i.status

    END AS status_display,

    i.created_by,

    i.created_at,

    i.updated_at,

    i.approved_at,

    i.approved_by,

    i.personnel_uuids,

    i.building_uuid,

    i.area_name,

    i.area_levels,



    p.id    AS project_id,

    p.title AS project_title,



    i.description

FROM incidents i

LEFT JOIN "incident-category" ic

    ON i.category_uuid = ic.uuid

LEFT JOIN project_schema.projects p

    ON p.uuid = i.project_uuid

LEFT JOIN LATERAL (

    SELECT jsonb_array_elements_text(

        COALESCE(i.personnel_uuids::jsonb, '[]'::jsonb)

    ) AS personnel_uuid

) pu ON TRUE

LEFT JOIN personnels per

    ON per.uuid = pu.personnel_uuid::uuid

LEFT JOIN user_schema.organizations o

    ON o.id = per.organisation_id;

Reads the foreign table itself.

… 19 more in the JSON output.

  • Not drafted: Dataset "DATASET_Survey Responses" (id 194): no reference could be tied to the table with certainty; check it by hand.
  • Not drafted: Dataset "DATASET_Observations Type Rank" (id 134): no reference could be tied to the table with certainty; check it by hand.