Flyway, configuration example and thoughts :(
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Wed, 28 Dec 2016 16:58:55 +0000 (17:58 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Wed, 28 Dec 2016 16:58:55 +0000 (17:58 +0100)
SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/datasource-configuration.xml
SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/flyway/V1__Initial_Setup.sql [new file with mode: 0644]
SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/flyway/flyway.conf [new file with mode: 0644]
SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/flyway/flyway.xml [new file with mode: 0644]

index 6b5500c..116a95b 100644 (file)
@@ -1,14 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>\r
 <beans xmlns="http://www.springframework.org/schema/beans"\r
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
-       xmlns:util="http://www.springframework.org/schema/util"\r
        xmlns:tx="http://www.springframework.org/schema/tx"\r
        xmlns:jee="http://www.springframework.org/schema/jee"\r
        xsi:schemaLocation="http://www.springframework.org/schema/beans\r
         http://www.springframework.org/schema/beans/spring-beans.xsd\r
-        http://www.springframework.org/schema/util\r
-        http://www.springframework.org/schema/util/spring-util.xsd\r
-        http://www.springframework.org/schema/tx \r
+        http://www.springframework.org/schema/tx\r
         http://www.springframework.org/schema/tx/spring-tx.xsd\r
         http://www.springframework.org/schema/jee\r
         http://www.springframework.org/schema/jee/spring-jee.xsd">\r
        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">\r
                <property name="entityManagerFactory" ref="entityManagerFactory" />\r
        </bean>\r
-       \r
+\r
+       <!-- Liquibase -->\r
        <import resource="liquibase/liquibase.xml" />\r
-       \r
+\r
+       <!-- Flyway\r
+       <import resource="flyway/flyway.xml" />\r
+    -->\r
+\r
+\r
 </beans>\r
diff --git a/SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/flyway/V1__Initial_Setup.sql b/SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/flyway/V1__Initial_Setup.sql
new file mode 100644 (file)
index 0000000..97d1948
--- /dev/null
@@ -0,0 +1,177 @@
+<!--
+   NO CONSIGO CREAR UN SCRIPT DDL QUE VALGA PARA H2 E INNODB 
+   
+   CON LIQUIBASE SÍ PUEDO PORQUE LIQUIBASE (con XML) SE ENCARGA ÉL
+   DE ADAPTARLO PARA QUE ENTRE EN H2
+
+   SUPONGO QUE FLYWAY PODRÍA USARSE SIN PROBLEMAS CUANDO TENGA LA
+   BASE DE DATOS DOCKERIZADA (EN LUGAR DE USAR H2 PARA LOS TESTS USAR DOCKER)
+
+   SI USO H2 PARA LOS TESTS LIQUIBASE PARECE MEJOR (usando el formato XML
+   de definición de changesets) PORQUE ADAPTA LOS STATEMENTS DE CREACIÓN A H2
+   Y MYSQL  :(
+
+-->
+
+CREATE TABLE AD (
+       ID  BIGINT AUTO_INCREMENT NOT NULL,
+       COMPANY_ID BIGINT,
+       COMPANY_CATEG_ID BIGINT,
+       AD_GPS BLOB,
+       AD_MOBILE_IMAGE VARCHAR(255),
+       CREATED_AT TIMESTAMP DEFAULT NOW() NOT NULL,
+       UPDATED_AT TIMESTAMP DEFAULT '1970-01-01 00:00:01' NOT NULL,
+       CONSTRAINT PK_AD PRIMARY KEY (ID)
+       );
+
+
+CREATE TABLE AD_AUDITED (
+       ID BIGINT NOT NULL,
+       REVISION BIGINT NOT NULL,
+       REVISION_TYPE TINYINT(3),
+       REVISION_END BIGINT,
+       REVISION_END_TIMESTAMP TIMESTAMP,
+       AD_MOBILE_IMAGE VARCHAR(255),
+       adMobileImage_MODIFIED BOOLEAN(1),
+       COMPANY_CATEG_ID BIGINT,
+       companyCategId_MODIFIED BOOLEAN(1),
+       COMPANY_ID BIGINT,
+       companyId_MODIFIED BOOLEAN(1),
+       CREATED_AT TIMESTAMP,
+       createdAt_MODIFIED BOOLEAN(1),
+       UPDATED_AT TIMESTAMP,
+       updatedAt_MODIFIED BOOLEAN(1),
+       adDescriptions_MODIFIED BOOLEAN(1));
+
+
+CREATE TABLE AD_DESCRIPTION (
+       ID BIGINT AUTO_INCREMENT NOT NULL,
+       LANGUAGE_ID BIGINT NOT NULL,
+       AD_ID BIGINT,
+       AD_NAME VARCHAR(255) NOT NULL,
+       AD_DESCRIPTION CLOB,
+       AD_MOBILE_TEXT VARCHAR(500) NOT NULL,
+       AD_LINK VARCHAR(3000) NOT NULL,
+       CONSTRAINT PK_AD_DESCRIPTION PRIMARY KEY (ID)
+       );
+
+
+
+CREATE TABLE AD_DESCRIPTION_AUDITED (
+       ID BIGINT NOT NULL,
+       REVISION BIGINT NOT NULL,
+       REVISION_TYPE TINYINT(3),
+       REVISION_END BIGINT,
+       REVISION_END_TIMESTAMP TIMESTAMP,
+       AD_DESCRIPTION VARCHAR(255),
+       AD_LINK VARCHAR(255),
+       AD_MOBILE_TEXT VARCHAR(255),
+       AD_NAME VARCHAR(255),
+       LANGUAGE_ID BIGINT,
+       AD_ID BIGINT
+       );
+
+
+
+CREATE TABLE CUSTOM_REVISION (
+       ID BIGINT AUTO_INCREMENT NOT NULL,
+       REVISION_DATE TIMESTAMP NOT NULL,
+       USERNAME VARCHAR(255),
+       CONSTRAINT PK_CUSTOM_REVISION PRIMARY KEY (ID)
+       );
+
+
+       
+       
+       
+       
+       -- OTRO
+       
+       
+       
+CREATE TABLE AD (
+  ID bigint(20) NOT NULL AUTO_INCREMENT,
+  COMPANY_ID bigint(20) DEFAULT NULL,
+  COMPANY_CATEG_ID bigint(20) DEFAULT NULL,
+  AD_GPS blob,
+  AD_MOBILE_IMAGE varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+  CREATED_AT timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+  UPDATED_AT timestamp NOT NULL DEFAULT '1970-01-01 00:00:01',
+  PRIMARY KEY (ID)
+);
+
+
+CREATE TABLE AD_DESCRIPTION (
+  ID bigint(20) NOT NULL AUTO_INCREMENT,
+  LANGUAGE_ID bigint(20) NOT NULL,
+  AD_ID bigint(20) DEFAULT NULL,
+  AD_NAME varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+  AD_DESCRIPTION longtext COLLATE utf8_unicode_ci,
+  AD_MOBILE_TEXT varchar(500) COLLATE utf8_unicode_ci NOT NULL,
+  AD_LINK varchar(3000) COLLATE utf8_unicode_ci NOT NULL,
+  PRIMARY KEY (ID),
+  KEY IND_01_AD_DESCRIPTION (AD_ID),
+  CONSTRAINT FK_01_AD_DESCRIPTION FOREIGN KEY (AD_ID) REFERENCES AD (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
+);
+
+
+CREATE TABLE CUSTOM_REVISION (
+  ID bigint(20) NOT NULL AUTO_INCREMENT,
+  REVISION_DATE timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+  USERNAME varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+  PRIMARY KEY (ID)
+);
+
+
+CREATE TABLE AD_AUDITED (
+  ID bigint(20) NOT NULL,
+  REVISION bigint(20) NOT NULL,
+  REVISION_TYPE tinyint(3) DEFAULT NULL,
+  REVISION_END bigint(20) DEFAULT NULL,
+  REVISION_END_TIMESTAMP datetime DEFAULT NULL,
+  AD_MOBILE_IMAGE varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+  adMobileImage_MODIFIED bit(1) DEFAULT NULL,
+  COMPANY_CATEG_ID bigint(20) DEFAULT NULL,
+  companyCategId_MODIFIED bit(1) DEFAULT NULL,
+  COMPANY_ID bigint(20) DEFAULT NULL,
+  companyId_MODIFIED bit(1) DEFAULT NULL,
+  CREATED_AT datetime DEFAULT NULL,
+  createdAt_MODIFIED bit(1) DEFAULT NULL,
+  UPDATED_AT datetime DEFAULT NULL,
+  updatedAt_MODIFIED bit(1) DEFAULT NULL,
+  adDescriptions_MODIFIED bit(1) DEFAULT NULL,
+  PRIMARY KEY (ID,REVISION),
+  KEY IND_01_AD_AUDITED (REVISION),
+  KEY IND_02_AD_AUDITED (REVISION_END),
+  CONSTRAINT FK_01_AD_AUDITED FOREIGN KEY (REVISION) REFERENCES CUSTOM_REVISION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
+  CONSTRAINT FK_02_AD_AUDITED FOREIGN KEY (REVISION_END) REFERENCES CUSTOM_REVISION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
+);
+
+--
+-- CREATE TABLE "MYBATIS_EXAMPLE"."AD_AUDITED" ("ID" BIGINT NOT NULL, "REVISION" BIGINT NOT NULL, "REVISION_TYPE" TINYINT(3), "REVISION_END" BIGINT, "REVISION_END_TIMESTAMP" TIMESTAMP, "AD_MOBILE_IMAGE" VARCHAR(255), "adMobileImage_MODIFIED" BOOLEAN(1), "COMPANY_CATEG_ID" BIGINT, "companyCategId_MODIFIED" BOOLEAN(1), "COMPANY_ID" BIGINT, "companyId_MODIFIED" BOOLEAN(1), "CREATED_AT" TIMESTAMP, "createdAt_MODIFIED" BOOLEAN(1), "UPDATED_AT" TIMESTAMP, "updatedAt_MODIFIED" BOOLEAN(1), "adDescriptions_MODIFIED" BOOLEAN(1))
+--
+
+
+
+CREATE TABLE AD_DESCRIPTION_AUDITED (
+  ID bigint(20) NOT NULL,
+  REVISION bigint(20) NOT NULL,
+  REVISION_TYPE tinyint(3) DEFAULT NULL,
+  REVISION_END bigint(20) DEFAULT NULL,
+  REVISION_END_TIMESTAMP datetime DEFAULT NULL,
+  AD_DESCRIPTION varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+  AD_LINK varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+  AD_MOBILE_TEXT varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+  AD_NAME varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+  LANGUAGE_ID bigint(20) DEFAULT NULL,
+  AD_ID bigint(20) DEFAULT NULL,
+  PRIMARY KEY (ID,REVISION),
+  KEY IND_01_AD_DESCRIPTION_AUDITED (REVISION),
+  KEY IND_02_AD_DESCRIPTION_AUDITED (REVISION_END),
+  CONSTRAINT FK_01_AD_DESCRIPTION_AUDITED FOREIGN KEY (REVISION) REFERENCES CUSTOM_REVISION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
+  CONSTRAINT FK_02_AD_DESCRIPTION_AUDITED FOREIGN KEY (REVISION_END) REFERENCES CUSTOM_REVISION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
+);
+
+
+
+
diff --git a/SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/flyway/flyway.conf b/SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/flyway/flyway.conf
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/flyway/flyway.xml b/SpringJava/Gradle/spring-jpa-persistence/src/main/resources/spring-configuration/flyway/flyway.xml
new file mode 100644 (file)
index 0000000..676bd6d
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+               http://www.springframework.org/schema/beans
+               http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+    <bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate">
+        <property name="dataSource" ref="dataSource" />
+        <property name="schemas" value="mybatis_example" />
+        <property name="locations" value="classpath:/spring-configuration/flyway/" />
+        <property name="baselineOnMigrate" value="true" />
+    </bean>
+
+
+</beans>
\ No newline at end of file