Back to Flyway

Snapshot

documentation/Reference/Commands/Snapshot.md

latest7.4 KB
Original Source

Description

{% include enterprise.html %}

Generates a snapshot from a database environment, build environment, schema snapshot folder or empty source. A snapshot captures the schema of a specified source into a file for subsequent use with the Check Changes command, Check Drift command, Snapshot command or [Snapshot provisioner](Configuration/Environments Namespace/Environment Provisioner Setting/Snapshot Provisioner).

Be sure to set environment schemas when generating a snapshot for Oracle databases.

Snapshots may be stored in the snapshot history table by specifying an appropriate location using the filename parameter. In this case, Flyway will create the snapshot history table automatically if it doesn't exist.

See Snapshots for more information.

Usage examples

Generating a snapshot from a database URL

bash
flyway snapshot -url=jdbc:sqlserver://localhost:1433;encrypt=false;databaseName=Inventory -user=sa -password=... -filename=C:\snapshot.json

Generating a snapshot from a database environment

if a database environment named dev is configured in the flyway.toml file, then the environment name can be provided as a CLI argument instead of passing the connection details as CLI arguments.

bash
flyway snapshot -source=dev -filename=C:\snapshot.json

Generating a snapshot from a schema snapshot folder

bash
flyway snapshot -source=schemaSnapshot -filename=C:\snapshot.json

Generating a snapshot using the build database

bash
flyway snapshot -source=migrations -buildEnvironment=shadow -buildVersion=2 -filename=C:\snapshot.json

The snapshot.build* arguments make it possible to create a snapshot for any migration version.

Parameters

Required

ParameterNamespaceDescription
filenamesnapshotDestination location for the snapshot. Can be a file path, or a snapshot history table entry.

Optional

ParameterNamespaceDescription
sourcesnapshotThe source from which a snapshot should be generated.
historyTablesnapshotThe name of the Flyway snapshot history database table, in which to store snapshots.
historyLimitsnapshotThe maximum number of snapshots to store in the database table.
buildEnvironmentsnapshotIf source is migrations, this specifies the environment to use as the build environment.
buildVersionsnapshotIf source is migrations, this specifies migration version to migrate the build environment to.
buildCherryPicksnapshotIf source is migrations, this specifies list of migrations to migrate the build environment with.
rebuildsnapshotIf source is migrations, forces a reprovision (rebuild) of the build environment.
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.
{environment parameters}(root)Environment configuration for the source environment.

Universal commandline parameters are listed here.

Settings from the following sections of the Flyway namespace can be specified in relation to database connections:

  • General settings
  • Settings in database-specific namespaces
  • Settings in secrets management namespaces

When the source is migrations, settings from the following sections of the Flyway namespace can also be set:

  • Migration location and naming settings
  • Migration reading settings
  • Migration execution settings
  • Flyway schema history settings
  • Placeholders

JSON output format

json
{
  "filename": "C:\snapshot.json"
}

Error codes

This command can produce the following error codes:

Database Binary size limits

When storing snapshots to the Flyway Snapshot History Table, there is a size constraint. The snapshots will be compressed before insertion into the table, so the constraint only applies after compression.

DatabaseDatatypeSize
SQL ServerVARBINARY(MAX)2Gb
OracleBLOB4Gb
MySQLLONGBLOB2Gb
PostgreSQLBYTEA1Gb