Skip to content

fix automatic database creation in Docker containers#29

Merged
ozanunal0 merged 1 commit intomainfrom
dev
Jul 9, 2025
Merged

fix automatic database creation in Docker containers#29
ozanunal0 merged 1 commit intomainfrom
dev

Conversation

@ozanunal0
Copy link
Copy Markdown
Owner

  • Import APIKey model in database.py to register with SQLModel metadata
  • Update docker-compose.yml to mount full project directory (.:/code)
  • Remove version specification and add shared network configuration
  • Database file now created automatically during container startup
  • Eliminates need for manual database initialization

- Import APIKey model in database.py to register with SQLModel metadata
- Update docker-compose.yml to mount full project directory (.:/code)
- Remove version specification and add shared network configuration
- Database file now created automatically during container startup
- Eliminates need for manual database initialization

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 9, 2025 14:50
@ozanunal0 ozanunal0 merged commit 9129746 into main Jul 9, 2025
6 of 12 checks passed
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jul 9, 2025

Copy link
Copy Markdown

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 fixes automatic database creation in Docker containers by ensuring all SQLModel tables are properly registered and adjusting the Docker volume mounting strategy. The changes eliminate the need for manual database initialization when running the application in containers.

  • Import APIKey model in database.py to register it with SQLModel metadata for automatic table creation
  • Update Docker Compose configuration to mount the full project directory and add shared networking
  • Remove deprecated version specification from docker-compose.yml

Reviewed Changes

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

File Description
app/database.py Adds APIKey model import to ensure table registration with SQLModel metadata
docker-compose.yml Updates volume mounting strategy, removes version spec, and adds shared network configuration

Comment thread docker-compose.yml
- .env
volumes:
- ./gateway.db:/code/gateway.db
- .:/code
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

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

Mounting the entire project directory (.:/code) into the container can expose sensitive files and create security risks. Consider mounting only necessary files or using a .dockerignore file to exclude sensitive content.

Copilot uses AI. Check for mistakes.
Comment thread docker-compose.yml

networks:
shared-app-network:
external: true
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

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

Using an external network requires manual creation before running docker-compose. Consider using a regular network definition or document the network creation requirement in the deployment instructions.

Suggested change
external: true
driver: bridge

Copilot uses AI. Check for mistakes.
Comment thread app/database.py
Comment on lines +4 to +5
# Import all models to register them with SQLModel metadata
from app.db_models.api_key import APIKey
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

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

[nitpick] Importing models solely for registration creates implicit dependencies that may be overlooked during refactoring. Consider using a dedicated model registry function or importing all models in a centralized location.

Suggested change
# Import all models to register them with SQLModel metadata
from app.db_models.api_key import APIKey
# Function to register all models with SQLModel metadata
def register_models():
from app.db_models.api_key import APIKey
# Add other models here as needed

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants