luckyframework / luckyframework/avram

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

Open Beginner friendly
#1,147 0 comments 0 reactions 0 assignees View on GitHub
improve error experience
Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

Using this code when there's no view named `some_view`

```crystal
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.

Contributor guide

Open the contributing guide

Research direction

Start in src/avram/schema_enforcer/ensure_existing_table.cr, where the schema mismatch is raised, and inspect the view declaration and existing coverage around spec/avram/multi_database_spec.cr. Add a regression case for a missing materialized view and verify that the resulting message identifies a view or otherwise avoids incorrectly calling it a table.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal
Domain
databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.