-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb_initialization.py
101 lines (92 loc) · 2.99 KB
/
db_initialization.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
# Copyright 2011-2014 orabot Developers
#
# This file is part of orabot, which is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
def start(self):
conn, cur = self.db_data()
print(("*** [%s] Creating database") % (self.irc_host))
users(conn, cur)
user_channel(conn, cur)
later(conn, cur)
pingme(conn, cur)
activity(conn, cur)
cur.close()
print(("*** [%s] Creating database completed") % (self.irc_host))
def users(conn, cur):
sql = """CREATE TABLE users (
"uid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
"user" varchar(30) NOT NULL,
"date" date,
"state" bool NOT NULL DEFAULT 0,
"last_message" varchar(1024),
"last_message_channel" varchar(30)
)
"""
cur.execute(sql)
conn.commit()
def user_channel(conn, cur):
sql = """CREATE TABLE user_channel (
"uid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
"user" VARCHAR NOT NULL,
"channel" VARCHAR NOT NULL,
"status" VARCHAR
)
"""
cur.execute(sql)
conn.commit()
def later(conn, cur):
sql = """CREATE TABLE later (
"uid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
"sender" varchar(30) NOT NULL,
"reciever" varchar(30) NOT NULL,
"channel" varchar(30) NOT NULL,
"date" date NOT NULL,
"message" varchar(1000) NOT NULL
)
"""
cur.execute(sql)
conn.commit()
def pingme(conn, cur):
sql = """CREATE TABLE "pingme" (
"uid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
"who" VARCHAR NOT NULL ,
"users_back" VARCHAR NOT NULL
)
"""
cur.execute(sql)
conn.commit()
def activity(conn, cur):
sql = """CREATE TABLE "activity" (
"uid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
"user" VARCHAR NOT NULL,
"act" VARCHAR NOT NULL,
"date_time" date NOT NULL,
"channel" VARCHAR
)
"""
cur.execute(sql)
conn.commit()
def voting(conn, cur):
sql = """CREATE TABLE "voting" (
"uid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
"topic" VARCHAR NOT NULL,
"active" bool NOT NULL DEFAULT 0,
"positive" INTEGER DEFAULT 0,
"negative" INTEGER DEFAULT 0,
"initialized_by" VARCHAR NOT NULL,
"date_activated" DATE,
"users_voted" VARCHAR
)
"""
cur.execute(sql)
conn.commit()