Skip to content

fix: DROP TABLE IF EXISTS before metric views (table-to-view migration)#233

Open
tingtingwan wants to merge 1 commit into
databricks-demos:mainfrom
tingtingwan:fix/drop-table-metric-views
Open

fix: DROP TABLE IF EXISTS before metric views (table-to-view migration)#233
tingtingwan wants to merge 1 commit into
databricks-demos:mainfrom
tingtingwan:fix/drop-table-metric-views

Conversation

@tingtingwan

Copy link
Copy Markdown
Contributor

Summary

  • Adds DROP TABLE IF EXISTS before each CREATE OR REPLACE VIEW for the 4 metric views: metrics_events, metrics_feedback, metrics_issues, metrics_daily_rolling
  • Fixes EXPECT_VIEW_NOT_TABLE error for users who previously deployed the marketing campaign demo (where these were defined as tables, not views)
  • Clean installs are unaffected — DROP TABLE IF EXISTS is a no-op when the table doesn't exist

Context

After merging PR #232 (Metric Views update), existing dbdemos users encounter:

[EXPECT_VIEW_NOT_TABLE.NO_ALTERNATIVE] The table `main`.`schema`.`metrics_daily_rolling` does not support CREATE OR REPLACE VIEW

This is because the old dbdemos defined these as tables, while the new version creates them as views.

Test plan

  • Verify clean install works (no prior tables exist)
  • Verify upgrade install works (prior tables exist from old dbdemos)
  • Confirm DROP TABLE IF EXISTS is a no-op when the object is already a view

🤖 Generated with Claude Code

…igration

Handles upgrade path from old dbdemos deployments (metrics as tables) to new
version (metrics as views). Without this, existing users who previously installed
the marketing campaign demo get EXPECT_VIEW_NOT_TABLE errors.

Applies to: metrics_events, metrics_feedback, metrics_issues, metrics_daily_rolling

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@QuentinAmbard

QuentinAmbard commented Mar 11, 2026

Copy link
Copy Markdown
Collaborator

hey, this won't work I believe cause if it's a VIEW then DROP TABLE fails (as it's a view and not a table) - and vice-versa
I don't have an easy solution tbh (like we'd need something like: IF TABLE THEN DROP TABLE?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants