Spring Batch 5.0 migration Guide - initial Database schema updates
Spring Batch가 5.0으로 버전 업하면서 여러 사항들이 변경 됐다. 자세한 내용은 아래 첨부한 링크에서 확인!
그 중 Spring Batch의 메타 데이터 저장 테이블의 Schema가 변경되어 Migration하거나, 초기 시작일 경우 생성하는 방법에 대해 기술하고자 한다.
Spring Batch가 제공하는 배치 메타 데이터 저장 테이블에 대한 정보는 아래 첨부한 링크에서 확인!
1. Schema Create 🚀
Spring Batch 작업을 처음 할 경우 Database에서 Schema에 대한 Create 쿼리는 아래와 같다.
(Oracle 기준임. 다른 DBMS의 경우 아래 링크 참조)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | -- Autogenerated: do not edit this file CREATE TABLE BATCH_JOB_INSTANCE ( JOB_INSTANCE_ID NUMBER(19,0) NOT NULL PRIMARY KEY , VERSION NUMBER(19,0) , JOB_NAME VARCHAR2(100 char) NOT NULL, JOB_KEY VARCHAR2(32 char) NOT NULL, constraint JOB_INST_UN unique (JOB_NAME, JOB_KEY) ) SEGMENT CREATION IMMEDIATE; CREATE TABLE BATCH_JOB_EXECUTION ( JOB_EXECUTION_ID NUMBER(19,0) NOT NULL PRIMARY KEY , VERSION NUMBER(19,0) , JOB_INSTANCE_ID NUMBER(19,0) NOT NULL, CREATE_TIME TIMESTAMP(9) NOT NULL, START_TIME TIMESTAMP(9) DEFAULT NULL , END_TIME TIMESTAMP(9) DEFAULT NULL , STATUS VARCHAR2(10 char) , EXIT_CODE VARCHAR2(2500 char) , EXIT_MESSAGE VARCHAR2(2500 char) , LAST_UPDATED TIMESTAMP(9), constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ) SEGMENT CREATION IMMEDIATE; CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( JOB_EXECUTION_ID NUMBER(19,0) NOT NULL , PARAMETER_NAME VARCHAR(100 char) NOT NULL , PARAMETER_TYPE VARCHAR(100 char) NOT NULL , PARAMETER_VALUE VARCHAR(2500 char) , IDENTIFYING CHAR(1) NOT NULL , constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID) references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ) SEGMENT CREATION IMMEDIATE; CREATE TABLE BATCH_STEP_EXECUTION ( STEP_EXECUTION_ID NUMBER(19,0) NOT NULL PRIMARY KEY , VERSION NUMBER(19,0) NOT NULL, STEP_NAME VARCHAR2(100 char) NOT NULL, JOB_EXECUTION_ID NUMBER(19,0) NOT NULL, CREATE_TIME TIMESTAMP(9) NOT NULL, START_TIME TIMESTAMP(9) DEFAULT NULL , END_TIME TIMESTAMP(9) DEFAULT NULL , STATUS VARCHAR2(10 char) , COMMIT_COUNT NUMBER(19,0) , READ_COUNT NUMBER(19,0) , FILTER_COUNT NUMBER(19,0) , WRITE_COUNT NUMBER(19,0) , READ_SKIP_COUNT NUMBER(19,0) , WRITE_SKIP_COUNT NUMBER(19,0) , PROCESS_SKIP_COUNT NUMBER(19,0) , ROLLBACK_COUNT NUMBER(19,0) , EXIT_CODE VARCHAR2(2500 char) , EXIT_MESSAGE VARCHAR2(2500 char) , LAST_UPDATED TIMESTAMP(9), constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ) SEGMENT CREATION IMMEDIATE; CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( STEP_EXECUTION_ID NUMBER(19,0) NOT NULL PRIMARY KEY, SHORT_CONTEXT VARCHAR2(2500 char) NOT NULL, SERIALIZED_CONTEXT CLOB , constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID) references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) ) SEGMENT CREATION IMMEDIATE; CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( JOB_EXECUTION_ID NUMBER(19,0) NOT NULL PRIMARY KEY, SHORT_CONTEXT VARCHAR2(2500 char) NOT NULL, SERIALIZED_CONTEXT CLOB , constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID) references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ) SEGMENT CREATION IMMEDIATE; CREATE SEQUENCE BATCH_STEP_EXECUTION_SEQ START WITH 0 MINVALUE 0 MAXVALUE 9223372036854775807 ORDER NOCYCLE; CREATE SEQUENCE BATCH_JOB_EXECUTION_SEQ START WITH 0 MINVALUE 0 MAXVALUE 9223372036854775807 ORDER NOCYCLE; CREATE SEQUENCE BATCH_JOB_SEQ START WITH 0 MINVALUE 0 MAXVALUE 9223372036854775807 ORDER NOCYCLE; | cs |
1. Schema Migrate 🚀
기존에 Database의 Schema Table들이 있을 경우 아래 쿼리를 실행하여 변경해주면 된다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | ALTER SEQUENCE BATCH_STEP_EXECUTION_SEQ ORDER; ALTER SEQUENCE BATCH_JOB_EXECUTION_SEQ ORDER; ALTER SEQUENCE BATCH_JOB_SEQ ORDER; ALTER TABLE BATCH_STEP_EXECUTION ADD CREATE_TIME TIMESTAMP DEFAULT TO_TIMESTAMP('1970-01-01 00:00:00', 'yyyy-MM-dd HH24:mi:ss') NOT NULL; ALTER TABLE BATCH_STEP_EXECUTION MODIFY START_TIME TIMESTAMP NULL; ALTER TABLE BATCH_JOB_EXECUTION_PARAMS DROP COLUMN DATE_VAL; ALTER TABLE BATCH_JOB_EXECUTION_PARAMS DROP COLUMN LONG_VAL; ALTER TABLE BATCH_JOB_EXECUTION_PARAMS DROP COLUMN DOUBLE_VAL; ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY TYPE_CD VARCHAR(100); ALTER TABLE BATCH_JOB_EXECUTION_PARAMS RENAME COLUMN TYPE_CD TO PARAMETER_TYPE; ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY KEY_NAME VARCHAR(100); ALTER TABLE BATCH_JOB_EXECUTION_PARAMS RENAME COLUMN KEY_NAME TO PARAMETER_NAME; ALTER TABLE BATCH_JOB_EXECUTION_PARAMS MODIFY STRING_VAL VARCHAR(2500); ALTER TABLE BATCH_JOB_EXECUTION_PARAMS RENAME COLUMN STRING_VAL TO PARAMETER_VALUE; ALTER TABLE BATCH_JOB_EXECUTION MODIFY CREATE_TIME TIMESTAMP(9); ALTER TABLE BATCH_JOB_EXECUTION MODIFY START_TIME TIMESTAMP(9); ALTER TABLE BATCH_JOB_EXECUTION MODIFY END_TIME TIMESTAMP(9); ALTER TABLE BATCH_JOB_EXECUTION MODIFY LAST_UPDATED TIMESTAMP(9); ALTER TABLE BATCH_STEP_EXECUTION MODIFY CREATE_TIME TIMESTAMP(9); ALTER TABLE BATCH_STEP_EXECUTION MODIFY START_TIME TIMESTAMP(9); ALTER TABLE BATCH_STEP_EXECUTION MODIFY END_TIME TIMESTAMP(9); ALTER TABLE BATCH_STEP_EXECUTION MODIFY LAST_UPDATED TIMESTAMP(9); | cs |
3. 관련 Link 🚀
Spring Batch 5.0 Migration Guide
반응형