Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There should be a way to apply automated database migrations #21

Closed
kmanning opened this issue Sep 3, 2019 · 3 comments · Fixed by #358
Closed

There should be a way to apply automated database migrations #21

kmanning opened this issue Sep 3, 2019 · 3 comments · Fixed by #358
Milestone

Comments

@kmanning
Copy link
Collaborator

kmanning commented Sep 3, 2019

  • It seems like it would make sense for migrations to live in the database pipeline (migrations = schema changes)
  • If the above statement is true, it seems like there should be a way to include such a step in the TerraformEnvironmentStage
  • I don't think we should dictate what tools are used to handle migration. Some options:
  • Just like everything else is intended to be pluggable, it seems like the migration stage should be pluggable with various implementations. And maybe we offer a few default implementations (java/ruby), while still allowing someone to specify their own implementation.
@kmanning kmanning changed the title There should be a way to apply automated migrations There should be a way to apply automated database migrations Mar 8, 2021
@kmanning kmanning added this to the v5.16 milestone Mar 8, 2021
@kmanning
Copy link
Collaborator Author

kmanning commented Mar 30, 2021

Example code:

  • Assumption, flyway commands are available on your jenkins node
  • Network and security connectivity are already available between jenkins node and database.
  • Pre-defined variables containing username/passwords that can run migrations (variable names can be overridden)
  • Pre-defined location containing migration scripts (can be overridden)
@Library(['terraform-pipeline']) _
Jenkinsfile.init(this, Customizations)
FlywayMigrationPlugin.init()

def validate = new TerraformValidateStage()
// For each environment
//     During plan, flyway will run dryrun and display output
//     During apply, flyway will execute migration after successful apply
def deployQa = new TerraformEnvironmentStage('qa')
def deployUat = new TerraformEnvironmentStage('uat')
def deployProd = new TerraformEnvironmentStage('prod')

validate.then(deployQa)
        .then(deployUat)
        .then(deployProd)
        .build()

@kmanning
Copy link
Collaborator Author

kmanning commented Apr 5, 2021

Dryrun is only available for Teams edition (paid). Consider the ability to run dryrun or info, since info is available in Teams (paid) and Community (free) editions.

@kmanning
Copy link
Collaborator Author

kmanning commented Apr 5, 2021

Cut a number of separate issues to iterate on this workflow:

  1. Optionally disable echo on the flyway commands (to prevent username/password from being displayed) - See Issue FlywayMigrationPlugin: Optionally disable echo for CLI #363
  2. Allow username/password to be configured as a CLI command (after allowing for echo to be disabled) - See Issue FlywayMigrationPlugin: Allow username/password to be configured as CLI parameters #365
  3. If a pending migration is detected, prompt the user before applying, "There are pending migrations - do you want to apply them?" <-- this is to prevent accidental changes - See FlywayPlugin: Prompt the user *again* before applying migration #368
  4. Optionally create a snapshot before applying migration - See FlywayMigrationPlugin: optionally take a snapshot before applying a migration #369
  5. If a migration fails, prompt the user to restore the backup. (This might be really trick, and unfeasible)
  6. If a previously failed migration is detected, prompt the user to run flyway repair
  7. If a previously failed migration is detected, optionally fail the pipeline on plan.
  8. Figure out a workflow for flyway baseline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant