• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

Flyway 관련 강의를 듣던 중 질문드립니다.

21.02.07 18:52 작성 조회수 404

0

안녕하세요

Flyway 강의를 듣던중 안되는 부분이 있어서 질문 드립니다.

db/migration 폴더에 V1__init.sql 파일을 만들어서 테스트 도중 V1_init.sql 파일을 플라이웨이가 실행 시키지 않는것 같아 질문드립니다.

server.port=1125
spring.datasource.hikari.maximum-pool-size=4
# 외부 DB에 대한 schema.xml 사용 허용
spring.datasource.initialization-mode=always

# sql server info
spring.datasource.url=jdbc:mysql://localhost:3306/studydb?serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=gmltjr1177@


# 드라이버가 createClub을 지원하지 않아서 warning 뜨는 것을 방지
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

# jpa info
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.generate-ddl=false
spring.jpa.show-sql=true

# flyway info
spring.flyway.baseline-on-migrate=true
spring.flyway.baseline-version=0

application.properties

drop table if exists account;
drop table if exists hibernate_sequence;
create table account (id bigint not null, email varchar(255), password varchar(255), username varchar(255), primary key (id));
create table hibernate_sequence (next_val bigint);
insert into hibernate_sequence values ( 1 );

V1_init.sql

package com.example.springbootjapstudy.account;

import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;


@Data
@Entity
public class Account {
@Id @GeneratedValue
private Long id;

private String username;

private String password;

private String email;
}

Account.class

접속하려는 데이터베이스는 MYSQL 입니다.

schema.sql을 사용했을 때는 정상적으로 실행이되었습니다.

flyway를 이용해서 V1__init.sql에 있는 테이블을 생성하려하니 생성이 안되는것 같아 문의드립니다.

답변 1

답변을 작성해보세요.

0

flyway_schema_history 을 지우지 않아서 생긴 문제 같습니다.

mysql에 생성된 flyway_schema_history  테이블을 drop 시키고 재 실행시 migration파일을 정상 실행하네요.