Skip to content

Instantly share code, notes, and snippets.

View goyalmohit's full-sized avatar

mohit goyal goyalmohit

View GitHub Profile
@goyalmohit
goyalmohit / tag-database-using-liquibase
Created March 9, 2019 13:44
Tag database using liquibase command
liquibase
--driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
--classpath="C:\\Program Files\\Microsoft JDBC Driver 6.0 for SQL Server\\sqljdbc_6.0\\enu\\jre8\\sqljdbc42.jar"
--url="jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks2017;integratedSecurity=false;"
--changeLogFile="D:\Source\generateChangeLog.xml"
--username=liquibase
--password=liquibase@123
--logLevel=info
tag dbchange-ci-1.0.0.219
@goyalmohit
goyalmohit / drop-table-with-precondition.xml
Created March 4, 2019 19:49
drop a table using precondition in liquibase
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
<changeSet author="mohitgoyal" id="20190304224600">
<preConditions onFail="HALT">
<sqlCheck expectedResult="0">select count(*) from customer</sqlCheck>
</preConditions>
<comment>Make sure that no data exists in the table before you drop it</comment>
<dropTable tableName="customer"/>
</changeSet>
</databaseChangeLog>
@goyalmohit
goyalmohit / add-new-column-with-precondition.xml
Created March 4, 2019 18:52
Add a new column in existing table customerdetails using preconditions in liquibase
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
<changeSet author="mohitgoyal" id="20190304223500">
<preConditions onFail="HALT">
<tableExists schemaName="dbo" tableName="CustomerDetails"/>
</preConditions>
<addColumn schemaName="dbo" tableName="CustomerDetails">
<column name="CustomerAddress" type="varchar(255)"/>
</addColumn>
</changeSet>
@goyalmohit
goyalmohit / error-log-table-changelog.sql
Created March 4, 2019 12:03
Liquibase formatted Sql changelog to create table named ErrorLog
--liquibase formatted sql
--changeset mohitgoyal:20190304153300 context:development
CREATE TABLE [dbo].[ErrorLog](
[ErrorLogID] [int] IDENTITY(1,1) NOT NULL,
[ErrorTime] [datetime] NOT NULL,
[UserName] [sysname] NOT NULL,
[ErrorNumber] [int] NOT NULL,
[ErrorSeverity] [int] NULL,
@goyalmohit
goyalmohit / download-liquibase.yml
Last active March 3, 2019 17:13
Quick ansible playbook to download and setup liquibase
--- # Quick ansible playbook for downloading liquibase
- name: download liquibase using ansible
hosts: dbservers
connection: ssh
sudo: yes
user: user
tasks:
- name: Create liquibase directory
file:
name: /opt/liquibase
@goyalmohit
goyalmohit / liquibase.properties
Last active March 2, 2019 09:50
Liquibase Properties file to compare databases
driver:com.microsoft.sqlserver.jdbc.SQLServerDriver
classpath:..\\Program Files\\Microsoft JDBC Driver 6.0 for SQL Server\\sqljdbc_6.0\\enu\\jre8\\sqljdbc42.jar
url:jdbc:sqlserver://localhost:1433;databaseName=AdventureWorksProd;integratedSecurity=false;
username:liquibase
password:liquibase@123
logLevel:debug
referenceUrl:jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks2017;integratedSecurity=false;
referenceUsername:liquibase
referencePassword:liquibase@123
@goyalmohit
goyalmohit / compare-database-using-liquibase
Last active May 19, 2022 16:22
Liquibase command to compare databases
liquibase
--driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
--classpath="C:\\Program Files\\Microsoft JDBC Driver 6.0 for SQL Server\\sqljdbc_6.0\\enu\\jre8"
--url="jdbc:sqlserver://localhost:1433;databaseName=AdventureWorksProd;integratedSecurity=false;"
--username=liquibase
--password=liquibase@123
--logLevel=debug
diff
--referenceUrl="jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks2017;integratedSecurity=false;"
--referenceUsername=liquibase
@goyalmohit
goyalmohit / export-data-using-liquibase
Last active December 10, 2024 01:41
Export data from existing database using Liquibase
liquibase
--driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
--classpath="C:\\Program Files\\Microsoft JDBC Driver 6.0 for SQL Server\\sqljdbc_6.0\\enu\\jre8"
--url="jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks2017;integratedSecurity=false;"
--changeLogFile="D:\Source\generateChangeLog--PersonSchema.xml"
--username=liquibase
--password=liquibase@123
--logLevel=info
--defaultSchemaName=dbo
--diffTypes=data
@goyalmohit
goyalmohit / export-schema-using-liquibase
Last active March 2, 2019 09:56
Export Specified Schema from database using Liquibase
liquibase
--driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
--classpath="C:\\Program Files\\Microsoft JDBC Driver 6.0 for SQL Server\\sqljdbc_6.0\\enu\\jre8"
--url="jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks2017;integratedSecurity=false;"
--changeLogFile="D:\Source\generateChangeLog--PersonSchema.xml"
--username=liquibase
--password=liquibase@123
--logLevel=info
--defaultSchemaName=Person
generateChangeLog
@goyalmohit
goyalmohit / export-db-schema
Last active March 2, 2019 09:54
Export DB Schema using Liquibase
liquibase
--driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
--classpath="C:\\Program Files\\Microsoft JDBC Driver 6.0 for SQL Server\\sqljdbc_6.0\\enu\\jre8\\sqljdbc42.jar"
--url="jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks2017;integratedSecurity=false;"
--changeLogFile="D:\Source\generateChangeLog.xml"
--username=liquibase
--password=liquibase@123
--logLevel=info
generateChangeLog