Ejemplo n.º 1
0
    def test_identity_on_null(self):
        m1 = MetaData()
        m2 = MetaData()

        Table(
            "user",
            m1,
            Column("id", Integer, sa.Identity(start=2, on_null=True)),
            Column("other", sa.Text),
        )

        Table(
            "user",
            m2,
            Column("id", Integer, sa.Identity(start=2, on_null=False)),
            Column("other", sa.Text),
        )

        diffs = self._fixture(m1, m2)
        if not config.requirements.supports_identity_on_null.enabled:
            eq_(diffs, [])
        else:
            eq_(len(diffs[0]), 1)
            diffs = diffs[0][0]
            eq_(diffs[0], "modify_default")
            eq_(diffs[2], "user")
            eq_(diffs[3], "id")
            old = diffs[5]
            new = diffs[6]

            is_true(isinstance(old, sa.Identity))
            is_true(isinstance(new, sa.Identity))
Ejemplo n.º 2
0
    def test_remove_identity_column(self):
        m1 = MetaData()
        m2 = MetaData()

        Table(
            "user",
            m1,
            Column(
                "id",
                Integer,
                sa.Identity(start=2, increment=3),
                primary_key=True,
            ),
        )

        Table("user", m2)

        diffs = self._fixture(m1, m2)

        eq_(diffs[0][0], "remove_column")
        eq_(diffs[0][2], "user")
        c = diffs[0][3]
        eq_(c.name, "id")

        is_true(isinstance(c.identity, sa.Identity))
        eq_(c.identity.start, 2)
        eq_(c.identity.increment, 3)
Ejemplo n.º 3
0
    def test_remove_identity_from_column(self):
        m1 = MetaData()
        m2 = MetaData()

        Table(
            "user",
            m1,
            Column("id", Integer, sa.Identity(start=2, maxvalue=1000)),
            Column("other", sa.Text),
        )

        Table(
            "user",
            m2,
            Column("id", Integer),
            Column("other", sa.Text),
        )

        diffs = self._fixture(m1, m2)

        eq_(len(diffs[0]), 1)
        diffs = diffs[0][0]
        eq_(diffs[0], "modify_default")
        eq_(diffs[2], "user")
        eq_(diffs[3], "id")
        eq_(diffs[6], None)
        removed = diffs[5]

        is_true(isinstance(removed, sa.Identity))
Ejemplo n.º 4
0
    def test_add_identity_column(self):
        m1 = MetaData()
        m2 = MetaData()

        Table("user", m1, Column("other", sa.Text))

        Table(
            "user",
            m2,
            Column("other", sa.Text),
            Column(
                "id",
                Integer,
                sa.Identity(start=5, increment=7),
                primary_key=True,
            ),
        )

        diffs = self._fixture(m1, m2)

        eq_(diffs[0][0], "add_column")
        eq_(diffs[0][2], "user")
        eq_(diffs[0][3].name, "id")
        i = diffs[0][3].identity

        is_true(isinstance(i, sa.Identity))
        eq_(i.start, 5)
        eq_(i.increment, 7)
Ejemplo n.º 5
0
 def check(kw, idt):
     if kw:
         is_true(isinstance(idt, sa.Identity))
         for k, v in kw.items():
             eq_(getattr(idt, k), v)
     else:
         is_true(idt in (None, False))
Ejemplo n.º 6
0
    def test_remove_computed_column(self):
        m1 = MetaData()
        m2 = MetaData()

        Table(
            "user",
            m1,
            Column("id", Integer, primary_key=True),
            Column("foo", Integer, sa.Computed("5")),
        )

        Table("user", m2, Column("id", Integer, primary_key=True))

        diffs = self._fixture(m1, m2)

        eq_(diffs[0][0], "remove_column")
        eq_(diffs[0][2], "user")
        c = diffs[0][3]
        eq_(c.name, "foo")

        is_(c.computed, None)

        if config.requirements.computed_reflects_as_server_default.enabled:
            is_true(isinstance(c.server_default, sa.DefaultClause))
            eq_(str(c.server_default.arg.text), "5")
        else:
            is_(c.server_default, None)
Ejemplo n.º 7
0
 def test_proxy_transaction_commit(self):
     context = self._fixture(
         {"transaction_per_migration": True, "transactional_ddl": True}
     )
     proxy = context.begin_transaction(_per_migration=True)
     is_true(self.conn.in_transaction())
     proxy.commit()
     is_false(self.conn.in_transaction())
