-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
50 lines (45 loc) · 1.62 KB
/
Copy pathdatabase.py
File metadata and controls
50 lines (45 loc) · 1.62 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from sqlalchemy import create_engine, Column, Integer, String, Text, ForeignKey, DateTime
from sqlalchemy.orm import declarative_base, sessionmaker
from contextlib import contextmanager
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DATABASE_URL = f"sqlite:///{os.path.join(BASE_DIR, 'graphguard.db')}"
engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False})
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
class DbToken(Base):
__tablename__ = "tokens"
id = Column(Integer, primary_key=True, index=True)
username = Column(String, index=True)
client_id = Column(String)
resource = Column(String)
access_token = Column(Text)
refresh_token = Column(Text)
id_token = Column(Text)
expires_on = Column(Integer)
created_at = Column(DateTime)
user_agent = Column(String)
forwarded_ip = Column(String)
class DbDeviceCode(Base):
__tablename__ = "device_codes"
id = Column(Integer, primary_key=True, index=True)
device_code = Column(String, unique=True, index=True)
user_code = Column(String)
verification_uri = Column(String)
expires_in = Column(Integer)
interval = Column(Integer)
message = Column(Text)
status = Column(String) # 'pending', 'success', 'expired', 'denied'
client_id = Column(String)
resource = Column(String)
created_at = Column(DateTime)
user_agent = Column(String)
forwarded_ip = Column(String)
# Create tables
Base.metadata.create_all(bind=engine)
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()