Skip to content

Latest commit

 

History

History
45 lines (30 loc) · 1.8 KB

3.4.md

File metadata and controls

45 lines (30 loc) · 1.8 KB

3.4 How to add a database migration

Similar to configuration, from time to time, the Go database needs to be migrated as well, to accommodate new features or other changes. Go uses DBDeploy to perform this operation.

Explaining by example, I'll take the case of how the database migration 1401001 was added

3.4.1 Introducing a new database migration

As part of 14.1, Go had one database migration to recreate triggers because of a name refactoring that was done. The below file naming scheme is followed for database migrations

<2-digit-major-release-version><2-digit-minor-release-version><3-digit-migration-sequence-number>_<description-of-the-migration>.sql

For example, for the first migration of 14.1 release, the migration was

~/projects/go$ touch ./server/db/migrate/h2deltas/1401001_recreating_trigger_because_of_cruise_to_go_change.sql
  • 2-digit-major-release-version : 14
  • 2-digit-minor-release-version : 01
  • 3-digit-migration-sequence-number: 001
  • description-of-the-migration: recreating_trigger_because_of_cruise_to_go_change

3.4.2 Writing the DML/DDL

Following the DBDeploy semantics, the 1401001 migration was created as

DROP TRIGGER lastTransitionedTimeUpdate;
CREATE TRIGGER lastTransitionedTimeUpdate AFTER INSERT ON buildStateTransitions FOR EACH ROW CALL "com.thoughtworks.go.server.sqlmigration.Migration_230007";

--//@UNDO

DROP TRIGGER lastTransitionedTimeUpdate;
CREATE TRIGGER lastTransitionedTimeUpdate AFTER INSERT ON buildStateTransitions FOR EACH ROW CALL "com.thoughtworks.go.server.sqlmigration.Migration_230007";

If you now run

./bn cruise:prepare

and then bring up a Development Server, you will see that the migration runs.