documentation/Reference/Commands/Generate.md
{% include enterprise.html %}
Generates a migration script based on the differences from an artifact produced by diff.
The version, description and location of the migration script can be specified or auto-generated by flyway.
Baseline, versioned and undo script types can be generated.
Note:
-generate.types=baseline,versioned or -generate.types=baseline,undo is disallowed and will result in an
error.generate.target must match one of the sources provided as either diff.source or diff.target.See Migrations for more information.
In all examples below the diff command must first be run to find changes to generate scripts from. The result of a
diff operation is stored in the diff artifact. The diff command can be combined with generate into a single flyway
call with verb chaining.
For example, the following command performs a diff and generate between the schema model directory and state
represented by the current project migrations. A shadow database is used as a temporary build environment for the
project migrations:
If the migrations directory has the following contents before running the generate command:
B001__baseline.sql
V002.sql
Then running the generate command will create a new versioned V003.sql migration script:
Leaving the migrations directory with the following contents:
B001__baseline.sql
V002.sql
V003.sql
If the migrations directory has the following contents before running the generate command:
B001__baseline.sql
V002.sql
Then running the following generate command will generate versioned and undo scripts with the specified version and
description:
Leaving the migrations directory with the following contents:
B001__baseline.sql
V002.sql
U003__New-feature.sql
V003__New-feature.sql
In this case the migrations directory will be empty, as the baseline migration is the first script to be generated.
Running the following generate command will generate a baseline script at the specified location:
Leaving the migrations directory with the following contents:
B000__initial_state.sql
If the migrations directory has the following contents before running the generate command:
B001__baseline.sql
V002_20240828161524__New_Feature.sql
Then running the following generate command will generate a corresponding undo script for the V002 migration, but
only containing the changes for the comma separated change Ids specified in the changes.txt file:
Leaving the migrations directory with the following contents:
B001__baseline.sql
U002_20240828161524__New_Feature.sql
V002_20240828161524__New_Feature.sql
| Parameter | Namespace | Description |
|---|---|---|
artifactFilename | generate | The path to the diff artifact. |
changes | generate | A comma separated list of change ids. |
types | generate | A comma separated list of script types to generate. |
location | generate | The location to generate the migration to. |
target | generate | Sets the direction of script generation by stating the target to use. Must match one of diff.source or diff.target from flyway diff. |
version | generate | The version part of the migration name. |
timestamp | generate | Add a timestamp to the calculated version if one is not already present. |
description | generate | The description part of the migration name. |
baselineFilename | generate | The filename (or full path) to use for the generated baseline migration. |
versionedFilename | generate | The filename (or full path) to use for the generated versioned migration. |
undoFilename | generate | The filename (or full path) to use for the generated undo migration. |
force | generate | If the migration script already exists, overwrite it. |
usePlaceholders | generate | Whether to use placeholders in the generated migration script. If set to true, Flyway will attempt to insert placeholders into the 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.
{
"scripts": [
{
"type": "versioned",
"location": "C:\\flywayProejct\\migrations\\V001__AddTable.sql",
"scriptConfigPath": "C:\\flywayProejct\\migrations\\V001__AddTable.sql.conf",
"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"
}
}
],
}
This command can produce the following error codes: