Automated Action 3e90deba20 Fix SQLite migration issues by removing non-constant defaults
Changes:
- Removed server_default with CURRENT_TIMESTAMP from User model (SQLite doesn't support non-constant defaults in ALTER TABLE)
- Updated migrations 002 and 003 to add datetime columns without server defaults
- Added manual timestamp updates using SQLite's datetime('now') function in migrations
- Modified User model to handle timestamps in Python code instead of database defaults
- Updated profile routes to manually set updated_at timestamps on profile changes
- Enhanced User model __init__ to set default timestamps for new users

This resolves the 'Cannot add a column with non-constant default' SQLite error
while maintaining proper timestamp functionality.
2025-06-24 19:53:37 +00:00

26 lines
978 B
Python

from sqlalchemy import Column, Integer, String, DateTime
from datetime import datetime
from app.db.base import Base
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True, index=True)
email = Column(String, unique=True, index=True, nullable=False)
password_hash = Column(String, nullable=False)
first_name = Column(String, nullable=True)
last_name = Column(String, nullable=True)
phone = Column(String, nullable=True)
bio = Column(String, nullable=True)
preferred_language = Column(String, default="en")
timezone = Column(String, default="UTC")
created_at = Column(DateTime(timezone=True), nullable=True)
updated_at = Column(DateTime(timezone=True), nullable=True)
def __init__(self, **kwargs):
super().__init__(**kwargs)
if not self.created_at:
self.created_at = datetime.utcnow()
if not self.updated_at:
self.updated_at = datetime.utcnow()