Does somebody know how to use create_view function to create a view using alembic upgrade function? for example, we have:
CREATE VIEW myview AS
SELECT column_name(s)
FROM table_name
WHERE condition
Now we want to define a view in alembic upgrade function script to create 'myview'. How to realize that?
Thanks.
I know, the question is way too old and probably the possibility didn't exist at that time. However for all the ones coming to this question now: there exists a possibility now described in the cookbook.
It leverages the creation, deletion and replacement of objects like views and stored procedures by giving you additional operations like op.create_view, op.drop_view or op.replace_view(myview, replaces="3f2ab897a.myview"). The same is true for stored procedures and can be also extended for e.g. user defined functions.
A view is defined the following way:
myview = ReplaceableObject('myview',
"""
SELECT * FROM mytable
"""
)
Of course all of this can also be done with simple op.execute statements, however in this case alembic takes care of the DROP VIEW, CREATE VIEW and ALTER VIEW commands.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With