Ejemplo n.º 8
0
    def test_transaction_per_all_non_transactional_ddl(self):
        context = self._fixture({"transactional_ddl": False})

        is_false(self.conn.in_transaction())

        with context.begin_transaction():
            is_false(self.conn.in_transaction())
            with context.begin_transaction(_per_migration=True):
                is_true(self.conn.in_transaction())

            is_false(self.conn.in_transaction())
        is_false(self.conn.in_transaction())
Ejemplo n.º 9
0
    def test_version_text(self):
        buf = compat.StringIO()
        to_mock = "sys.stdout" if util.compat.py3k else "sys.stderr"

        with mock.patch(to_mock, buf):
            try:
                config.CommandLine(prog="test_prog").main(argv=["--version"])
                assert False
            except SystemExit:
                pass

        is_true("test_prog" in str(buf.getvalue()))
        is_true(__version__ in str(buf.getvalue()))
Ejemplo n.º 10
0
    def test_proxy_transaction_contextmanager_rollback(self):
        context = self._fixture(
            {"transaction_per_migration": True, "transactional_ddl": True}
        )
        proxy = context.begin_transaction(_per_migration=True)
        is_true(self.conn.in_transaction())

        def go():
            with proxy:
                raise Exception("hi")

        assert_raises(Exception, go)
        is_false(self.conn.in_transaction())
Ejemplo n.º 11
0
    def test_proxy_transaction_contextmanager_explicit_rollback(self):
        context = self._fixture({
            "transaction_per_migration": True,
            "transactional_ddl": True
        })
        proxy = context.begin_transaction(_per_migration=True)
        is_true(self.conn.in_transaction())

        with proxy:
            is_true(self.conn.in_transaction())
            proxy.rollback()
            is_false(self.conn.in_transaction())

        is_false(self.conn.in_transaction())
Ejemplo n.º 12
0
    def test_autocommit_block(self):
        context = self._fixture({"transaction_per_migration": True})

        is_false(self.conn.in_transaction())

        with context.begin_transaction():
            is_false(self.conn.in_transaction())
            with context.begin_transaction(_per_migration=True):
                is_true(self.conn.in_transaction())

                with context.autocommit_block():
                    is_false(self.conn.in_transaction())

                is_true(self.conn.in_transaction())

            is_false(self.conn.in_transaction())
        is_false(self.conn.in_transaction())
Ejemplo n.º 13
0
    def test_remove_computed_default_on_computed(self):
        """Asserts the current behavior which is that on PG and Oracle,
        the GENERATED ALWAYS AS is reflected as a server default which we can't
        tell is actually "computed", so these come out as a modification to
        the server default.

        """
        m1 = MetaData()
        m2 = MetaData()

        Table(
            "user",
            m1,
            Column("id", Integer, primary_key=True),
            Column("bar", Integer),
            Column("foo", Integer, sa.Computed("bar + 42")),
        )

        Table(
            "user",
            m2,
            Column("id", Integer, primary_key=True),
            Column("bar", Integer),
            Column("foo", Integer),
        )

        diffs = self._fixture(m1, m2)

        eq_(diffs[0][0][0], "modify_default")
        eq_(diffs[0][0][2], "user")
        eq_(diffs[0][0][3], "foo")
        old = diffs[0][0][-2]
        new = diffs[0][0][-1]

        is_(new, None)
        is_true(isinstance(old, sa.DefaultClause))

        if exclusions.against(config, "postgresql"):
            eq_(str(old.arg.text), "(bar + 42)")
        elif exclusions.against(config, "oracle"):
            eq_(str(old.arg.text), '"BAR"+42')
Ejemplo n.º 14
0
    def test_add_computed_column(self):
        m1 = MetaData()
        m2 = MetaData()

        Table("user", m1, Column("id", Integer, primary_key=True))

        Table(
            "user",
            m2,
            Column("id", Integer, primary_key=True),
            Column("foo", Integer, sa.Computed("5")),
        )

        diffs = self._fixture(m1, m2)

        eq_(diffs[0][0], "add_column")
        eq_(diffs[0][2], "user")
        eq_(diffs[0][3].name, "foo")
        c = diffs[0][3].computed

        is_true(isinstance(c, sa.Computed))
        is_(c.persisted, None)
        eq_(str(c.sqltext), "5")