Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/gabrielfalcao/simple-db-mig…
Browse files Browse the repository at this point in the history
…rate into dev
  • Loading branch information
guilhermechapiewski committed Apr 30, 2009
2 parents 373c13d + 29be5b7 commit 35b1ee3
Show file tree
Hide file tree
Showing 24 changed files with 25 additions and 25 deletions.
Empty file modified .gitignore 100644 → 100755
Empty file.
Empty file modified LICENSE.txt 100644 → 100755
Empty file.
Empty file modified Makefile 100644 → 100755
Empty file.
Empty file modified NOTICE.txt 100644 → 100755
Empty file.
Empty file modified README.textile 100644 → 100755
Empty file.
Empty file modified example/20090123195634_create_table_users.migration 100644 → 100755
Empty file.
Empty file modified example/20090211120001_add_user_age.migration 100644 → 100755
Empty file.
Empty file modified example/20090211120002_add_user_mother_age.migration 100644 → 100755
Empty file.
Empty file modified example/20090211120003_create_table_chimps.migration 100644 → 100755
Empty file.
Empty file modified example/20090228235709_create_table_aleatory.migration 100644 → 100755
Empty file.
Empty file modified example/simple-db-migrate.conf 100644 → 100755
Empty file.
Empty file modified setup.py 100644 → 100755
Empty file.
Empty file modified src/simple_db_migrate/__init__.py 100644 → 100755
Empty file.
Empty file modified src/simple_db_migrate/cli.py 100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion src/simple_db_migrate/core.py 100644 → 100755
Expand Up @@ -5,7 +5,7 @@
import re

#TODO: Refactor: rename to "Migrations"
class SimpleDBMigrate(object):
class Migrations(object):

__migration_files_extension = ".migration"

Expand Down
Empty file modified src/simple_db_migrate/helpers.py 100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions src/simple_db_migrate/main.py 100644 → 100755
@@ -1,5 +1,5 @@
from cli import CLI
from core import SimpleDBMigrate
from core import Migrations
from helpers import Lists
from mysql import MySQL
import sys
Expand All @@ -17,7 +17,7 @@ def __init__(self, options=None, args=None, mysql=None, db_migrate=None):

self.__db_migrate = db_migrate
if self.__db_migrate is None:
self.__db_migrate = SimpleDBMigrate(self.__options.migrations_dir)
self.__db_migrate = Migrations(self.__options.migrations_dir)

