-- Migration 7: Versionamento de catalogo offline
-- Source: backend/db/dump/19052026_nextbar.sql

-- -------------------------------------------------------- 7. Versionamento de catalogo offline
--
-- Estrutura para tabela `versoes_catalogo`
--

CREATE TABLE `versoes_catalogo` (
  id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  tenant_id INT NOT NULL,
  event_id INT,
  version VARCHAR(200) NOT NULL,
  published_at TIMESTAMP,
  published_by INT(11),
  checksum VARCHAR(200),
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  status TINYINT(1) NOT NULL DEFAULT 1,
  trash TINYINT(1) NOT NULL DEFAULT 0,
  FOREIGN KEY (tenant_id) REFERENCES tenants(id),
  FOREIGN KEY (event_id) REFERENCES eventos(id),
  FOREIGN KEY (published_by) REFERENCES usuarios(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------
--
-- Estrutura para tabela `itens_versao_catalogo`
--

CREATE TABLE `itens_versao_catalogo` (
  id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  catalog_version INT NOT NULL,
  sector_id INT NOT NULL,
  product_tenant_id INT NOT NULL,
  product_concept_id INT NOT NULL,
  product_variant_id INT NOT NULL,
  similarity_cluster_id INT NULL,
  snapshot_name VARCHAR(200),
  price_snapshots DECIMAL(10,2),
  inventory_control_snapshot JSON NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  status TINYINT(1) NOT NULL DEFAULT 1,
  trash TINYINT(1) NOT NULL DEFAULT 0,
  FOREIGN KEY (catalog_version) REFERENCES versoes_catalogo(id),
  FOREIGN KEY (sector_id) REFERENCES setores(id),
  FOREIGN KEY (product_tenant_id) REFERENCES produtos_tenant(id),
  FOREIGN KEY (product_concept_id) REFERENCES conceitos_produtos(id),
  FOREIGN KEY (product_variant_id) REFERENCES variantes_produtos(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
