luckyframework / luckyframework/avram
Default columns should generate values from postgres
Nobody has claimed this yet.
- Dominant language
- Crystal
- Stars
- 183
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
If you're using something like Hasura to connect through Lucky, the GraphQL may need to insert records in to postgres at some point. If you happen to have Avram setup with UUID, then your ID, and the timestamps are all generated from Crystal. This means that inserting a record through GraphQL fails.
To temporarily fix this, you can create a migration that runs this:
def migrate
enable_extension "uuid-ossp" # NOTE: this requires Avram > 0.15? (as of today, it isn't released yet)
execute("ALTER TABLE users ALTER COLUMN id SET DEFAULT uuid_generate_v4();")
execute("ALTER TABLE users ALTER COLUMN created_at SET DEFAULT CURRENT_TIMESTAMP;")
execute("ALTER TABLE users ALTER COLUMN updated_at SET DEFAULT CURRENT_TIMESTAMP;")
end
/cc. @russ @KCErb
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/avram/save_operation.cr around lines 327-328 and review how Avram currently generates UUID and timestamp defaults. Compare that behavior with the migration workaround in the issue; done means records inserted through GraphQL can rely on PostgreSQL-generated id, created_at, and updated_at values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- crystal, postgres
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100