def test_db_sync_sanity_called(self):
        with contextlib.nested(
            mock.patch.object(migration, '_find_migrate_repo'),
            mock.patch.object(migration, '_db_schema_sanity_check'),
            mock.patch.object(versioning_api, 'downgrade')
        ) as (mock_find_repo, mock_sanity, mock_downgrade):

            mock_find_repo.return_value = self.return_value
            migration.db_sync(self.engine, self.path, self.test_version)

            mock_sanity.assert_called_once()
    def test_db_sync_downgrade(self):
        with contextlib.nested(
            mock.patch.object(migration, '_find_migrate_repo'),
            mock.patch.object(versioning_api, 'downgrade')
        ) as (mock_find_repo, mock_downgrade):

            mock_find_repo.return_value = self.return_value
            self.mock_api_db_version.return_value = self.test_version + 1

            migration.db_sync(self.engine, self.path, self.test_version)

            mock_downgrade.assert_called_once_with(
                self.engine, self.return_value, self.test_version)
    def test_db_sync_upgrade(self):
        init_ver = 55
        with contextlib.nested(
            mock.patch.object(migration, '_find_migrate_repo'),
            mock.patch.object(versioning_api, 'upgrade')
        ) as (mock_find_repo, mock_upgrade):

            mock_find_repo.return_value = self.return_value
            self.mock_api_db_version.return_value = self.test_version - 1

            migration.db_sync(self.path, self.test_version, init_ver)

            mock_upgrade.assert_called_once_with(
                db_session.get_engine(), self.return_value, self.test_version)
Beispiel #4
0
 def downgrade(self, version):
     try:
         # version for migrate should be valid int - else skip
         if version in ('base', None):
             version = self.init_version
         version = int(version)
         return migration.db_sync(self.engine,
                                  self.repository,
                                  version,
                                  init_version=self.init_version)
     except ValueError:
         LOG.error(
             _LE('Migration number for migrate plugin must be valid '
                 'integer or empty, if you want to downgrade '
                 'to initial state'))
         raise
 def downgrade(self, version):
     try:
         #version for migrate should be valid int - else skip
         if version in ('base', None):
             version = self.init_version
         version = int(version)
         return migration.db_sync(
             self.engine, self.repository, version,
             init_version=self.init_version)
     except ValueError:
         LOG.error(
             _LE('Migration number for migrate plugin must be valid '
                 'integer or empty, if you want to downgrade '
                 'to initial state')
         )
         raise
Beispiel #6
0
 def upgrade(self, version):
     version = None if version == 'head' else version
     return migration.db_sync(self.engine,
                              self.repository,
                              version,
                              init_version=self.init_version)
 def upgrade(self, version):
     version = None if version == 'head' else version
     return migration.db_sync(
         self.engine, self.repository, version,
         init_version=self.init_version)