Command-line - clean
Published 16 November 2022
Command-line: clean
Drops all objects (tables, views, procedures, triggers, ...) in the configured schemas.
The schemas are cleaned in the order specified by the schemas
property. If Flyway automatically created them, then the schemas themselves will be dropped when cleaning.
Usage
> flyway [options] clean
Options
See configuration for a full list of supported configuration parameters.
Sample configuration
flyway.driver=org.hsqldb.jdbcDriver
flyway.url=jdbc:hsqldb:file:/db/flyway_sample
flyway.user=SA
flyway.password=mySecretPwd
flyway.connectRetries=10
flyway.initSql=SET ROLE 'myuser'
flyway.schemas=schema1,schema2,schema3
flyway.callbacks=com.mycomp.project.CustomCallback,com.mycomp.project.AnotherCallback
flyway.skipDefaultCallbacks=false
flyway.cleanDisabled=false
flyway.workingDirectory=C:/myProject
flyway.jdbcProperties.myProperty=value
Sample output
> flyway clean Flyway 10.20.1 by Redgate Cleaned database schema 'PUBLIC' (execution time 00:00.014s)
Sample JSON output
> flyway clean -outputType=json { "schemasCleaned": [ "public" ], "schemasDropped": [], "flywayVersion": "10.20.1", "database": "testdb", "warnings": [], "operation": "clean" }
Limitations
Cleaning additional objects
For complicated database structures an accurate dependency graph cannot always be constructed, so not every object is cleaned. There are also objects that we do not drop as they aren’t always safe to, for example, users in SQL Server. To clean additional objects, you can add an afterClean callback defining drop statements. For example afterClean.sql:
DROP USER test_user