Ejemplo n.º 1
0
    def test_upgrade_downgrade_ops_list_accessors(self):
        u1 = ops.UpgradeOps(ops=[])
        d1 = ops.DowngradeOps(ops=[])
        m1 = ops.MigrationScript(
            "somerev", u1, d1
        )
        is_(
            m1.upgrade_ops, u1
        )
        is_(
            m1.downgrade_ops, d1
        )
        u2 = ops.UpgradeOps(ops=[])
        d2 = ops.DowngradeOps(ops=[])
        m1._upgrade_ops.append(u2)
        m1._downgrade_ops.append(d2)

        assert_raises_message(
            ValueError,
            "This MigrationScript instance has a multiple-entry list for "
            "UpgradeOps; please use the upgrade_ops_list attribute.",
            getattr, m1, "upgrade_ops"
        )
        assert_raises_message(
            ValueError,
            "This MigrationScript instance has a multiple-entry list for "
            "DowngradeOps; please use the downgrade_ops_list attribute.",
            getattr, m1, "downgrade_ops"
        )
        eq_(m1.upgrade_ops_list, [u1, u2])
        eq_(m1.downgrade_ops_list, [d1, d2])
Ejemplo n.º 2
0
    def test_add_column(self):
        t = self.table

        op = ops.AddColumnOp.from_column_and_tablename(None, 't', t.c.x)
        is_(op.to_column(), t.c.x)
        is_(op.reverse().to_column(), t.c.x)
        is_not_(None, op.to_column().table)
Ejemplo n.º 3
0
    def test_drop_column(self):
        t = self.table

        op = ops.DropColumnOp.from_column_and_tablename(None, "t", t.c.x)
        is_(op.to_column(), t.c.x)
        is_(op.reverse().to_column(), t.c.x)
        is_not_(None, op.to_column().table)
Ejemplo n.º 4
0
 def test_drop_unique_constraint(self):
     schema_obj = schemaobj.SchemaObjects()
     const = schema_obj.unique_constraint('x', 'foobar', ['a'])
     op = ops.DropConstraintOp.from_constraint(const)
     is_(
         op.to_constraint(), const
     )
Ejemplo n.º 5
0
 def test_create_table(self):
     schema_obj = schemaobj.SchemaObjects()
     table = schema_obj.table('x', Column('q', Integer))
     op = ops.CreateTableOp.from_table(table)
     is_(
         op.to_table(), table
     )
Ejemplo n.º 6
0
 def test_create_index(self):
     schema_obj = schemaobj.SchemaObjects()
     idx = schema_obj.index('x', 'y', ['z'])
     op = ops.CreateIndexOp.from_index(idx)
     is_(
         op.to_index(), idx
     )
Ejemplo n.º 7
0
    def test_migration_context_has_config(self):
        env = self._fixture()
        env.configure(url="sqlite://")
        ctx = env._migration_context
        is_(ctx.config, self.cfg)

        ctx = MigrationContext(ctx.dialect, None, {})
        is_(ctx.config, None)
Ejemplo n.º 8
0
    def test_alter_column_autoincrement_pk_implicit_true(self):
        m1 = MetaData()
        m2 = MetaData()

        Table("a", m1, Column("x", Integer, primary_key=True))
        Table("a", m2, Column("x", BigInteger, primary_key=True))

        ops = self._fixture(m1, m2, return_ops=True)
        is_(ops.ops[0].ops[0].kw["autoincrement"], True)
Ejemplo n.º 9
0
    def test_alter_column_autoincrement_pk_explicit_true(self):
        m1 = MetaData()
        m2 = MetaData()

        Table(
            'a', m1,
            Column('x', Integer, primary_key=True, autoincrement=True))
        Table(
            'a', m2,
            Column('x', BigInteger, primary_key=True, autoincrement=True))

        ops = self._fixture(m1, m2, return_ops=True)
        is_(ops.ops[0].ops[0].kw['autoincrement'], True)
Ejemplo n.º 10
0
    def test_double_migrate_table(self):
        writer = autogenerate.Rewriter()

        idx_ops = []

        @writer.rewrites(ops.ModifyTableOps)
        def second_table(context, revision, op):
            return [
                op,
                ops.ModifyTableOps('t2', ops=[
                    ops.AddColumnOp('t2', sa.Column('x', sa.Integer()))
                ])
            ]

        @writer.rewrites(ops.AddColumnOp)
        def add_column(context, revision, op):
            idx_op = ops.CreateIndexOp('ixt', op.table_name, [op.column.name])
            idx_ops.append(idx_op)
            return [
                op,
                idx_op
            ]

        directives = [
            ops.MigrationScript(
                util.rev_id(),
                ops.UpgradeOps(ops=[
                    ops.ModifyTableOps('t1', ops=[
                        ops.AddColumnOp('t1', sa.Column('x', sa.Integer()))
                    ])
                ]),
                ops.DowngradeOps(ops=[]),
            )
        ]

        ctx, rev = mock.Mock(), mock.Mock()
        writer(ctx, rev, directives)
        eq_(
            [d.table_name for d in directives[0].upgrade_ops.ops],
            ['t1', 't2']
        )
        is_(
            directives[0].upgrade_ops.ops[0].ops[1],
            idx_ops[0]
        )
        is_(
            directives[0].upgrade_ops.ops[1].ops[1],
            idx_ops[1]
        )
