This workshop is intended to show one more practice for CI and CD, so, this is the chance for learning a new tecnhique for new and legacy systems with a relational database.
- JDK 1.8+
- MySQL 5.5+
- A text editor
Simple!!! Right!!!
- Git for your convenience and control
- Groovy for an optimization
- Gradle 5.x+ for final integration with your systems
- Download liquibase from the website.
- Add to your PATH, wherever you want Güin2, Linux, Mac, but only in the terminal
- Verify your installation:
_> liquibase --version
Starting Liquibase at vie, 12 jun 2020 20:12:54 CDT (version 3.10.0 #10 built at Thu Jun 11 09:47:49 UTC 2020)
Liquibase Version: 3.10.0
Liquibase Community 3.10.0 by Datical
Running Java under /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre (Version 1.8.0_181)
Well, it's easy:
- Create a database
makingdevs_demo_db
mysql -u makingdevs -pmakingdevs -h 0.0.0.0 makingdevs_demo_db < create-schema-mysql.sql
- So we're going to rename a table
- Rename the
inv
table toinvoice
- Rename the
lineitem
table toline_item
- Rename the
lidetail
table toline_item_detail
- Rename some columns in the
invoice
table
- Rename
invid
toid
- Rename
invnumber
toinvoice_number
- Rename
datetimecreated
todate_created
- We're going to combine two columns using data transformation
invoice.udtime
andinvoice.uddate
should be combined intoinvoice.date_updated
- First populate the
date_created
new column with anUPDATE
query that merges theudtime
anduddate
values- HINT:
udtime
+uddate
- HINT:
- What do you think about this refactoring?
- drop or kept them?
- Create tables
contact_ball_of_mud
is too ambitious of a table (or insufficiently coherent). Let's begin splitting it up.- The contact table should contain name fields, gender, email address, street address, birthday, occupation, and national ID
- The security_info table should contain password and mother's maiden name
- The credit_card table should contain credit card type, number, expiration and CVV
- Choice of data type for each column is left as an exercise for the student.
- Don't run this refactoring yet!
- Tagging and rolling back
- Tag the database, then run the table rename refactoring written in the previous step
- Now roll back to continue development on the refactoring
- Finish refactoring of
contact_ball_of_mud
- Write data transformation code to populate the three tables from their source
- Remember that
security_info
andcredit_card
should have foreign keys to contact. Be sure to add these constraints with the appropriate refactorings
- Add a column
- Add a
full_name
column to contact - Write data transformation SQL to populate it with the three existing name fields combined
- HINT:
CONCAT_WS()
- HINT:
- Don't drop of the source name columns.
- Create a trigger
- Create a file called contact_insert.sql
- Write trigger logic to keep
full_name
up to date with the fields for first name, middle initial, and last name every time a new record is inserted
- Write trigger logic to keep
- Create a file called contact_update.sql
- Same logic as the insert trigger
- Write changeSets that use the sqlFile refactoring to install these triggers.
- Remember the runOnChange attribute.
- HINT: be sure the changeSet is idempotent!
- Use gradle, this is the thing that you should to do...
- Restart the steps but now with gradle
- Use the Groovy DSL for the new migrations
- Introduce surrogate key
- Add an auto-incrementing column to line_item called id.
- Add a primary key constraint on id.