def execute(self):
self.__cli.msg("\nStarting DB migration...")
Expand Down
2 changes: 1 addition & 1 deletion src/simple_db_migrate/mysql.py 100644 → 100755
Expand Up @@ -56,7 +56,7 @@ def __execute(self, sql):
def _drop_database(self):
db = self.__mysql_connect(False)
try:
db.query("drop database %s;" % self.__mysql_db)
db.query("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
Empty file modified tests/cli_test.py 100644 → 100755
Empty file.
38 changes: 19 additions & 19 deletions tests/core_test.py 100644 → 100755
Expand Up @@ -4,7 +4,7 @@
import os
import unittest

class SimpleDBMigrateTest(unittest.TestCase):
class MigrationsTest(unittest.TestCase):

def __create_empty_file(self, file_name):
f = open(file_name, "w")
Expand Down Expand Up @@ -63,20 +63,20 @@ def tearDown(self):
# eventually the tests that fail leave some garbage behind
# this is to clean up the mess
try:
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")
for each_file in db_migrate.get_all_migration_files():
os.remove(each_file)
except:
pass

def test_it_should_get_all_migration_files_in_dir(self):
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")
migration_files = db_migrate.get_all_migration_files()
for each_file in migration_files:
self.assertTrue(each_file in self.__test_migration_files)

def test_it_should_get_only_valid_migration_files_in_dir(self):
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")
migration_files = db_migrate.get_all_migration_files()

for file_name in self.__test_migration_files:
Expand All @@ -86,7 +86,7 @@ def test_it_should_get_only_valid_migration_files_in_dir(self):
self.assertFalse(bad_file_name in migration_files)

def test_it_should_get_all_migration_versions_available(self):
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")
migration_files = db_migrate.get_all_migration_files()
expected_versions = []
for each_file in migration_files:
Expand All @@ -97,25 +97,25 @@ def test_it_should_get_all_migration_versions_available(self):
self.assertTrue(each_version_got in expected_versions)

def test_it_should_get_all_migration_versions_up_to_a_version(self):
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")
migration_files = db_migrate.get_all_migration_versions_up_to("20090214115200")
self.assertEquals(len(migration_files), 1)
self.assertEquals(migration_files[0], "20090214115100")

def test_it_should_get_migration_up_command_in_file(self):
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")
migration_file = "20090214120600_example_migration_file_with_commands.migration"
sql = db_migrate.get_sql_command(migration_file, True)
self.assertEquals(sql, "create table test;")

def test_it_should_get_migration_down_command_in_file(self):
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")
migration_file = "20090214120600_example_migration_file_with_commands.migration"
sql = db_migrate.get_sql_command(migration_file, False)
self.assertEquals(sql, "drop table test;")

def test_it_should_not_get_migration_command_in_files_with_blank_commands(self):
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")
migration_file = "20090214120700_example_migration_file_without_commands.migration"
try:
sql = db_migrate.get_sql_command(migration_file, True)
Expand All @@ -124,7 +124,7 @@ def test_it_should_not_get_migration_command_in_files_with_blank_commands(self):
pass

def test_it_should_not_get_migration_command_in_empty_file(self):
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")
migration_file = self.__test_migration_files[0]
try:
sql = db_migrate.get_sql_command(migration_file, True)
Expand All @@ -135,7 +135,7 @@ def test_it_should_not_get_migration_command_in_empty_file(self):
pass

def test_it_should_get_migration_version_from_file(self):
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")
# good file name
example_file_name = "20090214120600_example_migration_file_name.migration"
version = db_migrate.get_migration_version(example_file_name)
Expand All @@ -146,17 +146,17 @@ def test_it_should_get_migration_version_from_file(self):
self.assertEquals(version, "2009021401")

def test_it_should_check_if_schema_version_exists_in_files(self):
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")
exists = db_migrate.check_if_version_exists("20090214115100")
self.assertTrue(exists)

def test_it_should_get_the_latest_schema_version_available(self):
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")
latest_version = db_migrate.latest_schema_version_available()
self.assertEquals(latest_version, "21420101000000")

def test_it_should_validate_file_name_format_mask(self):
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")

for file_name in self.__test_migration_files:
self.assertTrue(db_migrate.is_file_name_valid(file_name))
Expand All @@ -165,12 +165,12 @@ def test_it_should_validate_file_name_format_mask(self):
self.assertFalse(db_migrate.is_file_name_valid(bad_file_name))

def test_it_should_not_validate_gedit_swap_files(self):
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")
invalid_file_name = "%s~" % self.__test_migration_files[0]
self.assertFalse(db_migrate.is_file_name_valid(invalid_file_name))

def test_it_should_create_migration_file(self):
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")
new_migration_file_name = db_migrate.create_migration("create_a_migration_file")

self.assertTrue(db_migrate.is_file_name_valid(new_migration_file_name))
Expand All @@ -180,20 +180,20 @@ def test_it_should_create_migration_file(self):
self.__test_migration_files.append(new_migration_file_name)

def test_it_should_not_create_migration_file_with_bad_name(self):
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")
try:
db_migrate.create_migration("INVALID FILE NAME")
self.fail("it should not pass here")
except:
pass

def test_it_should_get_migration_file_from_version_number(self):
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")
migration_file_name = db_migrate.get_migration_file_name_from_version_number("20090214115100")
self.assertEquals(migration_file_name, "20090214115100_example_migration_file1.migration")

def test_it_should_get_none_migration_file_from_invalid_version_number(self):
db_migrate = SimpleDBMigrate(".")
db_migrate = Migrations(".")
migration_file_name = db_migrate.get_migration_file_name_from_version_number("***invalid***")
self.assertTrue(migration_file_name is None)

Expand Down
Empty file modified tests/helpers_test.py 100644 → 100755
Empty file.
Empty file modified tests/main_test.py 100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion tests/mysql_test.py 100644 → 100755
Expand Up @@ -61,7 +61,7 @@ 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 migration_test;"))
db_mock.expects(once()).method("query").query(eq("drop database if exists migration_test;"))
db_mock.expects(once()).method("close")

mysql = MySQL(db_config_file="test.conf", mysql_driver=mysql_driver_mock, drop_db_first=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/test.py 100644 → 100755
Expand Up @@ -22,7 +22,7 @@
test_suites.append(unittest.TestLoader().loadTestsFromTestCase(ListsTest))
test_suites.append(unittest.TestLoader().loadTestsFromTestCase(MainTest))
test_suites.append(unittest.TestLoader().loadTestsFromTestCase(MySQLTest))
test_suites.append(unittest.TestLoader().loadTestsFromTestCase(SimpleDBMigrateTest))
test_suites.append(unittest.TestLoader().loadTestsFromTestCase(MigrationsTest))

alltests = unittest.TestSuite(test_suites)

Expand Down

0 comments on commit 35b1ee3

Please sign in to comment.