liquibase / liquibase-hibernate

Liquibase Hibernate Integration
Apache License 2.0
272 stars 157 forks source link

liquibase ignores envers tables postfix therefore tables missing #169

Open zapphyre opened 6 years ago

zapphyre commented 6 years ago

I am using liquibase 3.5.3 with hibernate 5.2.9.Final and envers 5.2.12.Final.

liquibase configuration: pom.xml:

            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>3.5.3</version>
                <configuration>
                    <propertyFile>src/main/resources/liquibase.properties</propertyFile>
                    <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
                    <referenceUrl>
                        hibernate:spring:com.nws.vedica.model?dialect=org.hibernate.dialect.PostgreSQL92Dialect
                    </referenceUrl>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.liquibase.ext</groupId>
                        <artifactId>liquibase-hibernate5</artifactId>
                        <version>3.6</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-beans</artifactId>
                        <version>${spring.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.data</groupId>
                        <artifactId>spring-data-jpa</artifactId>
                        <version>1.11.1.RELEASE</version>
                    </dependency>
                    <dependency>
                        <groupId>javax.validation</groupId>
                        <artifactId>validation-api</artifactId>
                        <version>2.0.0.Final</version>
                    </dependency>
                </dependencies>
            </plugin>

liquibase.properties:

url=jdbc:postgresql://212.89.239.181:5432/vedica_db
username=vedic
password=veda
driver=org.postgresql.Driver
outputChangeLogFile=src/main/resources/liquibase-outputChangeLog.xml
changeLogFile=src/main/resources/liquibase-changeLog.xml

JPAConfig.java:

@PostConstruct
    public void init() {
        properties = new HashMap<>();
        properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQL92Dialect");
        properties.put("javax.persistence.jdbc.url", dbConnectionURL);
        properties.put("javax.persistence.jdbc.user", dbUser);
        properties.put("javax.persistence.jdbc.password", dbPassword);
        properties.put("hibernate.show_sql", log);
        properties.put("javax.persistence.jdbc.driver", "org.postgresql.Driver");
        properties.put("javax.persistence.target-database", "PostgreSQL");
        properties.put("org.hibernate.envers.audit_table_suffix", "_vers");
        properties.put("org.hibernate.envers.default_schema", "audit");
        properties.put("hibernate.integration.envers.enabled", "true");
        properties.put("hibernate.enable_lazy_load_no_trans", "true");
        properties.put("hibernate.jdbc.batch_size", "20");
        properties.put("hibernate.jdbc.batch_versioned_data", "true");
//        properties.put("hibernate.order_inserts", "true");
//        properties.put("hibernate.order_updates", "true");

        properties.put("hibernate.c3p0.timeout", "300");
        properties.put("hibernate.c3p0.min_size", "7");
        properties.put("hibernate.c3p0.max_size", "20");
        properties.put("hibernate.c3p0.max_statements", "50");
        properties.put("hibernate.c3p0.hibernate.c3p0.idle_test_period", "3000");
        properties.put("hibernate.c3p0.preferredTestQuery","SELECT 1");
        properties.put("hibernate.c3p0.testConnectionOnCheckout","true");
        properties.put("hibernate.c3p0.acquireRetryAttempts","1");
        properties.put("hibernate.c3p0.acquireIncrement","1");
        properties.put("hibernate.c3p0.idleConnectionTestPeriod","60");
        properties.put("hibernate.jdbc.lob.non_contextual_creation","true");
    }

so you see, my audit tables gets generated in 'audit' catalog with the '_vers' suffix.

when I run 'mvn liquibase:diff' it keeps telling me that audit tables are missing:

Missing Table(s): 
     DocShreddingInfo_AUD
     DocType_keywords_AUD
     DocVersion_AUD
     MetaFieldValidityRules_AUD
     Metadata_additions_AUD
     Metadata_json_AUD
     Metadata_patterns_AUD
     PartyKind_AUD
     ValidityRule_AUD
     document_AUD
     document_type_AUD
     product_instance_AUD
     related_doc_AUD
     shredding_type_AUD
     task_AUD

so it can't read suffinx information form the hibernate configuration. I have tried set @AuditTable on the entity with the value of the actual table name, but does not help.

advice, please.

┆Issue is synchronized with this Jira Bug by Unito

crtk commented 6 years ago

these might be helpful: #137 #99

zapphyre commented 6 years ago

I have seen and tried those, that's why I mention I tried @Audittable. But that's workaround anyway. Hope someone can solve it finally.

MalteKrueger commented 6 years ago

I wrote another workaournd in #99 which could solve this problem. Just set the "unsupported" properties via the environment (i.e -Dorg.hibernate.envers.audit_table_suffix=_vers)

zapphyre commented 6 years ago

Yes, now the problem is that it makes diff of the 'audit' postgre schema but on update goal it updates 'public' schema with the audit tables.. Is there an option to make liquibase preserve schema information?

felixoi commented 1 year ago

Does someone has a fix for this? Struggling with this problem too. @MalteKrueger's workaround seems not to work out for me.