-- Baltique OS Core 0.38.0 — Polygon Editor / OCR Safe Fix / Navigation Workspaces

CREATE TABLE IF NOT EXISTS hospital_floorplan_backgrounds (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  site_id BIGINT UNSIGNED NOT NULL,
  floor_id BIGINT UNSIGNED NOT NULL,
  label VARCHAR(190) NOT NULL,
  original_name VARCHAR(255) NULL,
  stored_name VARCHAR(255) NULL,
  storage_path TEXT NULL,
  mime_type VARCHAR(120) NULL,
  status VARCHAR(40) NOT NULL DEFAULT 'active',
  created_by_user_id BIGINT UNSIGNED NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL,
  PRIMARY KEY (id),
  KEY idx_floor_bg_floor (floor_id, status),
  KEY idx_floor_bg_site (site_id, status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- This migration also expects:
-- ALTER hospital_floorplan_polygons ADD visible, editor_note
-- ALTER hospital_sites ADD visible
-- ALTER hospital_rooms ADD clinical_function
-- OCR tables are repaired by upgrade_0_38_0.php and lab_ocr_engine.php self-healing.
