Setting column after create()

6 views
Skip to first unread message

Jeff Cook

unread,
Nov 6, 2011, 5:32:58 PM11/6/11
to migrate-users
I have this:

def upgrade(migrate_engine):
meta = MetaData(bind=migrate_engine)
comments = Table('comments', meta, autoload=True)
deletedc = Column('deleted', Boolean, default=False)
deletedc.create(comments)
smaker = orm.sessionmaker(bind=migrate_engine)
db = smaker()
db.expire_all()
db.flush()
print "Updating deleted flag on existing comments..."
for c in db.query(Comment).all():
print c
print c.body
if c.body == '[deleted]':
db.refresh(c)
print c.__dict__
print 'deleting'
#print c.deleted
c.deleted = True
db.add(c)
print db.dirty
print db.dirty
db.flush()
db.commit()

You can see I've tried lots of things to make it work and I've come to
the conclusion that sa-migrate must not actually run the create()
command until after it runs the user-defined upgrade() function, since
my c objects do not have the column attached.

Anyone know how I can do something like what I want to do there? After
I create a column with a new default, I need to go through and make
sure that stuff that didn't exist before that column is in place is
correct.

Jeff Cook

unread,
Nov 9, 2011, 4:15:51 AM11/9/11
to migrate-users
Anyone? If there's something obvious here I'd really like to be
informed.

Jan Dittberner

unread,
Nov 9, 2011, 4:51:50 AM11/9/11
to migrat...@googlegroups.com
I assume the ORM session would have to use the same MetaData instance,
I'm not sure that this is possible though.

2011/11/9 Jeff Cook <cooki...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups "migrate-users" group.
> To post to this group, send email to migrat...@googlegroups.com.
> To unsubscribe from this group, send email to migrate-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/migrate-users?hl=en.
>
>

--
Jan Dittberner
Software Architect - Debian Developer

Reply all
Reply to author
Forward
0 new messages