$ mysql -h 127.0.0.1 -uroot -p123456 test -e "show tables;" mysql: [Warning] Using a password on the command line interface can be insecure. +-----------------------+ | Tables_in_test | +-----------------------+ | DATABASECHANGELOG | | DATABASECHANGELOGLOCK | | deparment | +-----------------------+
Standard Commands: rollbackCount <value> Rolls back the last <value> change sets applied to the database
我们来执行rollbackCount进行回滚
1 2 3 4 5
$ liquibase rollbackCount 1 Liquibase Community 3.8.2 by Datical Rolling Back Changeset:myChangeLog.xml::1.0::bohan Unexpected error running Liquibase: No inverse to liquibase.change.core.RawSQLChange created For more information, please use the --logLevel flag
<changeSet id="1.0" author="bohan"> <sql> CREATE TABLE `deparment` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(100) COLLATE utf8mb4_bin DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; </sql> <rollback> DROP TABLE deparment; </rollback> </changeSet> <changeSet id="1.1" author="bohan"> <sql> insert into deparment values(1, "test"); </sql> <rollback> DELETE FROM deparment WHERE id = 1; </rollback> </changeSet> </databaseChangeLog>
执行回滚,发现已经没有新增的记录了
1 2 3 4 5 6
liquibase rollbackCount 1 Liquibase Community 3.8.2 by Datical Rolling Back Changeset:myChangeLog.xml::1.1::bohan Liquibase: Rollback has been successful. $ mysql -h 127.0.0.1 -uroot -p test -e "select * from deparment;" Enter password:
再次执行,数据库也如预期被删除
1 2 3 4 5 6 7 8 9 10 11 12
$ liquibase rollbackCount 1 Liquibase Community 3.8.2 by Datical Rolling Back Changeset:myChangeLog.xml::1.0::bohan Liquibase: Rollback has been successful. $ mysql -h 127.0.0.1 -uroot -p test -e "show tables;" Enter password: +-----------------------+ | Tables_in_test | +-----------------------+ | DATABASECHANGELOG | | DATABASECHANGELOGLOCK | +-----------------------+
Standard Commands: rollback <tag> Rolls back the database to the the state is was Maintenance Commands tag <tag string> 'Tags' the current database state for future rollback tagExists <tag string> Checks whether the given tag is already existing
针对当前数据库,我们通过liquibase tag进行打标签操作
1 2 3 4
$ liquibase tag v1.0 Liquibase Community 3.8.2 by Datical Successfully tagged 'root@172.17.0.1@jdbc:mysql://127.0.0.1/test' Liquibase command 'tag' was executed successfully.
$ liquibase rollback v1.0 Liquibase Community 3.8.2 by Datical Rolling Back Changeset:myChangeLog.xml::1.1::bohan Liquibase: Rollback has been successful.
<details> <summary>Click to open</summary> <p>If your browser supports this element, it should allow you to expand and collapse these details.</p></details>
classStruct: '''The recursive class for building and representing objects with.''' def__init__(self, obj): for k, v in obj.iteritems(): ifisinstance(v, dict): setattr(self, k, Struct(v)) else: setattr(self, k, v) def__getitem__(self, val): return self.__dict__[val] def__repr__(self): return'{%s}' % str(', '.join('%s : %s' % (k, repr(v)) for (k, v) in self.__dict__.iteritems()))
-a, --all=false Show all containers (default shows just running) --before= Show only container created before Id or Name -f, --filter=[] Filter output based on conditions provided --format= Pretty-print containers using a Go template --help=false Print usage -l, --latest=false Show the latest created container, include non-running -n=-1 Show n last created containers, include non-running --no-trunc=false Don't truncate output -q, --quiet=false Only display numeric IDs -s, --size=false Display total file sizes --since= Show created since Id or Name, include non-running