Esempio n. 1
0
    def setUp(self):
        self.engine1 = _sqlite_file_db(tempname='eng1.db')
        self.engine2 = _sqlite_file_db(tempname='eng2.db')
        self.engine3 = _sqlite_file_db(tempname='eng3.db')

        self.env = staging_env(template="multidb")
        self.cfg = _multidb_testing_config({
            "engine1": self.engine1,
            "engine2": self.engine2,
            "engine3": self.engine3
        })
Esempio n. 2
0
    def setUp(self):
        self.engine1 = _sqlite_file_db(tempname='eng1.db')
        self.engine2 = _sqlite_file_db(tempname='eng2.db')
        self.engine3 = _sqlite_file_db(tempname='eng3.db')

        self.env = staging_env(template="multidb")
        self.cfg = _multidb_testing_config({
            "engine1": self.engine1,
            "engine2": self.engine2,
            "engine3": self.engine3
        })
Esempio n. 3
0
 def setUp(self):
     self.bind = _sqlite_file_db(future=self.future)
     self.env = staging_env(sourceless=self.sourceless)
     self.cfg = _sqlite_testing_config(sourceless=self.sourceless,
                                       future=self.future)
     if self.branched_connection:
         self._branched_connection_env()
Esempio n. 4
0
    def setUp(self):
        self.bind = _sqlite_file_db()
        self.env = staging_env()
        self.cfg = _sqlite_testing_config()
        self.a = a = util.rev_id()
        self.b = b = util.rev_id()
        script = ScriptDirectory.from_config(self.cfg)
        script.generate_revision(a, None, refresh=True)
        write_script(
            script,
            a,
            """
revision = '%s'
down_revision = None
"""
            % a,
        )
        script.generate_revision(b, None, refresh=True)
        write_script(
            script,
            b,
            """
revision = '%s'
down_revision = '%s'
"""
            % (b, a),
        )
Esempio n. 5
0
    def setUp(self):
        self.bind = _sqlite_file_db()
        self.env = staging_env()
        self.cfg = _sqlite_testing_config()
        self.a = a = util.rev_id()
        self.b = b = util.rev_id()
        script = ScriptDirectory.from_config(self.cfg)
        script.generate_revision(a, None, refresh=True)
        write_script(
            script,
            a,
            """
revision = '%s'
down_revision = None
"""
            % a,
        )
        script.generate_revision(b, None, refresh=True)
        write_script(
            script,
            b,
            """
revision = '%s'
down_revision = '%s'
"""
            % (b, a),
        )
Esempio n. 6
0
 def test_pk_constraint_normally_prevents_dupe_rows(self):
     self._env_fixture()
     command.revision(self.cfg)
     r2 = command.revision(self.cfg)
     db = _sqlite_file_db()
     command.upgrade(self.cfg, "head")
     assert_raises(
         sqla_exc.IntegrityError, db.execute,
         "insert into alembic_version values ('%s')" % r2.revision)
Esempio n. 7
0
 def setup_class(cls):
     cls.bind = _sqlite_file_db()
     cls.env = env = staging_env()
     cls.cfg = _sqlite_testing_config()
     cls.a1 = env.generate_revision("a1", "a1")
     cls.a2 = env.generate_revision("a2", "a2")
     cls.a3 = env.generate_revision("a3", "a3")
     cls.b1 = env.generate_revision("b1", "b1", head="base")
     cls.b2 = env.generate_revision("b2", "b2", head="b1", depends_on="a2")
     cls.b3 = env.generate_revision("b3", "b3", head="b2")
Esempio n. 8
0
 def test_pk_constraint_normally_prevents_dupe_rows(self):
     self._env_fixture()
     command.revision(self.cfg)
     r2 = command.revision(self.cfg)
     db = _sqlite_file_db()
     command.upgrade(self.cfg, "head")
     assert_raises(
         sqla_exc.IntegrityError,
         db.execute,
         "insert into alembic_version values ('%s')" % r2.revision,
     )
Esempio n. 9
0
 def test_err_correctly_raised_on_dupe_rows(self):
     self._env_fixture()
     command.revision(self.cfg)
     r2 = command.revision(self.cfg)
     db = _sqlite_file_db()
     command.upgrade(self.cfg, "head")
     db.execute("insert into alembic_version values ('%s')" % r2.revision)
     assert_raises_message(
         util.CommandError,
         "Online migration expected to match one row when "
         "updating .* in 'alembic_version'; 2 found", command.downgrade,
         self.cfg, "-1")
Esempio n. 10
0
 def test_err_correctly_raised_on_dupe_rows(self):
     self._env_fixture()
     command.revision(self.cfg)
     r2 = command.revision(self.cfg)
     db = _sqlite_file_db()
     command.upgrade(self.cfg, "head")
     db.execute("insert into alembic_version values ('%s')" % r2.revision)
     assert_raises_message(
         util.CommandError,
         "Online migration expected to match one row when "
         "updating .* in 'alembic_version'; 2 found",
         command.downgrade, self.cfg, "-1"
     )
