-- mlsgrid_media_local.sql
-- Tracks local download/resize/upload state for MLSGrid media files.
-- MariaDB 10.6+

CREATE TABLE IF NOT EXISTS `MediaLocal` (
  `MediaKey` VARCHAR(255) NOT NULL,
  `ListingId` VARCHAR(255) NULL,
  `BucketDir` TINYINT UNSIGNED NULL,
  `OriginalPath` VARCHAR(1024) NULL,
  `HiResPath` VARCHAR(1024) NULL,
  `MedResPath` VARCHAR(1024) NULL,
  `LowResPath` VARCHAR(1024) NULL,
  `DownloadedAt` DATETIME NULL,
  `ResizedAt` DATETIME NULL,
  `UploadedAt` DATETIME NULL,
  `LastError` TEXT NULL,
  PRIMARY KEY (`MediaKey`),
  KEY `idx_listingid` (`ListingId`),
  KEY `idx_downloaded` (`DownloadedAt`),
  KEY `idx_resized` (`ResizedAt`),
  KEY `idx_uploaded` (`UploadedAt`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
