Back to Flyway

Prepare

documentation/Reference/Commands/Prepare.md

latest16.1 KB
Original Source

{% include enterprise.html %}

The prepare command generates a deployment script from a schemaModel, an environment, a diff artifact, or migrations

Usage examples

Generate a deployment script to update target database based on schema model

flyway prepare -source=schemaModel -target=production -scriptFilename="D__deployment.sql"

[!Important]
When the schemas are different between source and target, make sure to configure schema model schemas. If a target schema does not exist in the schema model, the generated script will contain SQL for deleting the schema.

Generate a deployment script to update target database based on source database

flyway prepare -source=env:dev -target=production -scriptFilename="D__deployment.sql"

Generate a deployment script from a diff artifact

flyway prepare -artifactFilename="myArtifactPath" -changes="-" -scriptFilename="D__deployment.sql"

Generates a deployment script which can be executed against a target database to make it match the target of the original comparison.

The artifact needed for this approach is generated by flyway diff.

This approach allows for programmatic partial selection of changes to deploy.

Generate a deployment script from migrations

flyway prepare -source=migrations -target=production-equivalent -scriptFilename="D__deployment.sql"

Generates a deployment script which can be executed against a target database to deploy all pending migrations.

This is a useful alternative to flyway migrate when you need to deploy to equivalent databases where flyway is not available, or want to review the exact script to be run before execution, but it does come with limitations:

  • This approach does not handle Java migrations or other non-SQL migrations
  • Callbacks are not supported

This is currently functionally equivalent to running a dry run on migrate.

Complete list of parameters for deploying from schema model or source database

Required

ParameterNamespaceDescription
sourceprepareEither schemaModel or a source database (e.g. env:dev) for this workflow.
targetprepareThe target environment to deploy to. This is only required when using a source database.

Optional

ParameterNamespaceDescription
typesprepareA comma separated list of script types to generate.
scriptFilenameprepareThe path to the deployment script that will be generated.
undoFilenameprepareThe path to the undo script that will be generated.
abortOnWarningSeverityprepareWill cause an error to be returned if any warnings of configured severity are raised when generating the deployment script.
forceprepareIf the deployment script already exists, overwrite it.
configFiles(root)The location of the flyway configuration files.
encoding(root)The encoding to use for the generated script.
{environment parameters}(root)Environment configuration for the source and/or target environments.
schemaModelLocation(root)The path to the schema model.
schemaModelSchemas(root)The schemas in the schema model.
workingDirectory(root)The directory to consider the current working directory. All relative paths will be considered relative to this.

Universal commandline parameters are listed here.

Note that comparison options, filters, and static data configuration are all supported, but can currently only be specified within the TOML config file, and can't yet be overridden on the command line

Complete list of options for deploying from artifact

Optional

ParameterNamespaceDescription
artifactFilenameprepareThe path to the diff artifact.
changesprepareA comma separated list of change ids.
typesprepareA comma separated list of script types to generate.
scriptFilenameprepareThe path to the deployment script that will be generated.
undoFilenameprepareThe path to the undo script that will be generated.
configFiles(root)The location of the flyway configuration files.
encoding(root)The encoding to use for the generated script.
workingDirectory(root)The directory to consider the current working directory. All relative paths will be considered relative to this.

Universal commandline parameters are listed here.

Note that comparison options, filters, and static data configuration are all supported, but can currently only be specified within the TOML config file, and can't yet be overridden on the command line

Complete list of options for deploying from migrations

Required

ParameterNamespaceDescription
sourceprepareMust be set to migrations for this workflow.

Optional

ParameterNamespaceDescription
targetprepareThe target environment to deploy to.
scriptFilenameprepareThe path to the deployment script that will be generated.
baselineOnMigrate(root)Whether to generate schema history table as part of the deployment script (required if does not exist in target database).
baselineVersion(root)If baselineOnMigrate is set, specifies the baseline version (only subsequent versioned migrations will be included in deployment).
cherryPick(root)A custom selection of migrations to use for generating the deployment script.
configFiles(root)The location of the flyway configuration files.
defaultSchema(root)The location of the flyway schema history table.
encoding(root)The encoding to use for the generated script.
{environment parameters}(root)Environment configuration for the source and/or target environments.
ignoreMigrationPatterns(root)Pattern for excluding migrations from the deployment script.
locations(root)Locations of the migrations to deploy.
{placeholders}(root)Placeholders in migration scripts to replace with runtime information.
placeholderPrefix(root)Placeholder prefix characters.
placeholderReplacement(root)Whether or not to replace placeholders.
placeholderSeparator(root)Placeholder separator characters.
placeholderSuffix(root)Placeholder suffix characters.
workingDirectory(root)The directory to consider the current working directory. All relative paths will be considered relative to this.

Universal commandline parameters are listed here.

JSON output format

json
{
  "scriptWasGenerated": true,
  "scriptFilename": "C:\\workingDirectory\\D__deployment.sql",
  "differences": [
    {
      "id": "1",
      "from": { "fullyQualifiedName": "[dbo].[Table1]", "schema": "dbo", "name": "Table1" },
      "to": null,
      "differenceType": "Add",
      "objectType": "Table",
      "selectionType": "Selected"
    },
    {
      "id": "2",
      "from": { "fullyQualifiedName": "[dbo].[View1]", "schema": "dbo", "name": "View1" },
      "to": null,
      "differenceType": "Add",
      "objectType": "View",
      "selectionType": "Dependency"
    }
  ],
  "warnings": [
    {
      "type": "WARNING_TYPE",
      "message": "Warning message"
    }
  ]
}

Error codes

This command can produce the following error codes: