<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `membership_number_chain` (
            `id`                  BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `membership_number`   VARCHAR(20) NOT NULL,
            `holder_type`         VARCHAR(50) NOT NULL,
            `holder_entity_type`  VARCHAR(100) NOT NULL,
            `holder_entity_id`    BIGINT UNSIGNED NOT NULL,
            `previous_holder_id`  BIGINT UNSIGNED NULL,
            `held_from`           DATETIME NOT NULL,
            `held_until`          DATETIME NULL DEFAULT NULL,
            `created_at`          TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            INDEX `idx_number_chain_number` (`membership_number`),
            INDEX `idx_number_chain_holder` (`holder_entity_type`, `holder_entity_id`),
            CONSTRAINT `fk_number_chain_prev` FOREIGN KEY (`previous_holder_id`) REFERENCES `membership_number_chain`(`id`) ON DELETE SET NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `membership_number_chain`",
];