-- tb_project
--INSERT INTO `tb_project` VALUES
--('2025-09-22','2025-09-22',1,'2025-09-22 14:28:51.507010','2025-09-22 14:28:51.507010','N','cuuva,admin','cuuva,admin','PRJ1758518911644','배터리 학습입니다.','AI 배터리 학습','cuuva,admin','cuuva,admin');


-- tb_role
INSERT IGNORE INTO `tb_role` VALUES
(1,'ROLE_USER'),
(2,'ROLE_MODERATOR'),
(3,'ROLE_ADMIN');

-- tb_user
INSERT IGNORE INTO tb_user (
    id,
    username,
    email,
    password
) VALUES
(
    5,
    'cuuva',
    'cuuva@naver.com',
    '$2a$10$UhWIoxGlxa7u9gks3m498u9tPGcGO2sh5PTeAD6319TJ9M67ZZqmO'
),
(
    6,
    'admin',
    'admin@naver.com',
    '$2a$10$zukuiEA7Ce1ygOeJxZilhOi29jQnsreIswyJQ3Z.lysmKFiQhTXeS'
),
(
    7,
    'user',
    'user@naver.com',
    '$2a$10$jkRSrScnLK.Qiy/AmapKmOVauP4tff.tIMnAzEd1mMoTvRCZXpU4u'
);

-- tb_user_project_map
INSERT IGNORE INTO `tb_user_project_map` VALUES
(1,1,6),
(2,1,5);

-- tb_user_project_permission
INSERT IGNORE INTO `tb_user_project_permission` VALUES
(2,'READ'),
(1,'READ'),
(2,'CREATE'),
(1,'CREATE'),
(2,'UPDATE'),
(1,'UPDATE'),
(2,'DELETE'),
(1,'DELETE');

-- tb_user_roles
INSERT IGNORE INTO `tb_user_roles` VALUES
(1,7),
(2,6),
(3,5);


-- 테이블 생성 (이미 존재하면 생성 안 함)
CREATE TABLE IF NOT EXISTS BATCH_JOB_INSTANCE (
                                                  JOB_INSTANCE_ID BIGINT NOT NULL PRIMARY KEY,
                                                  VERSION BIGINT,
                                                  JOB_NAME VARCHAR(100) NOT NULL,
                                                  JOB_KEY VARCHAR(32) NOT NULL,
                                                  CONSTRAINT JOB_INST_UN UNIQUE (JOB_NAME, JOB_KEY)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS BATCH_JOB_EXECUTION (
                                                   JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY,
                                                   VERSION BIGINT,
                                                   JOB_INSTANCE_ID BIGINT NOT NULL,
                                                   CREATE_TIME DATETIME(6) NOT NULL,
                                                   START_TIME DATETIME(6) DEFAULT NULL,
                                                   END_TIME DATETIME(6) DEFAULT NULL,
                                                   STATUS VARCHAR(10),
                                                   EXIT_CODE VARCHAR(2500),
                                                   EXIT_MESSAGE VARCHAR(2500),
                                                   LAST_UPDATED DATETIME(6),
                                                   CONSTRAINT JOB_INST_EXEC_FK FOREIGN KEY (JOB_INSTANCE_ID)
                                                       REFERENCES BATCH_JOB_INSTANCE(JOB_INSTANCE_ID)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS BATCH_JOB_EXECUTION_PARAMS (
                                                          JOB_EXECUTION_ID BIGINT NOT NULL,
                                                          PARAMETER_NAME VARCHAR(100) NOT NULL,
                                                          PARAMETER_TYPE VARCHAR(100) NOT NULL,
                                                          PARAMETER_VALUE VARCHAR(2500),
                                                          IDENTIFYING CHAR(1) NOT NULL,
                                                          CONSTRAINT JOB_EXEC_PARAMS_FK FOREIGN KEY (JOB_EXECUTION_ID)
                                                              REFERENCES BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS BATCH_STEP_EXECUTION (
                                                    STEP_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY,
                                                    VERSION BIGINT NOT NULL,
                                                    STEP_NAME VARCHAR(100) NOT NULL,
                                                    JOB_EXECUTION_ID BIGINT NOT NULL,
                                                    CREATE_TIME DATETIME(6) NOT NULL,
                                                    START_TIME DATETIME(6) DEFAULT NULL,
                                                    END_TIME DATETIME(6) DEFAULT NULL,
                                                    STATUS VARCHAR(10),
                                                    COMMIT_COUNT BIGINT,
                                                    READ_COUNT BIGINT,
                                                    FILTER_COUNT BIGINT,
                                                    WRITE_COUNT BIGINT,
                                                    READ_SKIP_COUNT BIGINT,
                                                    WRITE_SKIP_COUNT BIGINT,
                                                    PROCESS_SKIP_COUNT BIGINT,
                                                    ROLLBACK_COUNT BIGINT,
                                                    EXIT_CODE VARCHAR(2500),
                                                    EXIT_MESSAGE VARCHAR(2500),
                                                    LAST_UPDATED DATETIME(6),
                                                    CONSTRAINT JOB_EXEC_STEP_FK FOREIGN KEY (JOB_EXECUTION_ID)
                                                        REFERENCES BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS BATCH_STEP_EXECUTION_CONTEXT (
                                                            STEP_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY,
                                                            SHORT_CONTEXT VARCHAR(2500) NOT NULL,
                                                            SERIALIZED_CONTEXT TEXT,
                                                            CONSTRAINT STEP_EXEC_CTX_FK FOREIGN KEY (STEP_EXECUTION_ID)
                                                                REFERENCES BATCH_STEP_EXECUTION(STEP_EXECUTION_ID)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS BATCH_JOB_EXECUTION_CONTEXT (
                                                           JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY,
                                                           SHORT_CONTEXT VARCHAR(2500) NOT NULL,
                                                           SERIALIZED_CONTEXT TEXT,
                                                           CONSTRAINT JOB_EXEC_CTX_FK FOREIGN KEY (JOB_EXECUTION_ID)
                                                               REFERENCES BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)
) ENGINE=InnoDB;

