liquibase.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Wed, 23 Dec 2015 12:19:32 +0200
changeset 1842 e66fcbaf99fa
parent 1840 da2130eaa115
child 1844 7427de2e34ea
permissions -rw-r--r--
Split changesets into files. How big chould be changeset?
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1838
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     1
.. -*- coding: utf-8; -*-
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     2
.. include:: HEADER.rst
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     3
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     4
============
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
 LiquiBase.
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     6
============
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     7
.. contents::
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     8
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     9
Introducing LiquiBase to existing project.
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    10
==========================================
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    11
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    12
Official statement about introducing LiquiBase to existing project are:
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    13
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    14
  http://www.liquibase.org/documentation/existing_project.html
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    15
    Adding Liquibase on an Existing project
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    16
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    17
There are two approaches:
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    18
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    19
 * create full schema definition prior to introducing Liquibase
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    20
 * works only with current changes becase Liquibase basically work only with changesets and only
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    21
   special supplied instruments care about full schema definition
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    22
1840
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    23
To create full schema definition in LiquiBase XML changelog format you may run::
1838
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    24
1840
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    25
  $ mvn liquibase:generateChangeLog -Dliquibase.outputChangeLogFile=...
1838
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    26
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    27
on clean project without Liquibase. Or set name for changelog output file in ``pom.xml``.
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    28
(here reduced not fully worked declaration)::
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    29
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    30
  <plugin>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    31
      <groupId>org.liquibase</groupId>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    32
      <artifactId>liquibase-maven-plugin</artifactId>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    33
      <version>${liquibase.version}</version>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    34
      <configuration>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    35
          <outputChangeLogFile>changelog.xml</outputChangeLogFile>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    36
      </configuration>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    37
  </plugin>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    38
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    39
.. NOTE::
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    40
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    41
   ``pom.xml`` settings have precedence over ``-Dliquibase.outputChangeLogFile=...`` unless you
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    42
   define it as::
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    43
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    44
     <properties>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    45
         <liquibase.outputChangeLogFile>${project.build.directory}/changelog.xml</liquibase.outputChangeLogFile>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    46
     </properties>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    47
     <plugins>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    48
         <plugin>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    49
             <configuration>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    50
                 <outputChangeLogFile>${liquibase.outputChangeLogFile}</outputChangeLogFile>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    51
             </configuration>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    52
         </plugin>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    53
     </plugins>
031c61d1a8bd Introducing LiquiBase to existing project.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    54
1840
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    55
To create full schema definition in LiquiBase SQL format you may first to dump
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    56
your schema definition::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    57
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    58
  $ mysqldump --no-data -u $USER -p $DB_NAME > schema.sql
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    59
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    60
then check ``schema.sql`` for danger operations. For example I forget to add
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    61
``--skip-add-drop-table`` option to ``mysqldump`` and so remove any ``DROP
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    62
TABLE`` lines by editor.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    63
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    64
Becase we already have tables I replace ``CREATE TABLE`` statements with::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    65
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    66
  CREATE TABLE IF NOT EXISTS
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    67
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    68
Now my file is safely can be applied to production database without loosing
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    69
data and can recreate new schema in empty database.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    70
1842
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
    71
 * http://www.operatornew.com/2012/11/automatic-db-migration-for-java-web.html
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
    72
 * http://www.baeldung.com/liquibase-refactor-schema-of-java-app
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
    73
 * http://www.liquibase.org/documentation/existing_project.html
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
    74
 * http://www.liquibase.org/tutorial-using-oracle
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
    75
