Checkpoint, configuration can now be done through DB and the site. Server settings are still on the file system
This commit is contained in:
46
models.py
46
models.py
@ -1,11 +1,15 @@
|
||||
from sqlalchemy import create_engine, Column, Integer, String, DateTime, Float
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import (Column, DateTime, Float, Integer, String, Text,
|
||||
create_engine)
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class Photo(Base):
|
||||
__tablename__ = 'photos'
|
||||
__tablename__ = "photos"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
input_filename = Column(String, nullable=False)
|
||||
@ -19,16 +23,50 @@ class Photo(Base):
|
||||
height = Column(Integer)
|
||||
highlight_color = Column(String)
|
||||
orientation = Column(Integer)
|
||||
unique_key = Column(String(16), nullable=False) # Add this line
|
||||
unique_key = Column(String(16), nullable=False)
|
||||
|
||||
|
||||
class SiteConfig(Base):
|
||||
__tablename__ = "site_config"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
# Appearance
|
||||
site_title = Column(String, nullable=False, default="Spectra")
|
||||
accent_color = Column(String, nullable=False, default="#007bff")
|
||||
|
||||
# About
|
||||
author_name = Column(String, nullable=False, default="Your Name")
|
||||
author_location = Column(String, nullable=False, default="Your Location")
|
||||
profile_image = Column(String, nullable=False, default="/static/profile.jpg")
|
||||
bio = Column(
|
||||
Text,
|
||||
nullable=False,
|
||||
default="Write your bio in *markdown* here.\n\nSupports **multiple** paragraphs.",
|
||||
)
|
||||
|
||||
# Metadata
|
||||
updated_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
|
||||
engine = create_engine("sqlite:///photos.db")
|
||||
|
||||
engine = create_engine('sqlite:///photos.db')
|
||||
|
||||
def init_db():
|
||||
session = None
|
||||
try:
|
||||
Base.metadata.create_all(engine)
|
||||
# Create default site config if none exists
|
||||
session = Session()
|
||||
if not session.query(SiteConfig).first():
|
||||
session.add(SiteConfig())
|
||||
session.commit()
|
||||
except Exception as e:
|
||||
# Tables already exist, skip creation
|
||||
pass
|
||||
finally:
|
||||
if session:
|
||||
session.close()
|
||||
|
||||
|
||||
init_db()
|
||||
Session = sessionmaker(bind=engine)
|
||||
|
Reference in New Issue
Block a user