Liquibase diffChangeLog does not report stored procedures - sql-server

I am new to Liquibase. I am using Liquibase version 4.0 and on Windows 10 Home edition
Starting Liquibase at 23:08:42 (version 4.0.0 #19 built at 2020-07-13 19:45+0000)
Liquibase Version: 4.0.0
Liquibase Community 4.0.0 by Datical
I added one table and SP to DATABASEONE. I also generated diff between two databases and it worked fine.
liquibase diffChangeLog
liquibase.properties
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
classpath=../mssql-jdbc-8.4.0.jre11.jar
url=jdbc:sqlserver://localhost;databaseName=DATABASETWO
username=sa
password=Password123
referenceUrl=jdbc:sqlserver://localhost;databaseName=DATABASEONE
referenceUsername=sa
referencePassword=Password123
changeLogFile=diff.xml
However, Liquibase does not report difference on stored procedures.
How can I get the newly added (or) missing stored procedure information in diffChangeLog ?
EDIT
I used Pro License Key (14-day trial) to generate the diff for Stored Procedures
I also generated liquibase updateSQL > update.sql. Now I want to run 'update.sql' against another database. How can I do that?

Running an update on the update.sql generatated the command liquibase updateSQL > update.sql will return extra stuff that is debug info. Not just straight SQL. You will want to:
use generateChangelog to produce a changelog file (let's call it change.postgresql.xml)
run liuqibase update using the above produced changelog file and url of destination db
Note, if they are different db platforms, like say from postgres->mysql, then you will have to review the generate changelog (in this case change.postgresql.xml) for non spec db objects of the target db (in this example mysql).

Unfortunately, you can't diff stored function / procedure according to diff-changelog document
Additional Functionality with Liquibase Pro
While Liquibase Open Source stores all changesets in a changelog, Liquibase Pro creates a directory called Objects and places the directory at the same level as your changelog. The Objects directory contains a subdirectory for each of the following stored logic types:
checkconstraint
package
packagebody
procedure
function
trigger
synonyms

Related

How to generate the DB script by query. (NOT GUI)

I tried to generate the script by query because I want create easily and same settings. I checked MSdoc but there is no method.
I use SSMS v17.6, SQLServer2016(SP2) on WindowsServer2012 R2 Standard.
By the GUI, DB right click=>Task=>generate scripts=>select database objects and set some settings.
I want to generate by query.
You can follow below steps to automate the creation of a database.
First export the database as a dapac using Export Data Tier Application
Install SQLPackage.exe in the environment where you are planning to carry out the deployment. You can download sqlpackage.exe download path . It will be used to automate the generation of scripts from DACPAC.
Once you have the DACPAC of the database, you can publish the same to any environment. The caveat is, Sqlpackage.exe generates incremental script, comparing against the target datatbase. If you want complete CREATE script, then you can point against any empty database or system database like master to generate incremental CREATE scripts(here it will be complete database script, as target is empty database). The generated script will be present in the output path (here, it is C:\temp)
Note: we are setting parameter (DropObjectsNotInSource to false), to avoid generation of drop objects of the target database, which are
missing in source DACPAC.
"<Path>\SqlPackage.exe"
/Action:script
/SourceFile:“<Path>\Database.dacpac”
/TargetDatabaseName:master
/TargetServerName:"localhost"
/OutputPath:C:\temp
/p:DropObjectsNotInSource:false
UPDATE
I see that, now there is a tool mssql-scripter(currently in preview) to carry out the same activity of Generate Scripts wizard of SQL Server Management Studio. You can see about the tool here: https://github.com/Microsoft/mssql-scripter

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.

SSDT: incremental update script including data using sqlpackage.exe

I have an SSDT project with VS2015 and using SqlPackage.exe to generate deployment scripts and incremental update scripts. The database project contains post deployment scripts. here's how I generate the main script for DB installation:
sqlpackage.exe
/a:Script
/op:"database.sql"
/sf:"database.dacpac"
/tsn:"localhost"
/tdn:"MyDbName"
/p:CommentOutSetVarDeclarations="True"
/p:ScriptDatabaseCompatibility="True"
/p:IgnoreFileAndLogFilePath="True"
/p:IgnoreFilegroupPlacement="True"
/p:ScriptFileSize="True"
/p:PopulateFilesOnFilegroups="False"
This will output database.sql file which I run with sqlcmd.exe. the script file also contains all my post deployment scripts (Insert, Update, etc..)
Once I have a new version of the database, I create incremental update script from previously taken dacpac snapshot:
sqlpackage.exe
/a:Script
/op:"%migratePath%\%database%.!build!-%version%.sql"
/sf:"%snapshotPath%\%database%.%version%.dacpac"
/tf:"%snapshotPath%\%database%.!build!.dacpac"
/tdn:"MyDbName"
/p:CommentOutSetVarDeclarations="True"
/p:AllowIncompatiblePlatform="True"
/p:IgnorePermissions="True"
/p:IgnoreRoleMembership="True"
/p:ExcludeObjectTypes=Users;Credentials;Logins;Permissions;RoleMembership;ServerRoles;ServerRoleMembership;
this works fine, however, incremental update script does not contain metadata/reference data (e.g. e.g. list of countries, states, currencies, etc.).
Is there a way to tell SqlPackage to generate incremental script that contains the table reference data as well?

Differences between SqlPackage.exe and MsBuild SqlPublishTask

I'm trying to generate an output dacpac file which I can then deploy to different environments. Until now I was deploying directly from msbuild using the target publish, something like:
msbuild dbproject.sqlproj /t:Build;Publish /p:SqlPublishProfilePath=test.publish.xml /p:UpdateDatabase=True /p:PublishScriptFileName=test.sql
The size of the ouput script generated (just for reference as UpdateDatabase is set to true) is 2.5MB.
My new approach is to just build the project, store the dacpac and then deploy using sqlpackage with action 'Publish'. This new method is reporting some warnings which were not reported by msbuild SqlPublishTask.
For reference I ran the next command:
sqlpackage.exe /action:script /outputpath:test.sql /sourcefile:dbproject.dacpac /pr:test.publish.xml
and the size of the output script is now 4.9MB.
The specific warnings reported are not the concern here, the concern is that the script is different, my question is what is the difference?
and more importantly which one would be the best/safest method to do the deploy?
Sqlpackage.exe is more detailed and includes more objects during the deployment, it drops the permissions to tables to avoid any modification during the modification of the objects and then it proceeds to create or modify the them.
The difference is that ALL the objects are included in the script of sqlpackage, independently on whether they are different or not from the target database.
Although the warnings given were not a concern initially, using the sqlpackage method I discovered that some store procedure were not in the solution, only in the database. These 'orphan' sp were referencing tables being deployed, which is giving a warning stating that a change in the table may break the sp.

TFS - Compare branch and export

We currently use TFS 2010 for our VS applications and our SQL code. For SQL we have every stored procedure stored in different text files e.g."spname.sql" and we alter these files and then apply them to the Dev server.
When it comes to testing we then do a branchcompare to compare the DEV branch to the UAT branch to get a list of the .sql files that are different.
Question is, is there a way to export out the files in the list from the dev branch so we can them apply all the SQL code that has changed to the UAT server?
(We do table alters / updates etc in a "rollout" type script).
Thanks
When you do a compare in Visual Studio (with SSDT), you can choose to create a script instead of deploying. Or you could use powershell Get-TfsItemHistory with -Version to get the file list and then use that list to get the source.

Resources