我正在尝试将Liquibase用于已有多个SQL changelog文件的项目(之前已手动维护)。使用stackoverflow上某处的建议我添加了一个
<includeAll path="db/initial"/>
指向我的初始更改日志文件的指令,但是它失败并且没有非常有用的
您的SQL语法错误
消息。玩弄我发现问题在于文件中有多个sql语句。只要我提供的文件只有一个语句就可以了。
那么如何告诉Liquibase从sql文件执行多个语句?
答案 0 :(得分:10)
进一步搜索以找出问题不是Liquibase,而是MySql驱动程序,默认情况下拒绝执行多个语句。
关键是将allowMultiQueries = true添加到我的连接字符串:
url: jdbc:mysql://localhost/test_project?allowMultiQueries=true
答案 1 :(得分:1)
我希望您使用sql_file重构来导入SQL文件。它支持“splitStatements”属性,可以解决您的问题,而无需更改JDBC设置。
include语句通常用于导入liquibase更改日志....您是否已将文件调整为formatted SQL changelogs?这是值得尝试的,我已经包含了一个示例文件:
--liquibase formatted sql
--changeset mark:1
CREATE TABLE BONUS (ENAME VARCHAR(10) NOT NULL, JOB VARCHAR(9) NOT NULL, SAL DECIMAL(7, 2), COMM DECIMAL(7, 2));
ALTER TABLE BONUS ADD CONSTRAINT BONUS_PK PRIMARY KEY (ENAME, JOB);
--rollback DROP TABLE BONUS;
--changeset mark:2
CREATE TABLE DEPARTMENT (DEPTNO INT NOT NULL, NAME VARCHAR(14), LOCATION VARCHAR(13), CONSTRAINT DEPT_PK PRIMARY KEY (DEPTNO));
--rollback DROP TABLE DEPARTMENT;
--changeset mark:3
CREATE TABLE EMPLOYEE (EMPNO INT NOT NULL, NAME VARCHAR(10), JOB VARCHAR(9), BOSS INT, HIREDATE VARCHAR(12), SALARY DECIMAL(7, 2), COMM DECIMAL(7, 2), DEPTNO INT, CONSTRAINT EMP_PK PRIMARY KEY (EMPNO));
ALTER TABLE PUBLIC.EMPLOYEE ADD CONSTRAINT BOSS_FK FOREIGN KEY (BOSS) REFERENCES PUBLIC.EMPLOYEE (EMPNO) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE PUBLIC.EMPLOYEE ADD CONSTRAINT DEPARTMENT_FK FOREIGN KEY (DEPTNO) REFERENCES PUBLIC.DEPARTMENT (DEPTNO) ON UPDATE RESTRICT ON DELETE RESTRICT;
--rollback DROP TABLE EMPLOYEE;
--changeset mark:4
CREATE TABLE PROJECT (PROJECTNO INT NOT NULL, DESCRIPTION VARCHAR(100), START_DATE VARCHAR(12), END_DATE VARCHAR(12), CONSTRAINT PROJECT_PK PRIMARY KEY (PROJECTNO));
--rollback DROP TABLE PROJECT;
--changeset mark:5
CREATE TABLE ROLE (ROLE_ID INT NOT NULL, DESCRIPTION VARCHAR(100), CONSTRAINT ROLE_PK PRIMARY KEY (ROLE_ID));
--rollback DROP TABLE ROLE;
--changeset mark:6
CREATE TABLE PROJECT_PARTICIPATION (PROJECTNO INT NOT NULL, EMPNO INT NOT NULL, START_DATE VARCHAR(12) NOT NULL, END_DATE VARCHAR(12), ROLE_ID INT);
ALTER TABLE PROJECT_PARTICIPATION ADD CONSTRAINT PARTICIPATION_PK PRIMARY KEY (PROJECTNO, EMPNO, START_DATE);
ALTER TABLE PUBLIC.PROJECT_PARTICIPATION ADD CONSTRAINT EMPLOYEE_FK FOREIGN KEY (EMPNO) REFERENCES PUBLIC.EMPLOYEE (EMPNO) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE PUBLIC.PROJECT_PARTICIPATION ADD CONSTRAINT PROJECT_FK FOREIGN KEY (PROJECTNO) REFERENCES PUBLIC.PROJECT (PROJECTNO) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE PUBLIC.PROJECT_PARTICIPATION ADD CONSTRAINT ROLE_FK FOREIGN KEY (ROLE_ID) REFERENCES PUBLIC.ROLE (ROLE_ID) ON UPDATE RESTRICT ON DELETE RESTRICT;
--rollback DROP TABLE PROJECT_PARTICIPATION;
--changeset mark:7
CREATE TABLE SALARYGRADE (GRADE INT NOT NULL, LOSAL INT NOT NULL, HISAL INT NOT NULL, CONSTRAINT SALGRADE_PK PRIMARY KEY (GRADE));
--rollback DROP TABLE SALARYGRADE;
注意: