-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
44 lines (30 loc) · 1.23 KB
/
Copy pathmodels.py
File metadata and controls
44 lines (30 loc) · 1.23 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
import os
from sqlalchemy import Column, String, DateTime, Boolean, Text, create_engine
from sqlalchemy.orm import DeclarativeBase, sessionmaker
from datetime import datetime, timezone
class Base(DeclarativeBase):
pass
def utc_now():
return datetime.now(timezone.utc)
class Consent(Base):
__tablename__ = "consents"
id = Column(String, primary_key=True)
user_id = Column(String, nullable=False, index=True)
purpose = Column(String, nullable=False)
granted = Column(Boolean, default=True)
granted_at = Column(DateTime, default=utc_now)
withdrawn_at = Column(DateTime, nullable=True)
consent_metadata = Column("metadata", Text, nullable=True)
class AuditLog(Base):
__tablename__ = "audit_logs"
id = Column(String, primary_key=True)
user_id = Column(String, nullable=False, index=True)
action = Column(String, nullable=False)
timestamp = Column(DateTime, default=utc_now)
details = Column(Text, nullable=True)
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///dpdp_consent.db")
connect_args = {}
if DATABASE_URL.startswith("sqlite"):
connect_args["check_same_thread"] = False
engine = create_engine(DATABASE_URL, connect_args=connect_args)
SessionLocal = sessionmaker(bind=engine)