CREATE TABLE IF NOT EXISTS sh_csv_item_definition (
    code VARCHAR(10) NOT NULL,
    item_seq int NOT NULL,
    item_title VARCHAR(50) NOT NULL,
    item_name VARCHAR(20),
    is_duplicate_check_key BOOLEAN NOT NULL DEFAULT FALSE,
    data_type VARCHAR(16) NOT NULL,
    precision INT,
    scale INT,
    nullable BOOLEAN NOT NULL DEFAULT TRUE,
    enable_format_check BOOLEAN NOT NULL DEFAULT FALSE,
    format_regex VARCHAR(100),
    enable_exist_check BOOLEAN NOT NULL DEFAULT FALSE,
    allowed_values TEXT[],
    master_sybt VARCHAR(40),
    enable_relation_check BOOLEAN NOT NULL DEFAULT FALSE,
    json_ignore BOOLEAN NOT NULL DEFAULT FALSE,
    cmnuser VARCHAR(10),
    dmndate TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT uk_process_title 
        UNIQUE (code, item_title),

    CONSTRAINT uk_process_seq 
        UNIQUE (code, item_seq)
);

COMMENT ON COLUMN sh_csv_item_definition.code IS '処理コード';
COMMENT ON COLUMN sh_csv_item_definition.item_seq IS '項目順';
COMMENT ON COLUMN sh_csv_item_definition.item_title IS '項目タイトル';
COMMENT ON COLUMN sh_csv_item_definition.item_name IS '項目名称';
COMMENT ON COLUMN sh_csv_item_definition.is_duplicate_check_key IS '重複チェックキー';
COMMENT ON COLUMN sh_csv_item_definition.data_type IS 'データ型';
COMMENT ON COLUMN sh_csv_item_definition.precision IS '数値精度';
COMMENT ON COLUMN sh_csv_item_definition.scale IS '小数桁数';
COMMENT ON COLUMN sh_csv_item_definition.nullable IS 'NULL 許容フラグ';
COMMENT ON COLUMN sh_csv_item_definition.enable_format_check IS '書式チェック有効フラグ';
COMMENT ON COLUMN sh_csv_item_definition.format_regex IS '書式正規表現';
COMMENT ON COLUMN sh_csv_item_definition.enable_exist_check IS '存在チェック有効フラグ';
COMMENT ON COLUMN sh_csv_item_definition.allowed_values IS '許可値';
COMMENT ON COLUMN sh_csv_item_definition.master_sybt IS 'マスタ種別';
COMMENT ON COLUMN sh_csv_item_definition.enable_relation_check IS '相関チェック有効フラグ';
COMMENT ON COLUMN sh_csv_item_definition.json_ignore IS 'JSON_IGNOREフラグ';

