Updated requirements. Added
This commit is contained in:
60
src/alpine_bits_python/db.py
Normal file
60
src/alpine_bits_python/db.py
Normal file
@@ -0,0 +1,60 @@
|
||||
from sqlalchemy import create_engine, Column, Integer, String, Date, Boolean, ForeignKey, DateTime
|
||||
from sqlalchemy.orm import declarative_base, relationship, sessionmaker
|
||||
import os
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
class Customer(Base):
|
||||
__tablename__ = 'customers'
|
||||
id = Column(Integer, primary_key=True)
|
||||
given_name = Column(String)
|
||||
surname = Column(String)
|
||||
name_prefix = Column(String)
|
||||
email_address = Column(String)
|
||||
phone = Column(String)
|
||||
email_newsletter = Column(Boolean)
|
||||
address_line = Column(String)
|
||||
city_name = Column(String)
|
||||
postal_code = Column(String)
|
||||
country_code = Column(String)
|
||||
gender = Column(String)
|
||||
birth_date = Column(String)
|
||||
language = Column(String)
|
||||
reservations = relationship('Reservation', back_populates='customer')
|
||||
|
||||
class Reservation(Base):
|
||||
__tablename__ = 'reservations'
|
||||
id = Column(Integer, primary_key=True)
|
||||
customer_id = Column(Integer, ForeignKey('customers.id'))
|
||||
start_date = Column(Date)
|
||||
end_date = Column(Date)
|
||||
num_adults = Column(Integer)
|
||||
num_children = Column(Integer)
|
||||
children_ages = Column(String) # comma-separated
|
||||
offer = Column(String)
|
||||
utm_comment = Column(String)
|
||||
created_at = Column(DateTime)
|
||||
customer = relationship('Customer', back_populates='reservations')
|
||||
|
||||
class HashedCustomer(Base):
|
||||
__tablename__ = 'hashed_customers'
|
||||
id = Column(Integer, primary_key=True)
|
||||
customer_id = Column(Integer)
|
||||
hashed_email = Column(String)
|
||||
hashed_phone = Column(String)
|
||||
hashed_name = Column(String)
|
||||
redacted_at = Column(DateTime)
|
||||
|
||||
|
||||
def get_engine():
|
||||
db_url = os.environ.get('DATABASE_URL')
|
||||
if db_url:
|
||||
return create_engine(db_url)
|
||||
# Default to local sqlite
|
||||
return create_engine('sqlite:///alpinebits.db')
|
||||
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=get_engine())
|
||||
|
||||
def init_db():
|
||||
engine = get_engine()
|
||||
Base.metadata.create_all(bind=engine)
|
||||
Reference in New Issue
Block a user