Files
fitme3070.pt/database/migration_20260925_created_at.sql
andreandClaude Sonnet 5 32a5c24ba2 feat(db): created_at nas 7 tabelas que não tinham (auditoria 3.1.5)
fitme3070_info, galleries, horario, modalidades, system_settings,
website_offer e work_hours passam a ter created_at (DEFAULT
CURRENT_TIMESTAMP, linhas existentes ficam com a data da migração).
Sem created_by de propósito: são o CRUD de um só admin e a audit_log
(ligada 2026-09-25) já regista quem criou/mudou cada linha.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-25 12:44:07 +01:00

26 lines
1.9 KiB
SQL

-- ─── created_at nas tabelas que ainda não têm ────────────────────────────────
-- Auditoria 2026-09-24, ponto 3.1.5: fitme3070_info, galleries, horario,
-- modalidades, system_settings, website_offer e work_hours não registam
-- quando uma linha foi criada. Sem isso, uma fila de definições antigas ou
-- uma modalidade que já lá estava no dia 1 é indistinguível de uma criada
-- ontem.
--
-- Sem created_by de propósito: estas sete são o CRUD de um só admin (a
-- audit_log, ligada em 2026-09-25, já regista quem criou/mudou cada linha —
-- ver config/functions_audit.php). Uma coluna created_by aqui seria uma
-- segunda fonte da mesma resposta, sem valor a mais.
--
-- DEFAULT CURRENT_TIMESTAMP em vez de NULL: as linhas já existentes ficam com
-- a data da migração (a única data honesta disponível), e nenhum INSERT
-- existente que não mencione created_at parte.
--
-- Safe to re-run (IF NOT EXISTS é extensão do MariaDB).
ALTER TABLE `fitme3070_info` ADD COLUMN IF NOT EXISTS `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `id`;
ALTER TABLE `galleries` ADD COLUMN IF NOT EXISTS `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `name`;
ALTER TABLE `horario` ADD COLUMN IF NOT EXISTS `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `local`;
ALTER TABLE `modalidades` ADD COLUMN IF NOT EXISTS `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `gym_id`;
ALTER TABLE `system_settings` ADD COLUMN IF NOT EXISTS `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `setting_value`;
ALTER TABLE `website_offer` ADD COLUMN IF NOT EXISTS `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `gym_id`;
ALTER TABLE `work_hours` ADD COLUMN IF NOT EXISTS `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `gym_id`;