Post on 17-May-2015
description
2. What We'll Cover (and not cover)
3. Why Use Database Change Management 4. Why To Not Use Database Abstraction Layer Migrations
DBDeploy and LiquiBase
5. Basic Syntax 6. Recommended Structure 7. The [Somewhat] Prerequisites
8. You should be using source code management. 9. You already know how you are deploying your code. 10. Why Database Change Management
11. Deltas typically are a part of a code change. 12. Ensures the correlation between code revisions. 13. Allows the automation of changes. 14. Ensure you are keeping environments consistent. 15. Allows for reverting back to previous versions (some voodoo magic may be required). 16. The Traditional Way - #fail
17. Developer forgets to note change on bug tracking ticket or notify anyone of the change or DBA misses the change, etc. 18. Code deployment and database deployment happens. 19. System is broken... #fail 20. Developer attempts to figure out what happened, oops factor. 21. A Better Way
22. Developer tests changes locally. 23. Code and Database Delta is committed against a ticket (or at least together). 24. Pre-Deployment Database Changes are Applied. 25. Code Deployment is pushed out. 26. Post-Deployment Database Changes are Applied. 27. System === happiness. 28. Some ProcessTheory Simplified
29. Essentially, do not break what is already out there. Code Deployment
Database Post-Deployment
30. Database Abstraction Migrations
31. If you change your abstraction layer, you must change your migration logic. 32. Example Case:
33. What about the n+1 machines?! #fail 34. DBDeploy : dbdeploy.com
35. Utilizes SQL delta files. 36. Handles undo within the delta file.
Utilizes different table names to handle different deployments. 37. Queries the database for what has not been applied and generates a SQL file to apply towards the database. 38. DBDeploy : Getting Started
39. Download DBDeploy (Obvious) 40. Download your Java Connector 41. We will be using the command line version (rather than ant for this talk)
42. DBDeploy : Initial Setup
Put the Java Connector somewhere that you can reference it. 43. DBDeploy : The Command Line
44. -d | --dbms Database Type 45. -s | --scriptdirectory 46. -o | --outputfile Output File 47. -u | --url DB URL 48. -U | --userid DB Username 49. -P | --password DB Password 50. -t | --changeLogTableName 51. DBDeploy : Writing a Script
52. You can add a comment on the file name:
Put in your delta, then for handling an undo, put in a comment in the format of:
Save this file to a directory of the type of script:
53. DBDeploy : An Example
54. Let's watch this command, understand the output and look at the script. 55. DBDeploy : The Output dbdeploy 3.0M2 Reading change scripts from directory /home/mwillbanks/presentations/zendcon-uncon-2009-db-deployments/bin/dbdeploy/example... Changes currently applied to database: (none) Scripts available: 1, 2 To be applied: 1, 2 56. DBDeploy : Questions?
57. LiquiBase : liquibase.org
58. Utilizes XML Files for Changesets 59. Handles undo within the changeset. 60. Utilizes a single table with a primary key on the id, author and filename. 61. Queries the database for what has not been applied and applies the different SQL. 62. Very well documented unlike DBDeploy. 63. LiquiBase : Getting Started
64. Download LiquiBase (Obvious) 65. Download your Java Connector 66. We will be using the command line version
67. LiquiBase : Initial Setup
68. That's pretty much all you need initially, besides extracting the tar ball :) 69. LiquiBase : The Command Line
70. rollback to a tag 71. rollbackToDate rollback to a date 72. generateChangeLog useful to create the initial version of the change log. 73. changeLogSync mark all changes as ran. 74. markNextChangeSetRan mark next change as ran. 75. LiquiBase : Generating a Script
Run the command: 76. ./liquibase --driver=com.mysql.jdbc.Driver --changeLogFile=sql/pre.xml --username=uncon2009 --password=****** --url="jdbc:mysql://localhost/uncon2009_db generateChangeLog 77. This saves the file to the area specified. 78. LiquiBase : Writing a Change Log
79. Each change log starts with changeLog: 80. LiquiBase : The Internals
DATABASECHANGELOCK locks to ensure you are not executing the same change sets. 81. LiquiBase : Examples of Migration
82. Running through the post deployment file. 83. LiquiBase : Pre-Deployment File 84. LiquiBase : Post-Deployment File 85. Conclusion
Ensure you can handle pre and post deployments.
Read the manuals of each system
Slides will be posted with examples sometime today.
86. Mike Willbanks Blog:http://blog.digitalstruct.com Twitter : mwillbanks IRC : lubs Talk:http://joind.in/986 Questions?