Giter Site home page Giter Site logo

msoftware / liquibase-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from inkimar/liquibase-example

0.0 3.0 0.0 0 B

This project is a simple demonstration of how to use liquibase ( http://www.liquibase.org/ ) together with maven.

License: Creative Commons Zero v1.0 Universal

liquibase-example's Introduction

liquibase-example

This project could be a used as

  • a tutorial for learning the basics in liquibase
  • a base for dicussing on how-to-use liquibase in a collaboration development project

This project is a simple example of a liquibase-project with maven ( http://www.liquibase.org/ ).
This liquibase-project is ready to run with MySQL and postgreSQL
Dependencies to mysql- and posrgresql-connectors are found in the maven pom.xml

By stating this is simple example : Not using complex commands, nor using extension

This simple project contains 5 changesets :

  • 4 changesets that 'creates a table'
  • 1 changeset that 'alters a table' by adding a column

#disucssion topic

In a project with multiple developers using a version control system (VCS)

###working as a team

  • Guarantees that all the developers have the same schema on their local computer
    • how : by version controlling the changelog-files
  • Every developer has a unique liquibase.properties-file (contains schema&credentials)
    • how : ignoring the liquibase.properties-file (if using git, update the .gitignore-file)

###updating the schema in a test-environment using a CI-tool

Check if you are able to update your database in your stage/test-enviroment with liquibase.

  1. Create a liquibase-project as a module amongs your other projects.
  2. version control the project.
  3. CI-tool: Run this project as a build-step before the module that depends on the db. 1. obs : credentials are stored in the liquibase.properties-file

#prereq

Database

In this example the database is called 'denmark'.
You have to create the database before running the project

  • see the liquibase.properties-file
    • setting: url=jdbc:mysql://localhost/denmark

Software:

  • java
  • maven
  • a database-engine of choice

#important files for maven.

  • pom.xml
    • db: mysql-connector-java (version '5.1.37')
    • db: postgresql (version '9.1-901-1.jdbc4')
    • liquibase: liquibase-maven-plugin

#Files for the liquibase-project.

Necessary files

  • liquibase.properties
    • contains : driver and url to the database
    • contains : credentials
    • contains : path to the master.xml-file
    • contains : additional such as ; 'verbose = true', 'dropFirst = false'
  • master.xml
    • contains : path to 'db.changelog-x.y.xml' , x.y are version-nr.
  • db.changelog-1.0.xml
    • contains : all of your changesets (note : every changeset has to has a unique id)

You are able to have multiple 'db.changelog-x.y.xml'-files
This project contains 2 files ; db.changelog-1.0.xml and db.changelog-5.0.xml
In this example every file has its responsibility

  • The db.changelog-1.0.xml contains all your changesets,
  • The db.changelog-5.0.xml contains a reference to an .sql-file
    • The default-insert-for-admin_config.sql contains example content.

Other files

The following files are not necessary for the project.
They are just here as a configuration example.

  • liquibase.mysql.properties
  • liquibase.postgresql.properties

Writing changelogs in liquibase

In this example changesets are written in XML
You are not restrained to using XML for changesets.
Other formats are YAML, JSON and SQL
How-To-Documentation

Simple rules

  • You create new changelogs in the changelog-file
  • You do not delete old changelogs
  • Every changelog has a unique id

#How to run the Liquibase-project To run the project
type 'mvn clean install' in the same directory that the pom.xml-file resides

Check your database
The following 5 tables should have been created

  • 3 tables defined in the changelog-files
    • ADMIN_CONFIG
    • IMAGE
    • MEDIA
  • Additional 2 liquibase-tables
    • DATABASECHANGELOG
    • DATABASECHANGELOGLOCK

Additional stuff

Creating db-documentation

command-line tool:

"Using change information stored in the change logs and an existing database, Liquibase can generate database change documentation " How-To-dbdoc

NOTE : 'javadoc'-style documenation is created with this tool

Going from a 'legacy'-database to a changeset-file.

command-line tool:

"When starting to use Liquibase on an existing database, it is often useful, particularly for testing, to have a way to generate the change log to create the current database schema. Liquibase allows you to do this with the “generateChangeLog” command_line command." How-To-Generate_changelogs

"Note that this command currently has some limitations. It does not export the following types of objects: Stored procedures, functions, packages,Triggers"

liquibase-example's People

Contributors

inkimar avatar

Watchers

Michael jentsch avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.