I'm using alembic to manage my database structure.
After adding a table using id as Integer and primary key the id column will be an autoincrement-column. How do I query the data in the upgrade script so I'm sure that I get the correct id (I know it's 1 in this specific case)?
I know how to
#creating the table
op.create_table(
'srv_feed_return_type',
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('name', sa.String(50), nullable=False),
sa.Column('created', sa.DateTime, server_default=func.now(), nullable=False),
sa.Column('created_by', sa.String(50), nullable=False),
sa.Column('last_updated', sa.DateTime, nullable=False),
sa.Column('last_updated_by', sa.String(50), nullable=False)
)
#table for operations
srv_feed_return_type = table('srv_feed_return_type',
column('name'),
column('created'),
column('created_by'),
column('last_updated'),
column('last_updated_by'))
#bulk insert
op.bulk_insert(srv_feed_return_type,
[
{'name': 'dataset',
'created': datetime.now(), 'created_by': 'Asken',
'last_updated': datetime.now(), 'last_updated_by': 'Asken'}
])
I know I can do update but how do I do a select using something similar like below?
op.execute(
srv_feed_return_type.update().\
where(srv_feed_return_type.c.name==op.inline_literal('dataset')).\
values({'name':op.inline_literal('somethingelse')})
)