-- Baltique OS Core 0.38.0 — Polygon Editor / Lab OCR Repair / Navigation IA

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,
  original_name VARCHAR(255) NOT NULL,
  stored_name VARCHAR(255) NOT NULL,
  storage_path TEXT NOT NULL,
  render_image_path TEXT NULL,
  mime_type VARCHAR(120) NULL,
  size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
  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_floorplan_bg_floor (floor_id, status),
  KEY idx_floorplan_bg_site (site_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Existing tables are repaired conditionally by upgrade_0_38_0.php.
-- hospital_sites gets visible_on_board / is_planned.
-- hospital_floors gets background_id / viewbox dimensions.
-- hospital_floorplan_polygons gets clinical_function / notes.
-- operative_lab_ocr_* tables are recreated/repaired if missing.
