from app import db, ma from datetime import datetime class CompanyPrice(db.Model): __tablename__ = "company_prices" __table_args__ = {"schema": "public"} id = db.Column(db.Integer, primary_key=True, autoincrement=True) company_name = db.Column(db.String(255), nullable=False, index=True) town = db.Column(db.String(100), nullable=True) price_decimal = db.Column(db.Numeric(6, 3), nullable=False) scrape_date = db.Column(db.Date, nullable=False, index=True) zone = db.Column(db.String(50), nullable=False, default="zone10", index=True) created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) def to_dict(self): return { "id": self.id, "company_name": self.company_name, "town": self.town, "price": float(self.price_decimal) if self.price_decimal else None, "date": self.scrape_date.isoformat() if self.scrape_date else None, "zone": self.zone } class CompanyPriceSchema(ma.SQLAlchemyAutoSchema): class Meta: model = CompanyPrice