-- +migrate Up
CREATE TABLE IF NOT EXISTS `checkout_permission` (
	`id` BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY COMMENT 'チェックアウト権限ID',
	`task_id`BIGINT UNSIGNED NOT NULL COMMENT 'タスクID',
	`user_id` BIGINT UNSIGNED COMMENT 'タイピストユーザーID',
	`user_group_id` BIGINT UNSIGNED COMMENT 'タイピストユーザーグループID',
	`deleted_at` TIMESTAMP COMMENT '削除時刻',
	`created_by` VARCHAR(255) COMMENT '作成者',
	`created_at` TIMESTAMP DEFAULT now() COMMENT '作成時刻',
	`updated_by` VARCHAR(255) COMMENT '更新者',
	`updated_at` TIMESTAMP DEFAULT now() COMMENT '更新時刻',
	CONSTRAINT CHK_OnlyOneValue CHECK (
	(
		`user_id` IS NULL
		AND `user_group_id` IS NOT NULL
	)
	OR (
		`user_id` IS NOT NULL
		AND `user_group_id` IS NULL
	)
)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;

-- +migrate Down
DROP TABLE `checkout_permission`;