Liquibase schema-qualified change log - sql-server

Is it possible and what are best practices for generating schema-qualified object names in a Liquibase change log .sql file?
For example, I want the command liquibase generateChangeLog to generate a .sql file where the objects are schema qualified (CREATE TABLE [schema_name].[table_name]...). What I get is something like CREATE TABLE [table_name]... without the schema qualification.
I have tried the schemas and defaultSchema properties and their command-line equivalent w/no success. I have also tried setting the default schema for the liquibase login w/no success.
P.S. - this is for an MSSQL database.

Have you looked into using --includeSchema or --includeCatalog optional arguments with liquibaseGenerateChangeLog command?
Here's the documentation that mentions these optional arguments:

Related

DACPAC - How to deploy one particular schema

I've been looking to find ways to deploy one particular schema (Schema B) from database (Schema A, Schema B, Schema c..) using dacpac and sqlpackage.exe.
I found this similar question but looks like the links on it have been archived. also found out to put this parameter in sqlpackage.exe cmd DropObjectsNotInSource = false but still both schema are getting deployed. can anyone help?
I found out this can be done using this DeploymentContributorFilterer.
Put the AgileSqlClub.SqlPackageFilter.dll file into the same folder as SqlPackage.exe, and add these commmand line parameters to your deployment:
/p:AdditionalDeploymentContributors=AgileSqlClub.DeploymentFilterContributor /p:AdditionalDeploymentContributorArguments="SqlPackageFilter=IgnoreSchema(**SchemaA**)"

Why does Liquibase generateChangeLog generate an empty changelog file?

I'm using Liquibase to generate a DB scheme from existing H2 database.
I use the following:
liquibase --driver=org.h2.Driver --classpath=./h2-1.4.199.jar --changeLogFile=db.schema.sql --url="jdbc:h2:mem:testdb" --username=sa --password= --logLevel=debug generateChangeLog
So, absolutely default values in order to connect to the H2 instance. But the command above generates an empty changelog file (just some basic Liquibase headers).
I tried to use different urls (h2 in file), I tried to set different password and username, I even tried to define defaultSchemaName parameter, but still the same.
Liquibase maven plugin says: No changes found, nothing to do
Liquibase without maven plugin says: Liquibase command 'generateChangeLog' was executed successfully.
I also tried to put invalid credentials (username or password), but still the same.
generateChangeLog command exports data from the specified database. It means that such database should exist and be populated with some data.
There is no point to specify the in-memory embedded URL jdbc:h2:mem:testdb here. Each process have own memory and own in-memory databases. Liquibase will definitely see an empty database here inside its own memory.
You need to create a normal persistent database with your application and use its URL here. I strongly suggest you to specify the absolute database path (without file name extension) in the database URL to be sure that the same database will be used by your application and by Liquibase. Note that you can't use the embedded database by two applications at the same time without additional parameters (auto-server mode), so you need to close the database in your application before you'll launch Liquibase. As an alternative you can start the H2 Server process and use remote URLs or you can use the auto-server mode.
You can also append ;IFEXISTS=TRUE to the database URL for Liquibase only. It will prevent accidental silent creation of a new empty database in it.

Liquibase creates log tables with user schema

