Applies to
- Liquibase Secure (Pro)
- Liquibase Community (Open Source)
Conditions
- PostgreSQL database (may apply to other databases)
- Schema name contains uppercase letters
Issue Summary
When using a schema name that contains uppercase letters with the --defaultSchemaName or --liquibase-schema-name parameters, Liquibase fails to create its tracking tables and returns an error stating the schema does not exist, even though the schema exists in the database.
Error Message
Liquibase 4.31.0:
Unexpected error running Liquibase: ERROR: schema "schema_name" does not exist
Position: 14 [Failed SQL: (0) CREATE TABLE SCHEMA_NAME.databasechangelog ...]Liquibase 4.32.0+:
Unexpected error running Liquibase: An error occurred while attempting to create the database changelog table. Please make sure that you have both read and write permissions for the 'SCHEMA_NAME.databasechangelog' table.
- Caused by: ERROR: schema "schema_name" does not exist
Position: 14 [Failed SQL: (0) CREATE TABLE SCHEMA_NAME.databasechangelog ...]
Root Cause
By default, Liquibase does not treat schema and catalog names as case-sensitive. When an uppercase schema name is passed via the command line, Liquibase converts it to lowercase before executing the SQL statement. Since PostgreSQL is case-sensitive with quoted identifiers, the generated SQL references a lowercase schema name (schema) that does not match the actual uppercase schema (SCHEMA) in the database, causing the error.
Resolution
Add the --preserve-schema-case=true parameter to your Liquibase command. This tells Liquibase to quote schema names in SQL statements, preserving their original casing.
Also, ensure that the value for --liquibase-schema-name is not wrapped in quotes on the command line.
Example command:
liquibase \
--url=<your_url> \
--username=<your_username> \
--password=<your_password> \
--changeLogFile=<your_changelog_file> \
--defaultSchemaName=SCHEMA_NAME \
--liquibase-schema-name=SCHEMA_NAME \
--preserve-schema-case=true \
update
When preserve-schema-case is enabled, the generated SQL will correctly quote the schema name:
CREATE TABLE "SCHEMA_NAME".databasechangelog (...)
Parameter Formats
CLI:
--preserve-schema-case=trueFlow File:
globalArgs: {preserve-schema-case: "true"} Properties File:
liquibase.preserveSchemaCase: trueEnvironment Variable:
LIQUIBASE_PRESERVE_SCHEMA_CASE=true
Comments
0 comments
Article is closed for comments.