CREATE TABLE IF NOT EXISTS WebsiteRegistrationUserCache (
  WebsiteID INT NOT NULL,
  UserExternalID VARCHAR(191) NOT NULL,
  RegisteredAtUtc DATETIME(6) NOT NULL,
  RegisteredAtLocal DATETIME(6) NOT NULL,
  LocalDate DATE NOT NULL,
  CreatedAtUtc DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
  PRIMARY KEY (WebsiteID, UserExternalID),
  KEY idx_registration_cache_local (WebsiteID, RegisteredAtLocal),
  KEY idx_registration_cache_date (WebsiteID, LocalDate)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS WebsiteRegistrationSyncState (
  WebsiteID INT NOT NULL PRIMARY KEY,
  NewestUserExternalID VARCHAR(191) NULL,
  IsInitialized TINYINT(1) NOT NULL DEFAULT 0,
  CoverageStartLocal DATETIME(6) NULL,
  LastSyncAtUtc DATETIME(6) NULL,
  LastPagesRead INT NOT NULL DEFAULT 0,
  LastRowsRead INT NOT NULL DEFAULT 0,
  LastInserted INT NOT NULL DEFAULT 0,
  LastError VARCHAR(1000) NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
