Skip to content

Implement Optional DSL for View Definitions #41

@niteshpurohit

Description

@niteshpurohit

Feature Request

Description:

Implement an optional, code-based Domain-Specific Language (DSL) for defining materialized views. This would allow developers to manage view definitions in version-controlled Ruby files (e.g., in db/mat_views/*.rb) as an alternative to using the Admin UI. Coded views are not editable.

Use Case:

Many development teams prefer an 'infrastructure-as-code' approach, where database objects and configurations are versioned and deployed alongside application code. A DSL makes this workflow possible.

Proposed Solution:

  • Create a rake task (e.g., mat_views:sync_from_dsl) that reads all files in db/mat_views.
  • Define a DSL syntax, for example:
    matview "users_summary" do sql "SELECT id, count(*) FROM users GROUP BY id" refresh :concurrent, cron: "0 * * * *" end
  • The rake task will parse these files and create or update the corresponding MatViewDefinition records in the database.

RSpec Tests:

  • Create a sample DSL file in the test environment.
  • Run the mat_views:sync_from_dsl rake task.
  • Verify that a MatViewDefinition is created in the database with the correct attributes (SQL, schedule, etc.) from the DSL file.
  • Test that running the task again updates the existing record rather than creating a duplicate.

Checklist:

  • I have searched for a similar feature request and didn't find any duplicates.
  • I have included all the required information.
  • I have tagged the issue with the label "enhancement".

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions