Conversation
📝 WalkthroughWalkthroughAdds a global schema and languages table (with seeded records), SQLModel language models and exports, CRUD functions, API routes and docs for listing/getting languages, test coverage, and seed integration. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant API as API Router (/languages)
participant CRUD as CRUD Layer
participant DB as Database
Client->>API: GET /languages?skip=0&limit=100
API->>CRUD: get_languages(skip, limit)
CRUD->>DB: SELECT * FROM global.languages WHERE is_active = true LIMIT/OFFSET
DB-->>CRUD: rows
CRUD-->>API: list[Language]
API-->>Client: 200 { data: [...], count: N }
Client->>API: GET /languages/{id}
API->>CRUD: get_language_by_id(id)
CRUD->>DB: SELECT * FROM global.languages WHERE id = :id
DB-->>CRUD: row / empty
alt found
CRUD-->>API: Language
API-->>Client: 200 { data: Language }
else not found
API-->>Client: 404 { error }
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In
`@backend/app/alembic/versions/043_create_global_schema_and_languages_table.py`:
- Around line 3-5: The upgrade() and downgrade() functions are missing return
type annotations; update their definitions to include explicit None return types
by changing the signatures to "def upgrade() -> None:" and "def downgrade() ->
None:" (locate the function definitions named upgrade and downgrade in the
migration file and add the -> None annotation while leaving the function bodies
unchanged).
- Line 19: Add explicit return type hints to the Alembic hook functions: change
the signatures of upgrade and downgrade (functions named upgrade and downgrade
in this migration module) to include "-> None" so both functions are annotated
as returning None; ensure you update both occurrences (the upgrade definition
around the top and the downgrade definition later) to follow the project's
guideline for type-hinted functions.
- Around line 58-63: The migration defines the "is_active" column with
nullable=True which conflicts with the model's non-optional is_active: bool;
update the Column declaration for "is_active" (the sa.Boolean() entry named
"is_active") to use nullable=False (keep server_default=sa.text("true") and the
existing comment) so the DB disallows NULLs and matches the model's type
expectations; if this migration has already been applied in any environments,
instead add a follow-up migration that ALTERs the column to set NOT NULL after
ensuring no NULL values exist.
🧹 Nitpick comments (1)
backend/app/models/language.py (1)
36-59: Make the primary key optional and ensureupdated_atrefreshes on updates.
idis initialized asNone, so the type should reflect that, andupdated_atwon’t change unless you explicitly update it elsewhere. Consider adding anonupdatehook for consistency.🔧 Suggested update
- id: int = Field( + id: int | None = Field( default=None, primary_key=True, sa_column_kwargs={"comment": "Unique identifier for the language"}, ) @@ - updated_at: datetime = Field( - default_factory=now, - nullable=False, - sa_column_kwargs={"comment": "Timestamp when the language was last updated"}, - ) + updated_at: datetime = Field( + default_factory=now, + nullable=False, + sa_column_kwargs={ + "comment": "Timestamp when the language was last updated", + "onupdate": now, + }, + )
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
| def downgrade(): | ||
| op.drop_index("ix_global_languages_locale", table_name="languages", schema="global") | ||
| op.drop_table("languages", schema="global") | ||
| op.execute("DROP SCHEMA IF EXISTS global") |
There was a problem hiding this comment.
dropping schema global as of now is an right choice since it is not being used in other tables. but if in future we share global schema for some other tables, then it would be bad choice dropping the entire schema on downgrade.
There was a problem hiding this comment.
-
add unique constraint on locale since this are unique
sa.Column( "locale", sa.String(255), nullable=False, comment="ISO 639-1 language code (e.g., 'en', 'hi')", ), -
normalize the locale during insertion
locale = locale.strip().lower()
There was a problem hiding this comment.
- Our migrations are designed so that rolling back leaves the database exactly as it was before. Because of that, dropping the entire schema on downgrade is the cleanest and safest option for us.
- Add unique constraint, thanks for suggestion
- good suggestion but right now, though, we’re seeding all languages from migration itself and don’t have an API for creating languages yet. For the time being, that’s going to be our main focus.
Summary
Target issue is #582
Checklist
Before submitting a pull request, please ensure that you mark these task.
fastapi run --reload app/main.pyordocker compose upin the repository root and test.Notes
New Features
Database
Summary by CodeRabbit
New Features
Documentation
Tests