1840
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    76
Generate difference between databases.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    77
======================================
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    78
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    79
`This site
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    80
<http://www.broadleafcommerce.com/docs/core/current/appendix/managing-db-versions-migrations-with-liquibase>`_
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    81
suggest using Hibernate ``hibernate.hbm2ddl.auto=create`` to create clean schema
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    82
with Hibernate and compare it with previous one. So you:
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    83
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    84
 * create empty schema and grand permissions for user
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    85
 * register project to new user and schema, for example with Spring config::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    86
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    87
    <bean id="dataSource"
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    88
       class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    89
       <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    90
       <property name="url" value="jdbc:mysql://localhost:3306/app"/>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    91
       <property name="username" value="dbuser"/>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    92
       <property name="password" value="123456"/>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    93
    </bean>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    94
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    95
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    96
       <property name="dataSource" ref="dataSource" />
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    97
       <property name="jpaVendorAdapter">
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    98
           <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
    99
               <property name="generateDdl" value="false"/>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   100
               <property name="showSql" value="false"/>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   101
           </bean>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   102
       </property>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   103
       <property name="packagesToScan" value="com.app.domain" />
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   104
       <property name="jpaProperties">
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   105
          <props>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   106
              <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   107
              <prop key="hibernate.hbm2ddl.auto">create</prop>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   108
              <prop key="hibernate.default_schema">schema_v2_0</prop>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   109
          </props>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   110
       </property>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   111
    </bean>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   112
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   113
 * run Hibernate initialisation code via test or application deploy so
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   114
   ``hibernate.hbm2ddl.auto=create`` trigger to new schema generation.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   115
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   116
 * configure Maven ``pom.xml`` with paths and authentication data to old and new
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   117
   schema::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   118
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   119
     <plugin>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   120
         <groupId>org.liquibase</groupId>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   121
         <artifactId>liquibase-maven-plugin</artifactId>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   122
         <version>${liquibase.version}</version>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   123
         <configuration>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   124
             <changeLogFile>${basedir}/src/main/resources/sql/master.xml</changeLogFile>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   125
             <diffChangeLogFile>changelogDiff.xml</diffChangeLogFile>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   126
             <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   127
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   128
             <driver>com.mysql.jdbc.Driver</driver>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   129
             <username>dbuser</username>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   130
             <password>123456</password>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   131
             <url>jdbc:mysql://localhost:3306/app</url>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   132
             <defaultSchemaName>schema_v1.1</defaultSchemaName>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   133
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   134
             <referenceDriver>com.mysql.jdbc.Driver</referenceDriver>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   135
             <referenceUsername>dbuser</referenceUsername>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   136
             <referencePassword>123456</referencePassword>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   137
             <referenceUrl>jdbc:mysql://127.0.0.1:3306/app</referenceUrl>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   138
             <referenceDefaultSchemaName>schema_v2.0</referenceDefaultSchemaName>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   139
         </configuration>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   140
         <dependencies>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   141
             <dependency>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   142
                 <groupId>mysql</groupId>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   143
                 <artifactId>mysql-connector-java</artifactId>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   144
                 <version>5.1.6</version>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   145
             </dependency>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   146
         </dependencies>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   147
     </plugin>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   148
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   149
   .. NOTE::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   150
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   151
      ``username`` and ``referenceUsername`` as ``url`` and ``referenceUrl``,
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   152
      and ``defaultSchemaName`` and ``referenceDefaultSchemaName``, etc pairs
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   153
      should be adopted to your connection/authentication data. This settings
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   154
      also possible externalize to::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   155
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   156
        <changeLogFile>${basedir}/src/main/resources/sql/master.xml</changeLogFile>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   157
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   158
 * Review diff in ``changelogDiff.xml`` after::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   159
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   160
     $ mvn liquibase:diff
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   161
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   162
Resulted ``changelogDiff.xml`` may be registered to project with ``schema_v1.1``
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   163
schema state.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   164
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   165
It is possible to move inner part of ``changelogDiff.xml`` to the last changeset
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   166
that managed by LiquiBase in your project.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   167
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   168
Alternatively that file may be registered via ``<include file="..."/>`` syntax.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   169
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   170
After that staying in project at ``schema_v1.1`` state you may upgrade from
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   171
``schema_v1.1`` to ``schema_v2.0`` schema by::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   172
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   173
  $ mvn liquibase:update
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   174
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   175
Or create, review and apply SQL upgrade script (for your DBA)::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   176
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   177
  $ mvn liquibase:updateSQL
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   178
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   179
TODO:
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   180
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   181
  $ mvn liquibase:update -Dliquibase.changesToApply=1
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   182
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   183
Generating difference between database and JPA.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   184
===============================================
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   185
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   186
LiquiBase come with plug-in which mimics like SQL driver. So we may run::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   187
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   188
  $ mvn liquibase:diff
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   189
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   190
to get difference in LiquiBase XML format between our current database and JPA
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   191
schema description.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   192
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   193
With::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   194
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   195
  $ mvn liquibase:updateSQL
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   196
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   197
we get SQL update code to state that described by Hibernate.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   198
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   199
Depending on Hibernate metadata form we shoud adapt ``referenceUrl`` property.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   200
For example for Spring enabled project with JPA annotations::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   201
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   202
  <referenceUrl>hibernate:spring:com.app.domain?dialect=org.hibernate.dialect.MySQLDialect</referenceUrl>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   203
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   204
Here ``com.app.domain`` represent package with JPA annotated entities.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   205
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   206
So complete reference visit:
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   207
https://github.com/liquibase/liquibase-hibernate/wiki
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   208
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   209
Also we need Spring Beans and LiquiBase driver in classpath to resolve
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   210
dependencies during diff calculation. Complete Maven piece look like::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   211
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   212
  <plugin>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   213
      <groupId>org.liquibase</groupId>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   214
      <artifactId>liquibase-maven-plugin</artifactId>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   215
      <version>${liquibase.version}</version>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   216
      <configuration>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   217
          <changeLogFile>${basedir}/src/main/resources/sql/master.xml</changeLogFile>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   218
          <propertyFile>${liquibase.profile}</propertyFile>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   219
          <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   220
          <logging>info</logging>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   221
          <driver>com.mysql.jdbc.Driver</driver>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   222
          <defaultSchemaName>app</defaultSchemaName>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   223
          <changelogSchemaName>app</changelogSchemaName>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   224
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   225
          <!-- For mvn liquibase:updateSQL -->
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   226
          <migrationSqlOutputFile>migration.sql</migrationSqlOutputFile>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   227
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   228
          <referenceUrl>hibernate:spring:com.app.domain?dialect=org.hibernate.dialect.MySQLDialect</referenceUrl>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   229
          <diffChangeLogFile>changelogDiff.xml</diffChangeLogFile>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   230
          <diffTypes>tables,views,columns,indexes,foreignkeys,primarykeys,uniqueconstraints</diffTypes>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   231
      </configuration>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   232
      <dependencies>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   233
          <dependency>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   234
              <groupId>org.springframework.data</groupId>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   235
              <artifactId>spring-data-jpa</artifactId>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   236
              <version>${spring-data.version}</version>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   237
          </dependency>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   238
          <dependency>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   239
              <groupId>org.liquibase.ext</groupId>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   240
              <artifactId>liquibase-hibernate4.2</artifactId>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   241
              <version>3.5</version>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   242
          </dependency>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   243
      </dependencies>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   244
  </plugin>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   245
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   246
http://stackoverflow.com/questions/27877154/liquibase-and-jpa-annotated-entities
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   247
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   248
http://www.baeldung.com/liquibase-refactor-schema-of-java-app
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   249
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   250
How changelogs are identified.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   251
==============================
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   252
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   253
Upstream deside use three field to identify changeset:
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   254
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   255
 * each changeset mandatory marked by pair of ``user:id`` (which is actually any
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   256
   non-whitespace characters)
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   257
 * full path to file with changeset
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   258
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   259
``user:id`` is actually any non-whitespace and non-colon text with
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   260
non-whitespace text. Upstream suggest to use changeset authro identity for
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   261
``user`` and numbers or reason/name for changeset for ``id``.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   262
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   263
``user:id`` pair should be unique for file.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   264
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   265
Reason to capture full path as part of identifier is very dumb. Upstream
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   266
arguments:
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   267
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   268
 * http://forum.liquibase.org/topic/why-does-the-change-log-contain-the-file-name
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   269
 * http://forum.liquibase.org/topic/i-need-to-ignore-the-filename-in-the-processing-to-see-if-a-change-set-has-already-been-applied
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   270
 * http://forum.liquibase.org/topic/logical-filepath-in-change-sets-and-changelog
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   271
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   272
is very Java centric and require sticking to fixed changeset file location in
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   273
``CLASSPATH``.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   274
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   275
When you work with same file on different hosts / tools you should very
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   276
carefully check that path satisfy conventions that used with previous LiquiBase
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   277
work for concrete DB.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   278
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   279
I have incompatibilities between String integration and Maven plug-in. Because I
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   280
use full path in Maven and CLASSPATH relative in String.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   281
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   282
Hopefully there is logicalFilePath attribute.
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   283
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   284
In XML syntax in may be applied to top level tag::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   285
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   286
  <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   287
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   288
                     xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd"
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   289
                     logicalFilePath="legacy.xml">
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   290
      ...
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   291
  </databaseChangeLog>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   292
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   293
or may be overridden by each changeset::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   294
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   295
  <changeSet author="admin" id="fix-25" logicalFilePath="fix.xml">
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   296
     ...
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   297
  </changeSet>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   298
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   299
SQL syntax also have ``logicalFilePath`` attribute for top level file mark
1842
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   300
(implemented in v3.3)::
1840
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   301
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   302
    --liquibase formatted sql  logicalFilePath:legacy.sql
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   303
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   304
and may be overridden by each changeset::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   305
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   306
    --changeset legacy:1  logicalFilePath:other.sql
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   307
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   308
To verify that settings have effect run::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   309
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   310
  mvn liquibase:changelogSyncSQL
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   311
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   312
and review migration.sql. Corresponding ``pom.xml`` part::
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   313
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   314
  <plugin>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   315
      <groupId>org.liquibase</groupId>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   316
      <artifactId>liquibase-maven-plugin</artifactId>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   317
      <version>${liquibase.version}</version>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   318
      <configuration>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   319
          <changeLogFile>${basedir}/src/main/resources/sql/master.xml</changeLogFile>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   320
          <propertyFile>${liquibase.profile}</propertyFile>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   321
          <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   322
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   323
          <migrationSqlOutputFile>migration.sql</migrationSqlOutputFile>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   324
      </configuration>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   325
  </plugin>
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   326
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   327
..
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   328
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   329
 * http://stackoverflow.com/questions/19896436/how-to-configure-liquibase-not-to-include-file-path-or-name-for-calculating-chec
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   330
 * http://stackoverflow.com/questions/19959755/liquibase-how-to-disable-filename-column-check
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   331
 * http://stackoverflow.com/questions/18767815/refactoring-liquibase-changelog-files
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   332
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   333
Consult
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   334
``liquibase-core/src/main/java/liquibase/parser/core/formattedsql/FormattedSqlChangeLogParser.java``
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   335
for further info .
da2130eaa115 How changelogs are identified.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1838
diff changeset
   336