Ejemplo n.º 11
0
    def test_alter_column_autoincrement_compositepk_false(self):
        m1 = MetaData()
        m2 = MetaData()

        Table(
            'a', m1,
            Column('id', Integer, primary_key=True),
            Column('x', Integer, primary_key=True, autoincrement=False)
        )
        Table(
            'a', m2,
            Column('id', Integer, primary_key=True),
            Column('x', BigInteger, primary_key=True, autoincrement=False)
        )

        ops = self._fixture(m1, m2, return_ops=True)
        is_(ops.ops[0].ops[0].kw['autoincrement'], False)
Ejemplo n.º 12
0
    def test_alter_column_autoincrement_compositepk_false(self):
        m1 = MetaData()
        m2 = MetaData()

        Table(
            "a",
            m1,
            Column("id", Integer, primary_key=True),
            Column("x", Integer, primary_key=True, autoincrement=False),
        )
        Table(
            "a",
            m2,
            Column("id", Integer, primary_key=True),
            Column("x", BigInteger, primary_key=True, autoincrement=False),
        )

        ops = self._fixture(m1, m2, return_ops=True)
        is_(ops.ops[0].ops[0].kw["autoincrement"], False)
Ejemplo n.º 13
0
    def test_drop_table(self):
        t = self.table

        op = ops.DropTableOp.from_table(t)
        is_(op.to_table(), t)
        is_(op.reverse().to_table(), t)
        is_(self.metadata, op.to_table().metadata)
Ejemplo n.º 14
0
    def test_add_table(self):
        t = self.table

        op = ops.CreateTableOp.from_table(t)
        is_(op.to_table(), t)
        is_(op.reverse().to_table(), t)
        is_(self.metadata, op.to_table().metadata)
Ejemplo n.º 15
0
    def test_alter_column_autoincrement_compositepk_explicit_true(self):
        m1 = MetaData()
        m2 = MetaData()

        Table(
            'a', m1,
            Column('id', Integer, primary_key=True, autoincrement=False),
            Column('x', Integer, primary_key=True, autoincrement=True),
            # on SQLA 1.0 and earlier, this being present
            # trips the "add KEY for the primary key" so that the
            # AUTO_INCREMENT keyword is accepted by MySQL.  SQLA 1.1 and
            # greater the columns are just reorganized.
            mysql_engine='InnoDB'
        )
        Table(
            'a', m2,
            Column('id', Integer, primary_key=True, autoincrement=False),
            Column('x', BigInteger, primary_key=True, autoincrement=True)
        )

        ops = self._fixture(m1, m2, return_ops=True)
        is_(ops.ops[0].ops[0].kw['autoincrement'], True)
Ejemplo n.º 16
0
    def test_datetime(self):
        t1 = DateTime()
        t2 = DateTime(timezone=False)
        t3 = DateTime(timezone=True)

        impl = self._fixture()
        is_(impl.compare_type(Column('x', t1), Column('x', t2)), False)
        is_(impl.compare_type(Column('x', t1), Column('x', t3)), True)
        is_(impl.compare_type(Column('x', t2), Column('x', t3)), True)
Ejemplo n.º 17
0
    def test_alter_column_autoincrement_compositepk_explicit_true(self):
        m1 = MetaData()
        m2 = MetaData()

        Table(
            "a",
            m1,
            Column("id", Integer, primary_key=True, autoincrement=False),
            Column("x", Integer, primary_key=True, autoincrement=True),
            # on SQLA 1.0 and earlier, this being present
            # trips the "add KEY for the primary key" so that the
            # AUTO_INCREMENT keyword is accepted by MySQL.  SQLA 1.1 and
            # greater the columns are just reorganized.
            mysql_engine="InnoDB",
        )
        Table(
            "a",
            m2,
            Column("id", Integer, primary_key=True, autoincrement=False),
            Column("x", BigInteger, primary_key=True, autoincrement=True),
        )

        ops = self._fixture(m1, m2, return_ops=True)
        is_(ops.ops[0].ops[0].kw["autoincrement"], True)
