-- 07: FK ocr_document_creation_log → user
SET NAMES utf8mb4;
SET @db := DATABASE();

SET @fk := (
  SELECT COUNT(*) FROM information_schema.TABLE_CONSTRAINTS
  WHERE CONSTRAINT_SCHEMA = @db AND TABLE_NAME = 'ocr_document_creation_log'
    AND CONSTRAINT_NAME = 'FK_1D141786A76ED395' AND CONSTRAINT_TYPE = 'FOREIGN KEY'
);
SET @sql := IF(@fk = 0,
  'ALTER TABLE `ocr_document_creation_log` ADD CONSTRAINT `FK_1D141786A76ED395` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)',
  'SELECT ''skip FK_1D141786A76ED395'' AS note');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