1842
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   337
Split changesets into files.
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   338
============================
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   339
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   340
It is not possible to split file formatted in SQL LiquiBase syntax.
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   341
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   342
It is not possible to set tag with SQL LiquiBase syntax. To workaround this
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   343
issue you may split SQL file and set tags in XML sytax::
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   344
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   345
    <changeSet author="master" id="1">
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   346
        <tagDatabase tag="v0.1"/>
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   347
    </changeSet>
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   348
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   349
    <include file="legacy.sql" relativeToChangelogFile="true"/>
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   350
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   351
    <changeSet author="master" id="2">
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   352
        <tagDatabase tag="v1.0"/>
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   353
    </changeSet>
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   354
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   355
    <include file="v1.0.sql" relativeToChangelogFile="true"/>
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   356
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   357
Also you should be interested in storing stored procedures in separate file and
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   358
apply ``runOnChange`` attribure for XML syntax::
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   359
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   360
    <changeSet author="admin" id="proc-hello">
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   361
        <createProcedure
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   362
                runOnChange="true"
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   363
                encoding="utf8"
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   364
                dbms="oracle">
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   365
            CREATE OR REPLACE PROCEDURE hello AS
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   366
            BEGIN
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   367
              DBMS_OUTPUT.PUT_LINE('Hello');
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   368
            END;
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   369
        </createProcedure>
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   370
    </changeSet>
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   371
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   372
or  with SQL syntax::
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   373
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   374
    --changeset admin:proc-hello  runOnChange:true
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   375
    CREATE OR REPLACE PROCEDURE hello AS
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   376
    BEGIN
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   377
      DBMS_OUTPUT.PUT_LINE('Hello');
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   378
    END;
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   379
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   380
Some people suggest to use one file per stored procedure / package.
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   381
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   382
How big chould be changeset?
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   383
============================
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   384
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   385
Less is better.
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   386
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   387
Some databases doesn't support transactional DDL (e.g. Oracle, SQL Server), each
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   388
DDL statement should be put into a single changeset.
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   389
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   390
Putting unrelated operations into single changeset leads to trouble when last or
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   391
intermediate of them fail to apply.
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   392
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   393
Try to group constraint adding in corresponding update statements. If you have
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   394
wrong update that doesn't prepare data to constraint it shouldn't be commited
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   395
but rewritten.
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   396
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   397
 * http://blog.mgm-tp.com/2010/11/data-modeling-part2/
e66fcbaf99fa Split changesets into files. How big chould be changeset?
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1840
diff changeset
   398