Ejemplo n.º 18
0
    def test_numeric(self):
        t1 = Numeric(10, 5)
        t2 = Numeric(12, 5)
        t3 = DECIMAL(10, 5)
        t4 = DateTime

        impl = self._fixture()
        is_(impl.compare_type(Column('x', t3), Column('x', t1)), False)
        is_(impl.compare_type(Column('x', t3), Column('x', t2)), True)
        is_(impl.compare_type(Column('x', t3), Column('x', t4)), True)
Ejemplo n.º 19
0
    def test_string(self):
        t1 = String(30)
        t2 = String(40)
        t3 = VARCHAR(30)
        t4 = Integer

        impl = self._fixture()
        is_(impl.compare_type(Column('x', t3), Column('x', t1)), False)
        is_(impl.compare_type(Column('x', t3), Column('x', t2)), True)
        is_(impl.compare_type(Column('x', t3), Column('x', t4)), True)
Ejemplo n.º 20
0
 def test_drop_check(self):
     ck = self.ck
     op = ops.DropConstraintOp.from_constraint(ck)
     is_(op.to_constraint(), ck)
     is_(op.reverse().to_constraint(), ck)
     is_not_(None, op.to_constraint().table)
Ejemplo n.º 21
0
 def test_drop_fk(self):
     fk = self.fk
     op = ops.DropConstraintOp.from_constraint(fk)
     is_(op.to_constraint(), fk)
     is_(op.reverse().to_constraint(), fk)
Ejemplo n.º 22
0
 def test_create_index(self):
     op = ops.CreateIndexOp.from_index(self.ix)
     is_(op.to_index(), self.ix)
     is_(op.reverse().to_index(), self.ix)
Ejemplo n.º 23
0
 def test_drop_index(self):
     op = ops.DropIndexOp.from_index(self.ix)
     is_(op.to_index(), self.ix)
     is_(op.reverse().to_index(), self.ix)
Ejemplo n.º 24
0
    def test_integer(self):
        t1 = Integer()
        t2 = SmallInteger()
        t3 = BIGINT()
        t4 = String()
        t5 = INTEGER()
        t6 = BigInteger()

        impl = self._fixture()
        is_(impl.compare_type(Column('x', t5), Column('x', t1)), False)
        is_(impl.compare_type(Column('x', t3), Column('x', t1)), True)
        is_(impl.compare_type(Column('x', t3), Column('x', t6)), False)
        is_(impl.compare_type(Column('x', t3), Column('x', t2)), True)
        is_(impl.compare_type(Column('x', t5), Column('x', t2)), True)
        is_(impl.compare_type(Column('x', t1), Column('x', t4)), True)
Ejemplo n.º 25
0
    def test_numeric_noprecision(self):
        t1 = Numeric()
        t2 = Numeric(scale=5)

        impl = self._fixture()
        is_(impl.compare_type(Column("x", t1), Column("x", t2)), False)
Ejemplo n.º 26
0
 def test_drop_pk(self):
     pk = self.pk
     op = ops.DropConstraintOp.from_constraint(pk)
     is_(op.to_constraint(), pk)
     is_(op.reverse().to_constraint(), pk)
     is_not_(None, op.to_constraint().table)
Ejemplo n.º 27
0
 def test_drop_unique_constraint(self):
     schema_obj = schemaobj.SchemaObjects()
     const = schema_obj.unique_constraint("x", "foobar", ["a"])
     op = ops.DropConstraintOp.from_constraint(const)
     is_(op.to_constraint(), const)
Ejemplo n.º 28
0
 def test_add_fk(self):
     fk = self.fk
     op = ops.AddConstraintOp.from_constraint(fk)
     is_(op.to_constraint(), fk)
     is_(op.reverse().to_constraint(), fk)
     is_not_(None, op.to_constraint().table)
Ejemplo n.º 29
0
 def test_create_index(self):
     schema_obj = schemaobj.SchemaObjects()
     idx = schema_obj.index("x", "y", ["z"])
     op = ops.CreateIndexOp.from_index(idx)
     is_(op.to_index(), idx)
Ejemplo n.º 30
0
 def test_drop_table(self):
     schema_obj = schemaobj.SchemaObjects()
     table = schema_obj.table("x", Column("q", Integer))
     op = ops.DropTableOp.from_table(table)
     is_(op.to_table(), table)
Ejemplo n.º 31
0
 def test_drop_unique(self):
     uq = self.uq
     op = ops.DropConstraintOp.from_constraint(uq)
     is_(op.to_constraint(), uq)
     is_(op.reverse().to_constraint(), uq)
     is_not_(None, op.to_constraint().table)