Beispiel #1
0
    def test_run_migration_downgrade(self):
        repo = FileRepository('repository', 'app2')
        self.sqlupdater.migration = repo.get_migration(
            version_from=StepVersion('4.10.0'),
            version_to=StepVersion('4.0.1'))

        self.sqlupdater.run_migration()

        self.assertEqual(self.sqlupdater.output_sql, (
            "BEGIN;\n"
            "DROP INDEX test_first_idx;\n"
            "INSERT INTO public.dbupgrade_history (application,version) VALUES ('app2','4.10.0');\n"
            "DROP TABLE test_second;\n"
            "INSERT INTO public.dbupgrade_history (application,version) VALUES ('app2','4.5.0');\n"
            "DROP TABLE test_first;\n"
            "INSERT INTO public.dbupgrade_history (application,version) VALUES ('app2','4.0.1.2');\n"
            "COMMIT;\n"))
Beispiel #2
0
    def test_run_migration_upgrade(self):
        repo = FileRepository('repository', 'app2')
        self.sqlupdater.migration = repo.get_migration(
            version_from=StepVersion('4.0.1'),
            version_to=StepVersion('4.10.0'))

        self.sqlupdater.run_migration()

        self.assertEqual(
            self.sqlupdater.output_sql, "BEGIN;\n"
            "CREATE TABLE test_first (a INTEGER, b VARCHAR);\n"
            "INSERT INTO public.dbupgrade_history (application,version) VALUES ('app2','4.0.1.2');\n"
            "CREATE TABLE test_second (a INTEGER, b VARCHAR);\n"
            "INSERT INTO public.dbupgrade_history (application,version) VALUES ('app2','4.5.0');\n"
            "CREATE INDEX test_first_idx ON test_first (b);\n"
            "INSERT INTO public.dbupgrade_history (application,version) VALUES ('app2','4.10.0');\n"
            "COMMIT;\n")
Beispiel #3
0
    def test_run_migration_upgrade(self):
        repo = FileRepository('repository', 'app2')
        self.sqlupdater.migration = repo.get_migration(
            version_from=StepVersion('4.0.1'),
            version_to=StepVersion('4.10.0'))

        self.sqlupdater.run_migration()

        self.sqlupdater.migration = repo.get_migration(
            version_from=StepVersion('4.10.0'),
            version_to=StepVersion('4.0.1'))

        self.sqlupdater.run_migration()

        self.assertEqual(self.sqlupdater.schema_dump(),
                         ('BEGIN TRANSACTION;\n'
                          'CREATE TABLE dbupgrade_history (\n'
                          '    application  VARCHAR(90) NOT NULL,\n'
                          '    version VARCHAR(90) NOT NULL,\n'
                          '    timestamp DATE NOT NULL DEFAULT CURRENT_DATE\n'
                          ');\n'
                          'COMMIT;\n'))
    def test_run_migration_upgrade(self):
        repo = FileRepository('repository', 'app2')
        self.sqlupdater.migration = repo.get_migration(version_from=StepVersion('4.0.1'),
                                                       version_to=StepVersion('4.10.0'))

        self.sqlupdater.run_migration()

        self.assertEqual(
            self.sqlupdater.output_sql,
            "BEGIN;\n"

            "CREATE TABLE test_first (a INTEGER, b VARCHAR);\n"
            "INSERT INTO public.dbupgrade_history (application,version) VALUES ('app2','4.0.1.2');\n"

            "CREATE TABLE test_second (a INTEGER, b VARCHAR);\n"
            "INSERT INTO public.dbupgrade_history (application,version) VALUES ('app2','4.5.0');\n"

            "CREATE INDEX test_first_idx ON test_first (b);\n"
            "INSERT INTO public.dbupgrade_history (application,version) VALUES ('app2','4.10.0');\n"

            "COMMIT;\n"
        )
    def test_run_migration_downgrade(self):
        repo = FileRepository('repository', 'app2')
        self.sqlupdater.migration = repo.get_migration(version_from=StepVersion('4.10.0'),
                                                       version_to=StepVersion('4.0.1'))

        self.sqlupdater.run_migration()

        self.assertEqual(
            self.sqlupdater.output_sql,
            (
                "BEGIN;\n"

                "DROP INDEX test_first_idx;\n"
                "INSERT INTO public.dbupgrade_history (application,version) VALUES ('app2','4.10.0');\n"

                "DROP TABLE test_second;\n"
                "INSERT INTO public.dbupgrade_history (application,version) VALUES ('app2','4.5.0');\n"

                "DROP TABLE test_first;\n"
                "INSERT INTO public.dbupgrade_history (application,version) VALUES ('app2','4.0.1.2');\n"

                "COMMIT;\n"
            )
        )
    def test_run_migration_upgrade(self):
        repo = FileRepository('repository', 'app2')
        self.sqlupdater.migration = repo.get_migration(version_from=StepVersion('4.0.1'),
                                                       version_to=StepVersion('4.10.0'))

        self.sqlupdater.run_migration()

        self.sqlupdater.migration = repo.get_migration(version_from=StepVersion('4.10.0'),
                                                       version_to=StepVersion('4.0.1'))

        self.sqlupdater.run_migration()

        self.assertEqual(
            self.sqlupdater.schema_dump(),
            (
                'BEGIN TRANSACTION;\n'
                'CREATE TABLE dbupgrade_history (\n'
                '    application  VARCHAR(90) NOT NULL,\n'
                '    version VARCHAR(90) NOT NULL,\n'
                '    timestamp DATE NOT NULL DEFAULT CURRENT_DATE\n'
                ');\n'
                'COMMIT;\n'
            )
        )
