Skip to content

A non-existent materialized view raises an error telling you to create a table #1147

@jwoertink

Description

@jwoertink

Using this code when there's no view named some_view

class MaterializedView < Avram::Model
  view :some_view, materialized: true do
    column name : String
  end
end

you'll get this error

MaterializedView wants to use the 'some_view' table but it is missing.

       If you need to create the 'some_view' table...

         ▸ Generate a migration:

             lucky gen.migration CreateMaterializedView

         ▸ Create the table in the migration:

             create table_for(MaterializedView) do/end

       Or, you can skip schema checks for this model:

           class MaterializedView < BaseModel
             # Great for models used in migrations, or for legacy schemas
             skip_schema_enforcer
           end

        (Avram::SchemaMismatchError)
         from src/avram/schema_enforcer/ensure_existing_table.cr:24:9 in 'validate!'
         from spec/avram/multi_database_spec.cr:49:3 in 'ensure_correct_column_mappings!'
         from spec/avram/multi_database_spec.cr:101:7 in '->'

The error is a bit misleading since we're not trying to use a table here, it's a view... However, it's possible that the view could be the wrong thing 🤷‍♂️ So maybe we just need to say wants to use the 'some_view' table/view, etc..? Be generic about both? Or if it's possible to know which one is being tried, then say "view" when it's a view or "table" otherwise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions