From 0705217200a89818f0108ea566e705e96f8677df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henry=20H=C3=BCske?= <35104402+henryhueske@users.noreply.github.com> Date: Thu, 7 Mar 2024 11:13:41 +0100 Subject: [PATCH] Add IF EXISTS clause to DROP VIEW statements in order to prevent errors when non-existing views will be dropped in an Alembic version --- .gitignore | 2 +- src/databricks/sqlalchemy/dialect/base.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 66c94734..56e5642e 100644 --- a/.gitignore +++ b/.gitignore @@ -195,7 +195,7 @@ cython_debug/ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ +.idea/ # End of https://www.toptal.com/developers/gitignore/api/python,macos diff --git a/src/databricks/sqlalchemy/dialect/base.py b/src/databricks/sqlalchemy/dialect/base.py index 23919fde..f5a0efaf 100644 --- a/src/databricks/sqlalchemy/dialect/base.py +++ b/src/databricks/sqlalchemy/dialect/base.py @@ -154,6 +154,9 @@ def visit_drop_table(self, drop, **kw): return text + self.preparer.format_table(drop.element) + def visit_drop_view(self, drop, **kw): + return "\nDROP VIEW IF EXISTS " + self.preparer.format_table(drop.element) + @compiles(ColumnComment, "databricks") def visit_column_comment(