Skip to content

Refactor database views to use external SQL files#128

Open
davidharting wants to merge 1 commit into
mainfrom
claude/refactor-migration-sql-zHECK
Open

Refactor database views to use external SQL files#128
davidharting wants to merge 1 commit into
mainfrom
claude/refactor-migration-sql-zHECK

Conversation

@davidharting
Copy link
Copy Markdown
Owner

Summary

Refactored the database view management system to extract SQL definitions into separate files and introduce a DatabaseView helper class for consistent view creation and migration handling.

Key Changes

  • Created App\Support\DatabaseView class with two static methods:

    • createOrReplace(): Loads SQL from database/views/{viewName}.sql and creates/replaces the view
    • warnOnRollback(): Logs a warning during rollback since views cannot be safely dropped in migrations
  • Extracted SQL to external file: Moved the media_tracking_summary view definition from the migration into database/views/media_tracking_summary.sql

  • Updated migration (2026_03_19_180958_create_media_tracking_summary_view.php):

    • Replaced inline DB::statement() with DatabaseView::createOrReplace()
    • Replaced DROP VIEW with DatabaseView::warnOnRollback()
    • Removed Illuminate\Support\Facades\DB import (now handled by helper class)
  • Added new migration (2026_03_28_023449_add_creator_id_to_media_tracking_summary_view.php):

    • Demonstrates the new pattern for view modifications
    • Uses the same DatabaseView helper methods

Benefits

  • Separation of concerns: SQL definitions are now separate from migration logic
  • Consistency: All view migrations follow the same pattern
  • Maintainability: View definitions are easier to read and modify in dedicated SQL files
  • Reusability: The DatabaseView helper can be used across all view-related migrations

https://claude.ai/code/session_01GM5ERnDYZPAWvg7tJPFcAW

Introduces App\Support\DatabaseView with createOrReplace() and
warnOnRollback() to eliminate raw SQL heredocs from migrations.
View SQL now lives in database/views/ with proper syntax highlighting.
down() methods are no-ops per the no-rollback-in-production philosophy.

- New: database/views/media_tracking_summary.sql — view SELECT body
- New: app/Support/DatabaseView.php — createOrReplace / warnOnRollback
- Refactor: create_media_tracking_summary_view migration to use utility
- New: add_creator_id_to_media_tracking_summary_view migration (one-liner up/down)

https://claude.ai/code/session_01GM5ERnDYZPAWvg7tJPFcAW
davidharting added a commit that referenced this pull request Mar 28, 2026
…#128)

Extracts web-search-based media identification from the main MediaTrackingAgent
into a dedicated ResolveMediaTool that runs on claude-haiku-4-5-20251001.
MediaTrackingAgent no longer uses WebSearch directly, reducing token costs ~1/3
per /track interaction.

ResolveMediaTool accepts a raw media reference and returns a JSON array of
matches (title, year, creator, media_type), handling ambiguity by returning
multiple results when more than one plausible match exists.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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