Beispiel #7
0
from dbupgrade.repository.file_repository import FileRepository

__author__ = 'vincent'

if __name__ == '__main__':
    repo = FileRepository()

Beispiel #8
0
 def setUp(self):
     self.repo = FileRepository('repository', 'app2')
Beispiel #9
0
class FileRepositoryCase(unittest.TestCase):
    def setUp(self):
        self.repo = FileRepository('repository', 'app2')

    def test_list_applications(self):
        apps = FileRepository.list_applications('repository')
        self.assertEqual(['app1', 'app2'], apps)

    def test_list_versions(self):
        assert_versions = [
            StepVersion('4.0.1'),
            StepVersion('4.0.1.2'),
            StepVersion('4.5.0'),
            StepVersion('4.10.0'),
        ]
        versions = self.repo.list_versions()

        self.assertEqual(versions, assert_versions)

    def test_path_to_version(self):
        with self.assertRaises(RepositoryException):
            self.repo.path_to_version(version_from=StepVersion('7.0.0'))

        with self.assertRaises(RepositoryException):
            self.repo.path_to_version(version_to=StepVersion('7.0.0'))

        self.assertEqual(
            self.repo.path_to_version(version_from=StepVersion('4.5.0'), version_to=StepVersion('4.5.0')),
            []
        )

        self.assertEqual(
            self.repo.path_to_version(),
            [
                StepVersion('4.0.1'),
                StepVersion('4.0.1.2'),
                StepVersion('4.5.0'),
                StepVersion('4.10.0'),
            ]
        )

        # Upgrade
        self.assertEqual(
            self.repo.path_to_version(version_to=StepVersion('4.5.0')),
            [
                StepVersion('4.0.1'),
                StepVersion('4.0.1.2'),
                StepVersion('4.5.0'),
            ]
        )

        self.assertEqual(
            self.repo.path_to_version(version_from=StepVersion('4.0.1.2')),
            [
                StepVersion('4.5.0'),
                StepVersion('4.10.0'),
            ]
        )

        self.assertEqual(
            self.repo.path_to_version(version_from=StepVersion('4.0.1.2'), version_to=StepVersion('4.5.0')),
            [
                StepVersion('4.5.0'),
            ]
        )

        # Downgrade
        self.assertEqual(
            self.repo.path_to_version(version_from=StepVersion('4.5.0'), version_to=StepVersion('4.0.1.2')),
            [
                StepVersion('4.5.0'),
            ]
        )

        self.assertEqual(
            self.repo.path_to_version(version_from=StepVersion('4.10.0'), version_to=StepVersion('4.0.1')),
            [
                StepVersion('4.10.0'),
                StepVersion('4.5.0'),
                StepVersion('4.0.1.2'),

            ]
        )

    def test_get_migration(self):
        # Upgrade

        steps = self.repo.get_migration(version_from=StepVersion('4.0.1'), version_to=StepVersion('4.10.0'))
        self.assertEquals(steps.content_steps(),
                          (
                              'CREATE TABLE test_first (a INTEGER, b VARCHAR);',
                              'CREATE TABLE test_second (a INTEGER, b VARCHAR);',
                              'CREATE INDEX test_first_idx ON test_first (b);',
                          )
        )

        # Downgrade
        steps = self.repo.get_migration(version_from=StepVersion('4.10.0'), version_to=StepVersion('4.0.1'))
        self.assertEquals(steps.content_steps(),
                          (
                              'DROP INDEX test_first_idx;',
                              'DROP TABLE test_second;',
                              'DROP TABLE test_first;',
                          )
        )
Beispiel #10
0
 def test_list_applications(self):
     apps = FileRepository.list_applications('repository')
     self.assertEqual(['app1', 'app2'], apps)