Liquibase : Automating Your SQL and PL/SQL Deployments
This article gives a quick overview of applying changes to the database using Liquibase.
oracle miscconfigurationintermediate
by OracleDba
14 views
This article gives a quick overview of applying changes to the database using Liquibase.
123456789101112131415161718
Rem Windows
c:\software\liquibase\liquibase-3.10.0 : The Liquibase software.
c:\git\my_project\changelogs : The location for the individual Liquibase changelogs.
c:\git\my_project\scripts : The location of any scripts referenced by Liquibase.
c:\git\my_project\changelogs\changelog_master.xml : The master.xml that maintains the changelog order.
# Linux
/software/liquibase/liquibase-3.10.0 : The Liquibase software.
/git/my_project/changelogs : The location for the individual Liquibase changelogs.
/git/my_project/scripts : The location of any scripts referenced by Liquibase.
/git/my_project/changelogs/changelog_master.xml : The master.xml that maintains the changelog order.
Rem Windows
set PATH=c:\software\liquibase\liquibase-3.10.0;%PATH%
set JAVA_HOME=c:\Program Files\Java\jre1.8.0_221
# Linux
export PATH=/software/liquibase/liquibase-3.10.0:$PATH123456789101112131415
liquibase --driver=oracle.jdbc.OracleDriver ^
--classpath="/software/liquibase/liquibase-3.10.0/lib" ^
--changeLogFile="/git/my_project/changelogs/changelog_00001.xml" ^
--url="jdbc:oracle:thin:@localhost:1521/pdb1" ^
--username=test ^
--password=test ^
{command}
driver: oracle.jdbc.OracleDriver
classpath: /software/liquibase/liquibase-3.10.0/lib
url: jdbc:oracle:thin:@localhost:1521/pdb1
username: test
password: test
liquibase --defaultsFile="/software/liquibase/test_liquibase.properties" {command}12345678910111213141516171819202122232425262728293031323334353637383940414243
create table tab1 (
id number,
description varchar2(50),
constraint tab1_pk primary key (id)
);
create sequence tab1_seq;
insert into tab1 (id, description) values (tab1_seq.nextval, 'Description for ' || tab1_seq.currval);
commit;
create or replace function get_tab1_count return number as
l_count number;
begin
select count(*)
into l_count
from tab1;
return l_count;
end;
/
liquibase --defaultsFile="/software/liquibase/test_liquibase.properties" --changeLogFile="my_changelog.xml" generateChangeLog
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd">
<changeSet author="tim (generated)" id="1571293572660-1">
<createTable tableName="TAB1">
<column name="ID" type="NUMBER">
<constraints primaryKey="true" primaryKeyName="TAB1_PK"/>
</column>
<column name="DESCRIPTION" type="VARCHAR2(50 BYTE)"/>
</createTable>
</changeSet>
<changeSet author="tim (generated)" id="1571293572660-2">
<createSequence maxValue="9999999999999999999999999999" sequenceName="TAB1_SEQ" startValue="21"/>
</changeSet>
</databaseChangeLog>1234567891011121314151617
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd">
</databaseChangeLog>
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd">
<includeAll path="/git/my_project/changelogs"/>
</databaseChangeLog>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
-- tab1_seq.sql
create sequence tab1_seq;
-- tab1.sql
create table tab1 (
id number,
description varchar2(50),
constraint tab1_pk primary key (id)
);
insert into tab1 (id, description) values (tab1_seq.nextval, 'Description for ' || tab1_seq.currval);
commit;
-- get_tab1_count.sql
create or replace function get_tab1_count returns number as
l_count number;
begin
select count(*)
into l_count
from tab1;
return l_count;
end;
/
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd">
<changeSet author="tim" id="01_tab1_seq">
<sqlFile dbms="oracle"
endDelimiter=";"
path="../scripts/tab1_seq.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="false"/>
</changeSet>
<changeSet author="tim" id="02_tab1">
<sqlFile dbms="oracle"
endDelimiter=";"
path="../scripts/tab1.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="false"/>
</changeSet>
<changeSet author="tim" id="03_get_tab1_count" runOnChange="true">
<sqlFile dbms="oracle"
endDelimiter=";"
path="../scripts/get_tab1_count.sql"
relativeToChangelogFile="true"
splitStatements="false"
stripComments="false"/>
</changeSet>
</databaseChangeLog>
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd">
<include file="./changelog_00001_setup_tab1.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
liquibase --defaultsFile="/software/liquibase/test_liquibase.properties" ^
--changelog-file="/git/my_project/changelogs/changelog_master.xml" ^
update
column object_name format a30
select object_name, object_type
from user_objects
order by 1, 2;
OBJECT_NAME OBJECT_TYPE
------------------------------ -----------------------
DATABASECHANGELOG TABLE
DATABASECHANGELOGLOCK TABLE
GET_TAB1_COUNT FUNCTION
PK_DATABASECHANGELOGLOCK INDEX
TAB1 TABLE
TAB1_PK INDEX
TAB1_SEQ SEQUENCE
7 rows selected.
SQL>
SQL> desc databasechangelog
Name Null? Type
------------- -------- -------------
ID NOT NULL VARCHAR2(255)
AUTHOR NOT NULL VARCHAR2(255)
FILENAME NOT NULL VARCHAR2(255)
DATEEXECUTED NOT NULL TIMESTAMP(6)
ORDEREXECUTED NOT NULL NUMBER(38)
EXECTYPE NOT NULL VARCHAR2(10)
MD5SUM VARCHAR2(35)
DESCRIPTION VARCHAR2(255)
COMMENTS VARCHAR2(255)
TAG VARCHAR2(255)
LIQUIBASE VARCHAR2(20)
CONTEXTS VARCHAR2(255)
LABELS VARCHAR2(255)
DEPLOYMENT_ID VARCHAR2(10)
SQL>
column id format a17
column filename format a60
select id, filename from databasechangelog;
ID FILENAME
----------------- ------------------------------------------------------------
01_tab1_seq /git/my_project/changelogs/changelog_00001_setup_tab1.xml
02_tab1 /git/my_project/changelogs/changelog_00001_setup_tab1.xml
03_get_tab1_count /git/my_project/changelogs/changelog_00001_setup_tab1.xml
SQL>
-- tab2_seq.sql
create sequence tab2_seq;
-- tab2.sql
create table tab2 (
id number,
description varchar2(50),
constraint tab2_pk primary key (id)
);
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd">
<changeSet author="tim" id="01_tab2_seq">
<sqlFile dbms="oracle"
endDelimiter=";"
path="../scripts/tab2_seq.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="false"/>
</changeSet>
<changeSet author="tim" id="02_tab2">
<sqlFile dbms="oracle"
endDelimiter=";"
path="../scripts/tab2.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="false"/>
</changeSet>
</databaseChangeLog>
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd">
<include file="./changelog_00001_setup_tab1.xml" relativeToChangelogFile="true"/>
<include file="./changelog_00002_setup_tab2.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
liquibase --defaultsFile="/software/liquibase/test-liquibase.properties" ^
--changelog-file="/git/my_project/changelogs/changelog_master.xml" ^
update
column object_name format a30
select object_name, object_type
from user_objects
order by 1, 2;
OBJECT_NAME OBJECT_TYPE
------------------------------ -----------------------
DATABASECHANGELOG TABLE
DATABASECHANGELOGLOCK TABLE
GET_TAB1_COUNT FUNCTION
PK_DATABASECHANGELOGLOCK INDEX
TAB1 TABLE
TAB1_PK INDEX
TAB1_SEQ SEQUENCE
TAB2 TABLE
TAB2_PK INDEX
TAB2_SEQ SEQUENCE
10 rows selected.
SQL>
column id format a17
column filename format a60
select id, filename from databasechangelog;
ID FILENAME
----------------- ------------------------------------------------------------
01_tab1_seq /git/my_project/changelogs/changelog_00001_setup_tab1.xml
02_tab1 /git/my_project/changelogs/changelog_00001_setup_tab1.xml
03_get_tab1_count /git/my_project/changelogs/changelog_00001_setup_tab1.xml
01_tab2_seq /git/my_project/changelogs/changelog_00002_setup_tab2.xml
02_tab2 /git/my_project/changelogs/changelog_00002_setup_tab2.xml
SQL>Please to add comments
No comments yet. Be the first to comment!