resending because my PGP tools totally got in the way

On 01/22/2016 09:05 AM, Michal Petrucha wrote:
> On Fri, Jan 22, 2016 at 01:44:38PM +0100, Michal Petrucha wrote:
>> Can anyone help me come up with the best way of renaming a Boolean
>> column on both backends? I'm about to try creating a new column with
>> the new name, copying the data from the old column, and dropping the
>> old one, but that's a really convoluted approach.
> 
> ...and just now I realized that won't work either, because there's a
> bug in the batch implementation of drop_column. Funnily enough, it was
> only yesterday that I submitted a PR for that particular bug
> (https://bitbucket.org/zzzeek/alembic/pull-requests/53/ for those who
> are interested). Which means even my brute-force fallback solution is
> a no go, at least for the time being.
> 
> In light of that, can anyone come up with a solution that does not
> involve any of the following:
> - a straight-up rename of a Boolean column,
> - changing Boolean to Integer, and
> - dropping a Boolean column?
> 
> Changing the type from Boolean() to Boolean(create_constraint=False)
> has the same effect as changing to Integer().
> 
> Or maybe -- can I drop the CHECK constraint manually? What I mean is,
> is it guaranteed that the constraint will be there for all backends,
> even those with a native boolean type? (That appears to be the case
> for MS SQL, but I'm curious if it holds for other backends as well.)
> If the only condition for creating the constraint is
> create_constraint=True (regardless of the backend's capabilities),
> this might be a way forward.


I see in

     batch_op.alter_column(name, type_=sa.Integer(),
existing_type=sa.Boolean())

you aren't giving it the constraint name in the existing_type, that's
actually where the
"_unnamed_" is coming from.

I just added a test for this and it seems that this existing_type is
where the problem comes from, not the batch migration.  So setting
create_constraint=False allows it to recreate (which is wrong, but gets
us to the next step):

    def _boolean_fixture(self):
        t = Table(
            'hasbool', self.metadata,
            Column('x', Boolean(create_constraint=True, name='ck1'))
        )
        t.create(self.conn)

    def test_bool_change(self):
        self._boolean_fixture()
        with self.op.batch_alter_table("hasbool") as batch_op:
            batch_op.alter_column(
                'x', type_=Integer, existing_type=Boolean(
                    create_constraint=False, name='ck1'))

however, it's still copying the constraint, and adding a DROP is not
working so I have to just cerate an issue for this, sorry.

https://bitbucket.org/zzzeek/alembic/issues/354/cant-change-type-of-bool
ean-w-batch




> 
> Cheers,
> 
> Michal
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy-alembic+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to