Skip to content
Snippets Groups Projects
Commit 9a7ce074 authored by Carlos Carral's avatar Carlos Carral
Browse files

[IMP] core: support dropping materialized views

The function `drop_view_if_exists` only works when the view in question is a regular view, [materialized views](https://www.postgresql.org/docs/current/rules-materializedviews.html

) need a special syntax to be dropped (with an additional `MATERIALIZED` flag).

This is an issue when e.g. needing to replace standard views with materialized views for performance reasons, as dropping the views now fails.

Check the table kind beforehand and dispatch to the correct query.

closes odoo/odoo#117424

Signed-off-by: default avatarXavier Morel (xmo) <xmo@odoo.com>
parent 28a8cc9b
No related branches found
No related tags found
No related merge requests found
......@@ -242,7 +242,11 @@ def drop_index(cr, indexname, tablename):
_schema.debug("Table %r: dropped index %r", tablename, indexname)
def drop_view_if_exists(cr, viewname):
cr.execute("DROP view IF EXISTS %s CASCADE" % (viewname,))
kind = table_kind(cr, viewname)
if kind == 'v':
cr.execute("DROP VIEW {} CASCADE".format(viewname))
elif kind == 'm':
cr.execute("DROP MATERIALIZED VIEW {} CASCADE".format(viewname))
def escape_psql(to_escape):
return to_escape.replace('\\', r'\\').replace('%', '\%').replace('_', '\_')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment