-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
48 lines (41 loc) · 1.51 KB
/
models.py
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
from database import Base
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, Boolean, ARRAY, JSON, DateTime, func
from sqlalchemy.orm import backref, relationship
class Department(Base):
__tablename__ = 'department'
id = Column(Integer, primary_key=True)
name = Column(String)
class Role(Base):
__tablename__ = 'roles'
role_id = Column(Integer, primary_key=True)
name = Column(String)
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key=True)
name = Column(String)
# Use default=func.now() to set the default hiring time
# of an User to be the current time when an
# User record was created
hired_on = Column(DateTime, default=func.now())
department_id = Column(Integer, ForeignKey('department.id'))
role_id = Column(Integer, ForeignKey('roles.role_id'))
# Use cascade='delete,all' to propagate the deletion of a Department onto its Users
department = relationship(
Department,
backref=backref('users',
uselist=True,
cascade='delete,all'))
role = relationship(
Role,
backref=backref('roles',
uselist=True,
cascade='delete,all'))
class Dataset(Base):
__tablename__ = 'datasets'
id = Column(Integer, primary_key=True)
name = Column(String)
description = Column(String)
table_name = Column(String)
enabled = Column(Boolean)
created_at = Column(DateTime)
raw = Column(JSON)