liquibase / liquibase-hibernate

Liquibase Hibernate Integration
Apache License 2.0
271 stars 154 forks source link

Entity attribute Schema does not work for diff #248

Open chernikov321 opened 4 years ago

chernikov321 commented 4 years ago

For example, i have two entities:

package ru.atc.initsqldata.entity.multischema;

import javax.persistence.*;

@Entity
@Table(schema = "schema1", name = "table1")
public class Entity1 {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String name;
}

and

package ru.atc.initsqldata.entity.multischema;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(schema = "schema2", name = "table2")
public class Entity2 {

    @Id
    private Long id;

    private String name;
}

When i run liquibase:diff script, i have the changelog like:

databaseChangeLog:
- changeSet:
    id: 1590958915435-1
    author: chernikov (generated)
    changes:
    - createTable:
        columns:
        - column:
            autoIncrement: true
            constraints:
              primaryKey: true
              primaryKeyName: table1PK
            name: id
            type: BIGINT
        - column:
            name: name
            type: VARCHAR(255)
        tableName: table1
- changeSet:
    id: 1590958915435-2
    author: chernikov (generated)
    changes:
    - createTable:
        columns:
        - column:
            constraints:
              nullable: false
            name: id
            type: BIGINT
        - column:
            name: name
            type: VARCHAR(255)
        tableName: table2
- changeSet:
    id: 1590958915435-3
    author: chernikov (generated)
    changes:
    - addPrimaryKey:
        columnNames: id
        constraintName: table2PK
        tableName: table2

Is it possible to get changelog like this? ... tableName: table1 schemaName: schema1 ... tableName: table2 schemaName: schema2

Here is my configs: pom.xml

          <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>3.5.5</version>
                <configuration>
                    <propertyFile>
                        ${project.build.outputDirectory}/properties/application-${liquibase.profile}.properties
                    </propertyFile>
                    <logging>info</logging>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.liquibase.ext</groupId>
                        <artifactId>liquibase-hibernate5</artifactId>
                        <version>3.6</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-data-jpa</artifactId>
                        <version>2.1.5.RELEASE</version>
                    </dependency>
                    <dependency>
                        <groupId>javax.validation</groupId>
                        <artifactId>validation-api</artifactId>
                        <version>2.0.1.Final</version>
                    </dependency>
                    <dependency>
                        <groupId>org.javassist</groupId>
                        <artifactId>javassist</artifactId>
                        <version>3.24.0-GA</version>
                    </dependency>
                    <dependency>
                        <groupId>org.yaml</groupId>
                        <artifactId>snakeyaml</artifactId>
                        <version>1.12</version>
                    </dependency>
                </dependencies>
            </plugin>

and properties file:

driver=org.postgresql.Driver
url=jdbc:postgresql://localhost:5432/test_db
username=test_db
password=pas
changeLogFile=@project.basedir@/src/main/resources/liquibase/changelog-master.yaml
referenceUrl=hibernate:spring:ru.atc.initsqldata.entity.multischema?dialect=org.hibernate.dialect.PostgreSQLDialect
diffChangeLogFile=@project.basedir@/src/main/resources/liquibase/changelog-@timestamp@.yaml
ignoreClasspathPrefix=true
changelogSchemaName=liquibase

┆Issue is synchronized with this Jira Bug by Unito

hkakutalua commented 4 years ago

Any update on this?

hkakutalua commented 4 years ago

Can i contribute with a PR?

DejfCold commented 2 years ago

Same issue here 2 years later. diffChangeLog --schemas=public,other --includeSchema=true generates schemaName="HIBERNATE" tableName="table1" and schemaName="HIBERNATE" tableName="table2" for entities defined as @Table(name = "table1", schema = "public") and @Table(name = "table2", schema = "other" respectively.

Versions:

seems like (also) unresolved #160 could be related

sitole commented 2 years ago

Same issue, its not possible to generate diff with tables in different Postgres Scheme. Liquibase is trying to generate all tables in default scheme from zero everytime.

Some quickfix? ❤️

sitole commented 2 years ago

Hey, any update in this topic? 🚀 We are ready to somehow support fix, because its critical use-case for our codebase with many database tables.

Its any possibility to support Liquidbase? ❤️

kataggart commented 2 years ago

@sitole I will see if we can give this some love and attention...

sitole commented 1 year ago

@kataggart Hi! I would like to ask if there has been any progress? 🚀 I see there is some issue (https://github.com/liquibase/liquibase/issues/3174) about schemes in Maven plugin but iam not sure if its relevant or not.

Thanks for your reply ✨

kataggart commented 1 year ago

@sitole wish I had a timeline for you, but I do not; we should hopefully be able to take a look at this soon.

dehidehidehi commented 11 months ago

Hello, I have the same issue, hoping this gets some love!