Liquibase:dropAll didn't delete schema

2019-08-28 00:18发布

问题:

my software:
Maven 3.0.4
Liquibase: 3.0.2
Postgresql: 9.1.9
JavaSE: 1.7.0_25

My problem:
I create some schema with liquibase

<changeSet id="create-customermgmt-schema" author="nl">  
   <sql>CREATE SCHEMA "customermgmt";</sql>  
</changeSet>

If i try to exec liquibase:dropAll i get this:

[INFO] Scanning for projects...  
[INFO]                                                                           
[INFO] ------------------------------------------------------------------------    
[INFO] Building akufit.server 0.0.1-SNAPSHOT    
[INFO] ------------------------------------------------------------------------   
[INFO]   
[INFO] --- liquibase-maven-plugin:3.0.2:dropAll (default-cli) @ akufit.server ---   
[INFO] ------------------------------------------------------------------------   
[INFO] Executing on Database: jdbc:postgresql://localhost:5432/akufit   
INFO 8/18/13 5:45 PM:liquibase: Successfully acquired change log lock   
INFO 8/18/13 5:45 PM:liquibase: Dropping Database Objects in schema: akufit.public   
INFO 8/18/13 5:45 PM:liquibase: Creating database history table with name: public.databasechangelog    
INFO 8/18/13 5:45 PM:liquibase: Successfully released change log lock    
INFO 8/18/13 5:45 PM:liquibase: Successfully released change log lock    
[INFO] ------------------------------------------------------------------------   
[INFO]     
[INFO] ------------------------------------------------------------------------   
[INFO] BUILD SUCCESS   
[INFO] ------------------------------------------------------------------------   
[INFO] Total time: 5.978s   
[INFO] Finished at: Sun Aug 18 17:45:54 CEST 2013   
[INFO] Final Memory: 8M/85M     
[INFO] ------------------------------------------------------------------------`   

but my schema are still there and nothing is droped.

I verified, that all tables and schemas belong to the user in the liquibase settings. If you need more information, please write.

Maybe you can help me. Thanks.

pom.xml:

<plugin>   
    <groupId>org.liquibase</groupId>   
    <artifactId>liquibase-maven-plugin</artifactId>   
    <version>3.0.2</version>   
    <configuration>   
        <changeLogFile>src/main/resources/db-changelog.xml</changeLogFile>   
    <driver>org.postgresql.Driver</driver>   
    <url>jdbc:postgresql://localhost:5432/akufit</url>   
    <username>***</username>   
    <password>***</password>   
    </configuration>   
    <dependencies>   
        <dependency>   
        <groupId>postgresql</groupId>   
        <artifactId>postgresql</artifactId>   
        <version>9.0-801.jdbc4</version>   
    </dependency>   
    </dependencies>   
</plugin>

回答1:

Liquibase is designed to manage the objects within your application's schema. This explains why there are no "create schema" database actions supported.

This does not prevent someone writing custom SQL actions that would create/drop schemas, but this causes some problems, for example liquibase creates two additional book keeping tables within the schema that would also be wiped out....

Is there a good reason why the schema creation cannot be done outside of liquibase? I generally create a new schema and associated user for each application instance. In this way I don't have to configure liquibase with my database's admin account.



回答2:

What @Mark O'Connor wrote is 100% right. If you programmatorically drop the Schema where the LiquiBase changelog tables are, you will get the following error:

SEVERE 5/02/14 10:26:liquibase: liquibase/db.dropschema.changelog.xml::dropschema-1::debacked: Could not release lock

This is because you dropped also the LiquiBase changelog tables.

You can easily solve this by setting the parameter liquibase.changelogSchemaName. That way the LiquiBase Changelog tables have their own schema.

By the way, I always set this parameter, that way the LiquiBase Changelog tables do not clutter up your Schema, as they do not have any business value...