Skip to content

Language: Initialization#583

Merged
AkhileshNegi merged 6 commits intomainfrom
enhancement/language
Feb 6, 2026
Merged

Language: Initialization#583
AkhileshNegi merged 6 commits intomainfrom
enhancement/language

Conversation

@AkhileshNegi
Copy link
Collaborator

@AkhileshNegi AkhileshNegi commented Feb 5, 2026

Summary

Target issue is #582

Checklist

Before submitting a pull request, please ensure that you mark these task.

  • Ran fastapi run --reload app/main.py or docker compose up in the repository root and test.
  • If you've fixed a bug or added code that is tested and has test cases.

Notes

  • New Features

    • Added multilingual support infrastructure with a languages management system.
    • Seeded database with 13 languages including English, Hindi, Tamil, Kannada, Malayalam, Telugu, Odia, Assamese, Gujarati, Bengali, Punjabi, Marathi, and Urdu.
  • Database

    • Created new global schema and languages table with locale indexing.

Summary by CodeRabbit

  • New Features

    • Added language management supporting 13 languages (including English, Hindi, Tamil, Kannada, Malayalam, Telugu, Odia, Assamese, Gujarati, Bengali, Punjabi, Marathi, Urdu); new endpoints to list and retrieve language details; seeded default language records.
  • Documentation

    • Added API docs for language list and get endpoints.
  • Tests

    • Added tests covering listing, pagination, retrieval, not-found, and auth scenarios.

@AkhileshNegi AkhileshNegi self-assigned this Feb 5, 2026
@AkhileshNegi AkhileshNegi added the enhancement New feature or request label Feb 5, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2026

📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Migration
backend/app/alembic/versions/043_create_global_schema_and_languages_table.py
Creates global schema and global.languages table (id, label, label_locale, description, locale, is_active, inserted_at, updated_at), adds unique constraint on locale, inserts ~13 seed rows; downgrade drops constraint, table, and schema.
Models
backend/app/models/language.py, backend/app/models/__init__.py
Adds LanguageBase, Language (table in global schema), LanguagePublic, LanguagesPublic; re-exports Language* symbols in __init__.py (appears added twice).
CRUD
backend/app/crud/language.py
New helpers: get_languages(session, skip, limit) (filters active), get_language_by_id(session, id), get_language_by_locale(session, locale); module-level logger.
API Routes & Registration
backend/app/api/routes/languages.py, backend/app/api/main.py
New /languages router with list_languages and get_language endpoints using response models and docs; router registered in main API router.
API Docs
backend/app/api/docs/languages/list.md, backend/app/api/docs/languages/get.md
Adds documentation for listing languages and retrieving a language by ID.
Seed Data
backend/app/tests/seed_data/seed_data.py
Adds seed_languages(session) to create schema/table if needed and insert predefined languages; integrates into existing seeding flow (imports Language, uses text).
Tests
backend/app/tests/api/routes/test_languages.py
Adds tests for listing (with pagination), retrieval by ID, 404 handling, authenticated and unauthorized scenarios.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I dug a schema, tucked seeds in rows so neat,

Thirteen tongues now hum where migrations meet,
Models snug and routes say “come and see,”
Tests clap paws — a multilingual jubilee! 🎋

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Language: Initialization' clearly and specifically describes the main change: introducing language infrastructure and initialization.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch enhancement/language

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@AkhileshNegi AkhileshNegi linked an issue Feb 5, 2026 that may be closed by this pull request
@AkhileshNegi AkhileshNegi marked this pull request as ready for review February 5, 2026 09:03
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ensure updated_at refreshes on updates.
id is initialized as None, so the type should reflect that, and updated_at won’t change unless you explicitly update it elsewhere. Consider adding an onupdate hook 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
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

❌ Patch coverage is 94.02985% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
backend/app/tests/seed_data/seed_data.py 62.50% 6 Missing ⚠️
backend/app/crud/language.py 85.71% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@ProjectTech4DevAI ProjectTech4DevAI deleted a comment from coderabbitai bot Feb 5, 2026
@ProjectTech4DevAI ProjectTech4DevAI deleted a comment from coderabbitai bot Feb 5, 2026
@ProjectTech4DevAI ProjectTech4DevAI deleted a comment from coderabbitai bot Feb 5, 2026
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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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')", ),

  2. normalize the locale during insertion
    locale = locale.strip().lower()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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.
  2. Add unique constraint, thanks for suggestion
  3. 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.

@AkhileshNegi AkhileshNegi merged commit d721938 into main Feb 6, 2026
3 checks passed
@AkhileshNegi AkhileshNegi deleted the enhancement/language branch February 6, 2026 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Language: Initialization

2 participants