Skip to content

v0.2.0 - Migrate app to use SQLModel#1

Merged
dyka3773 merged 3 commits intomainfrom
develop
Nov 12, 2025
Merged

v0.2.0 - Migrate app to use SQLModel#1
dyka3773 merged 3 commits intomainfrom
develop

Conversation

@dyka3773
Copy link
Copy Markdown
Member

🧩 Summary

  • Migrate from pydantic to sqlmodel
  • Fix environment variables example file
  • Correct timestamp insertions

✅ Changes

  • Feature / enhancement
  • Bug fix
  • Documentation
  • Refactor / maintenance

@dyka3773 dyka3773 self-assigned this Nov 12, 2025
Copilot AI review requested due to automatic review settings November 12, 2025 22:54
@dyka3773 dyka3773 added the enhancement New feature or request label Nov 12, 2025
@dyka3773 dyka3773 merged commit 4fd9903 into main Nov 12, 2025
4 of 6 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates the application from Pydantic-only models to SQLModel for database integration, enabling proper persistence of telescope observations and user data. The migration introduces database models with proper relationships, fixes timestamp handling with a new UTC utility, and corrects environment variable examples.

Key changes:

  • Replaced Pydantic schemas with SQLModel-based models for User and Observation entities with proper database table definitions
  • Implemented database persistence logic in the telescope router with user and observation creation
  • Added UTC timestamp utility function to standardize time handling across the application

Reviewed Changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/backend/utils/time_utils.py New utility for generating naive UTC timestamps
src/backend/schemas.py Removed legacy Pydantic-only schema definitions
src/backend/routers/web.py Updated import path from schemas to models
src/backend/routers/telescope.py Implemented database persistence for observations and users
src/backend/models/user.py New SQLModel definition for User with database table mapping
src/backend/models/responses.py Extracted StatusResponse as standalone response model
src/backend/models/observation.py New SQLModel definition for Observation with database table mapping
src/backend/models/init.py New models package exports
src/backend/main.py Added table creation on startup and improved root endpoint
src/backend/database.py Migrated from SQLAlchemy DeclarativeBase to SQLModel
src/backend/configs/config.py Added create_tables_on_startup configuration option
pyproject.toml Added sqlmodel dependency and fixed backend script path
.env.example Corrected database name and CORS settings format

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +109 to +111
else:
# Convert database model to read schema
return ObservationRead.model_validate(db_observation)
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

The else block should not be used here as it will never execute. The return statement should be at the same indentation level as the try block (after line 108), not inside an else clause. The current structure means the return will only happen if no exception occurs, but since exceptions are raised and re-raised, this else will execute in the success path. However, the indentation suggests this should be outside the try-except entirely.

Suggested change
else:
# Convert database model to read schema
return ObservationRead.model_validate(db_observation)
# Convert database model to read schema
return ObservationRead.model_validate(db_observation)

Copilot uses AI. Check for mistakes.
# Import models to register them with SQLModel
from backend.models import Observation, User # noqa: F401, PLC0415

await conn.run_sync(SQLModel.metadata.create_all, tables=[Observation, User])
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

The tables parameter expects table objects, not model classes. This should be SQLModel.metadata.create_all without the tables parameter to create all tables, or pass the actual table objects via [User.__table__, Observation.__table__] if you want to create specific tables only.

Suggested change
await conn.run_sync(SQLModel.metadata.create_all, tables=[Observation, User])
await conn.run_sync(SQLModel.metadata.create_all, tables=[Observation.__table__, User.__table__])

Copilot uses AI. Check for mistakes.
CORS_ALLOW_METHODS=*
CORS_ALLOW_HEADERS=*
CORS_ALLOW_METHODS=["*"]
CORS_ALLOW_HEADERS=["*"]
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

Environment variable values should not use JSON array syntax. These should be comma-separated strings like CORS_ORIGINS=http://localhost:4200 or if multiple values are needed: CORS_ORIGINS=http://localhost:4200,http://localhost:3000. The square brackets and quotes will be interpreted as literal string characters, not as array notation.

Suggested change
CORS_ALLOW_HEADERS=["*"]
CORS_ALLOW_HEADERS=*

Copilot uses AI. Check for mistakes.
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.

2 participants