Skip to content

Commit

Permalink
#47: Corrected bug in --drop option. A MySQL 'bug' did not allow data…
Browse files Browse the repository at this point in the history
…bases to be dropped unless constraints were disabled.
  • Loading branch information
guilhermechapiewski committed Jun 16, 2009
1 parent 949c2a5 commit e4e7b00
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/simple_db_migrate/mysql.py
Expand Up @@ -50,7 +50,7 @@ def __execute(self, sql):
def _drop_database(self):
db = self.__mysql_connect(False)
try:
db.query("drop database if exists %s;" % self.__mysql_db)
db.query("set foreign_key_checks=0; drop database if exists %s;" % self.__mysql_db)
except Exception, e:
self.__cli.error_and_exit("can't drop database '%s'; database doesn't exist" % self.__mysql_db)
db.close()
Expand Down
7 changes: 5 additions & 2 deletions tests/mysql_test.py
Expand Up @@ -73,10 +73,13 @@ def test_it_should_drop_database_on_init_if_its_asked(self):

self.__mock_db_init(mysql_driver_mock, db_mock, cursor_mock)

db_mock.expects(once()).method("query").query(eq("drop database if exists migration_test;"))
db_mock.expects(once()).method("query").query(eq("set foreign_key_checks=0; drop database if exists migration_test;"))
db_mock.expects(once()).method("close")

mysql = MySQL(self.__config, mysql_driver=mysql_driver_mock)
config = Config("test.conf")
config.put("drop_db_first", True)

mysql = MySQL(config, mysql_driver=mysql_driver_mock)

def test_it_should_execute_migration_up_and_update_schema_version(self):
mysql_driver_mock = Mock()
Expand Down

0 comments on commit e4e7b00

Please sign in to comment.