-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
101 lines (73 loc) · 3.2 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import datetime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy import Column, String, Integer, Boolean, ForeignKey, Date, DateTime, UniqueConstraint, BigInteger
# Base class for DB Classes
base = declarative_base()
class Channel(base):
__tablename__ = 'Channel'
id = Column(Integer, primary_key=True)
delete_commands = Column(Boolean)
delete_all = Column(Boolean)
discord_id = Column(BigInteger, unique=True)
discord_server_id = Column(BigInteger)
polls = relationship('Poll', cascade='all,delete')
def __init__(self, discord_id, discord_server_id, delete_commands=False, delete_all=False):
self.discord_id = discord_id
self.discord_server_id = discord_server_id
self.delete_commands = delete_commands
self.delete_all = delete_all
class Poll(base):
__tablename__ = 'Poll'
id = Column(Integer, primary_key=True)
created_datetime = Column(DateTime, default=datetime.datetime.utcnow)
poll_key = Column(String)
question = Column(String)
multiple_options = Column(Boolean)
only_numbers = Column(Boolean)
new_options = Column(Boolean)
allow_external = Column(Boolean)
closed = Column(Boolean)
closed_date = Column(Date)
channel_id = Column(Integer, ForeignKey('Channel.id'))
discord_server_id = Column(BigInteger)
discord_author_id = Column(BigInteger)
discord_message_id = Column(BigInteger, unique=True)
__table_args__ = (UniqueConstraint('poll_key', 'discord_server_id', name='poll_composite_id'),)
options = relationship('Option', cascade='all,delete')
def __init__(self, poll_key, discord_author_id, question, multiple_options, only_numbers, new_options,
allow_external, channel_id, discord_server_id):
self.poll_key = poll_key
self.discord_author_id = discord_author_id
self.question = question
self.multiple_options = multiple_options
self.only_numbers = only_numbers
self.new_options = new_options
self.allow_external = allow_external
self.channel_id = channel_id
self.discord_server_id = discord_server_id
self.closed = False
class Option(base):
__tablename__ = 'Option'
id = Column(Integer, primary_key=True)
position = Column(Integer)
option_text = Column(String)
locked = Column(Boolean)
poll_id = Column(Integer, ForeignKey('Poll.id'))
votes = relationship('Vote', cascade='all,delete')
def __init__(self, poll_id, position, option_text, locked=False):
self.poll_id = poll_id
self.position = position
self.option_text = option_text
self.locked = locked
class Vote(base):
__tablename__ = 'Vote'
id = Column(Integer, primary_key=True)
vote_datetime = Column(DateTime, default=datetime.datetime.utcnow)
discord_participant_id = Column(BigInteger)
participant_name = Column(String)
option_id = Column(Integer, ForeignKey('Option.id'))
def __init__(self, option_id, discord_participant_id, participant_name):
self.option_id = option_id
self.discord_participant_id = discord_participant_id
self.participant_name = participant_name