Creating a changelog for multiple databases in sql server

I am trying to start using liquibase on an existing SQL Server database. As a starting point I would like to use liquibase to generate the existing schema with the generateChangeLog command. This is what I am doing:

./liquibase --logLevel=debug --password=“myPassword” --username=myuser --url=“jdbc:sqlserver://localhost:1433;databaseName=My_Database_1” --changeLogFile=mylog.mssql.sql --includeTablespace=true --includeSchema=true --includeCatalog=true --schemas=My_Database_1 --defaultCatalogName=My_Database_1 --defaultSchemaName=My_Database_1 generateChangeLog

If I were using plain SQL I would have a statement near the top saying

USE My_Database_1

The ‘myuser’ user’s default schema is not My_Database_1. I’m not sure what the ‘schema’ command in liquibase is doing: SQL Server has multiple databases as well as schemas, and I need to generate a changelog for more than one database within the same server instance.

Liquibase gives me:

[2020-08-20 11:46:30] SEVERE [liquibase.integration] Unexpected error running Liquibase: Cannot use default schema name My_Database_1 on Microsoft SQL Server because the login schema of the current user (dbo) is different and MSSQL does not support setting the default schema per session.

Is there any way to use Liquibase to generate an initial changelog with SQL Server which is running more than one database?

Hi @duboisj,

I am not a 100% sure, I would defer to @NathanVoxland or our product team (@Pete / @mariochampion) but a workaround could be to generate changelog per schema individually (so multiple liquibase generateChangelog commands).

Backing up a sec:
What do you plan to do with those changelogs? Do you have other environments you need to seed and the source db is your baseline? Otherwise if all environments are already synchronized (as in the same schema exists across enviornments), you can just start creating changesets and use liquibase moving forward, no need to generate what is already there.

-Ronak