73 lines
2.1 KiB
Python
73 lines
2.1 KiB
Python
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"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
input_filename = Column(String, nullable=False)
|
|
thumbnail_filename = Column(String, nullable=False)
|
|
focal_length = Column(String)
|
|
aperture = Column(String)
|
|
shutter_speed = Column(String)
|
|
date_taken = Column(DateTime)
|
|
iso = Column(Integer)
|
|
width = Column(Integer)
|
|
height = Column(Integer)
|
|
highlight_color = Column(String)
|
|
orientation = Column(Integer)
|
|
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")
|
|
|
|
|
|
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)
|