Esempio n. 11
0
    def test_stamp_purge(self):
        command.stamp(self.cfg, [self.a])

        eng = _sqlite_file_db()
        with eng.begin() as conn:
            result = conn.execute(
                text("update alembic_version set version_num='fake'"))
            eq_(result.rowcount, 1)

        with capture_engine_context_buffer() as buf:
            command.stamp(self.cfg, [self.a, self.e, self.f], purge=True)

        self._assert_sql(buf.getvalue(), None, {self.a, self.e, self.f})
Esempio n. 12
0
    def _env_fixture(self, target_metadata):
        self.engine = engine = _sqlite_file_db()

        def run_env(self):
            from alembic import context

            with engine.connect() as connection:
                context.configure(connection=connection,
                                  target_metadata=target_metadata)
                with context.begin_transaction():
                    context.run_migrations()

        return mock.patch("alembic.script.base.ScriptDirectory.run_env",
                          run_env)
Esempio n. 13
0
    def _env_fixture(self, target_metadata):
        self.engine = engine = _sqlite_file_db()

        def run_env(self):
            from alembic import context

            with engine.connect() as connection:
                context.configure(
                    connection=connection,
                    target_metadata=target_metadata)
                with context.begin_transaction():
                    context.run_migrations()

        return mock.patch(
            "alembic.script.base.ScriptDirectory.run_env",
            run_env
        )
Esempio n. 14
0
    def test_warning_on_passing_engine(self):
        env = self._fixture()

        engine = _sqlite_file_db()

        a_rev = "arev"
        env.script.generate_revision(a_rev, "revision a", refresh=True)
        write_script(
            env.script,
            a_rev,
            """\
"Rev A"
revision = '%s'
down_revision = None

from alembic import op


def upgrade():
    pass


def downgrade():
    pass

"""
            % a_rev,
        )
        migration_fn = MagicMock()

        def upgrade(rev, context):
            migration_fn(rev, context)
            return env.script._upgrade_revs(a_rev, rev)

        with expect_warnings(
            r"'connection' argument to configure\(\) is "
            r"expected to be a sqlalchemy.engine.Connection "
        ):
            env.configure(
                connection=engine, fn=upgrade, transactional_ddl=False
            )

        env.run_migrations()

        eq_(migration_fn.mock_calls, [call((), env._migration_context)])
Esempio n. 15
0
    def test_warning_on_passing_engine(self):
        env = self._fixture()

        engine = _sqlite_file_db()

        a_rev = "arev"
        env.script.generate_revision(a_rev, "revision a", refresh=True)
        write_script(
            env.script,
            a_rev,
            """\
"Rev A"
revision = '%s'
down_revision = None

from alembic import op


def upgrade():
    pass


def downgrade():
    pass

"""
            % a_rev,
        )
        migration_fn = mock.MagicMock()

        def upgrade(rev, context):
            migration_fn(rev, context)
            return env.script._upgrade_revs(a_rev, rev)

        with expect_warnings(
            r"'connection' argument to configure\(\) is "
            r"expected to be a sqlalchemy.engine.Connection "
        ):
            env.configure(
                connection=engine, fn=upgrade, transactional_ddl=False
            )

        env.run_migrations()

        eq_(migration_fn.mock_calls, [mock.call((), env._migration_context)])
Esempio n. 16
0
    def test_error_on_passing_engine(self):
        env = self._fixture()

        engine = _sqlite_file_db()

        a_rev = "arev"
        env.script.generate_revision(a_rev, "revision a", refresh=True)
        write_script(
            env.script,
            a_rev,
            """\
"Rev A"
revision = '%s'
down_revision = None

from alembic import op


def upgrade():
    pass


def downgrade():
    pass

"""
            % a_rev,
        )
        migration_fn = mock.MagicMock()

        def upgrade(rev, context):
            migration_fn(rev, context)
            return env.script._upgrade_revs(a_rev, rev)

        with expect_raises_message(
            util.CommandError,
            r"'connection' argument to configure\(\) is "
            r"expected to be a sqlalchemy.engine.Connection ",
        ):
            env.configure(
                connection=engine, fn=upgrade, transactional_ddl=False
            )
Esempio n. 17
0
 def setUp(self):
     self.bind = _sqlite_file_db()
     self.env = staging_env(sourceless=self.sourceless)
     self.cfg = _sqlite_testing_config(sourceless=self.sourceless)
Esempio n. 18
0
 def setUp(self):
     self.bind = _sqlite_file_db()
     self.env = staging_env(sourceless=self.sourceless)
     self.cfg = _sqlite_testing_config(sourceless=self.sourceless)