When implementing liquibase on Sql Server. Below tables are created on USER schema not with DBO schema. Not sure how to fix this.
AMAR.DATABASECHANGELOG
AMAR.DATABASECHANGELOGLOCK
It should be
DBO.DATABASECHANGELOG
DBO.DATABASECHANGELOGLOCK
I don't have any issues on creating table. It always creates on dbo schema. I'm using integratedSecurity and Liquibase version is 3.4.2
You can specify
--liquibaseSchemaName=dbo
as a parameter when running Liquibase from the command line.
I prefer to that into my liquibase.properties file.
This works for me using Liquibase 3.5.3 - don't know about 3.4.2 though
Have a look at changelogSchemaName parameters (http://www.liquibase.org/documentation/maven/generated/updateSQL-mojo.html) to specify schema where Liquibase stores tables.

mysqldump Fully Qualifies Triggers with Database Name

I'm am trying to use mysqldump to export a database which needs to be imported using a different database name. Looking at the SQL generated by mysqldump, it appears that triggers are the only object names which are fully-qualified with the source database name thus foiling my needs. Is there anyway to direct mysqldump to not fully-qualify any object names including triggers?
I had the same problem and I found the solution. I was using MySQL Workbench to design my database and I've created some triggers there. All of them used the syntax CREATE TRIGGER trigger_name except for one: CREATE TRIGGER dbname.trigger_name (it was just my mistake). Mysqldump output included all triggers in the same way: only one had database name.
Mysqldump uses your original CREATE TRIGGER instructions which you can see via SHOW CREATE TRIGGER. If you have a trigger defined with a database name, simply replace it (drop and create) with a one without dbname.
Most probably you add the database name when you create the trigger. Try updating your trigger without the database name in it.
Not an ideal solution but pumping the output through the following has gotten rid of the database name on the triggers for me.
mysqldump ... opts ... | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/'

Generating DDLs for Sybase tables and indexes

I'm looking for a command line tool to generate DDL for both tables and indexes (nothing more complicated is needed) for some Sybase tables in databases that I take care of. I have access to GUI tools for viewing the individual DDLs, and I could cut and paste them, but I would like something that will go through all the tables in a database and generate some nice text files that I can get checked into CVS.
I tried using a tool called ddlgen, which was provided by Sybase, but it just threw exceptions like this:
bash-3.00# ./ddlgen -SdatabaseServer:4100 -Uusername -PsecretPassword -TDB -NdatabaseName
U64: null: databaseName.dbo.firstTable
U64: null: databaseName.dbo.firstTable
at com.sybase.ddlgen.container.UserTableContainer.getDependentDDL(UserTableContainer.java:1065)
at com.sybase.ddlgen.container.UserTableContainer.open(UserTableContainer.java:1364)
at com.sybase.ddlgen.container.UserTableMetaContainer.open(UserTableMetaContainer.java:94)
at com.sybase.ddlgen.container.DDLBaseContainer.load(DDLBaseContainer.java:76)
at com.sybase.ddlgen.container.DatabaseContainer.addChildren(DatabaseContainer.java:552)
at com.sybase.ddlgen.container.DatabaseContainer.open(DatabaseContainer.java:104)
at com.sybase.ddlgen.container.DatabaseMetaContainer.open(DatabaseMetaContainer.java:114)
at com.sybase.ddlgen.DDLThread.run(DDLThread.java:89)
which wasn't very helpful. I keep thinking that there must be a nice Perlish way to do this, but I don't know what that would be.
You can also use the Perl-based dbschema.pl
http://www.isug.com/Sybase_FAQ/ASE/section9.html#9.3.2
use below command to get deffination
defncopy -P tester1 -S sqppdb2 -U pmestr -D ppdb2 -o tab4 ppdb2..tab4
Thanks
Download an evaluation version of Embarcadero DBArtisan and use its extract feature to get the DDL out.
You can turn Logging on in DBArtisan (Logfile ->Log SQL) and then see what SQL it's sending to Sybase to get the table DDL. Copy and paste the SQL in the logfile to a script that you run from the command line and that might work.
Apologies in advance if you are not using Windows...DBArtisan is Windows-only.
Another way of doing this is MyGeneration a code generator (like CodeSmith but open source) which uses templates to create code. That code could be anything you like - Sql, C# etc. I use Sql Server and I've used some of the freely available templates to create DDL as you specify, and automagically create NHibernate Mapping files too - brilliant.
ddlgen will give you what you require and works very well. You seem to be having an enviroment issue with Java. Try again and post the error that you have in it's entirety.

Resources