-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
34 lines (24 loc) · 1.04 KB
/
Copy pathdatabase.py
File metadata and controls
34 lines (24 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey, DateTime, Boolean, Float, func
from sqlalchemy.orm import sessionmaker, declarative_base
from dotenv import load_dotenv
import os
load_dotenv()
DATABASE_URL = os.getenv("DATABASE_URL")
engine = create_engine(DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
class URL(Base):
__tablename__ = "urls"
id = Column(Integer, primary_key=True, index=True)
address = Column(String, unique=True, index=True)
created_at = Column(DateTime, default=func.now() ,nullable=True)
from_ip = Column(String,nullable=True)
class HealthCheck(Base):
__tablename__ = "health_checks"
id = Column(Integer, primary_key=True, index=True)
url_id = Column(Integer, ForeignKey("urls.id"))
timestamp = Column(DateTime, default=func.now())
is_up = Column(Boolean)
response_time = Column(Float, nullable=True)
status_code = Column(Integer, nullable=True)
Base.metadata.create_all(bind=engine)