Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Database(object):
- def __int__(self):
- return self
- connection = sqlite3.connect("users.db", timeout=10)
- connection.execute("PRAGMA foreign_keys = ON;")
- cursor = connection.cursor()
- connection.isolation_level = ''
- print("database connected")
- cursor.execute('''
- CREATE TABLE IF NOT EXISTS users (
- id integer PRIMARY KEY,
- login text NOT NULL UNIQUE,
- password text NOT NULL
- )
- ''')
- cursor.execute('''
- CREATE TABLE IF NOT EXISTS rooms (
- id integer PRIMARY KEY,
- password text NOT NULL,
- owner_id integer NOT NULL,
- FOREIGN KEY (owner_id) REFERENCES users (id)
- )
- ''')
- cursor.execute('''
- CREATE TABLE IF NOT EXISTS users_rooms (
- id integer PRIMARY KEY,
- room_id integer NOT NULL,
- user_id integer NOT NULL,
- FOREIGN KEY (user_id) REFERENCES users (id),
- FOREIGN KEY (room_id) REFERENCES rooms (id),
- UNIQUE(room_id, user_id)
- )
- ''')
- cursor.execute('''
- CREATE TABLE IF NOT EXISTS poll (
- id integer PRIMARY KEY,
- subject_id integer NOT NULL,
- task_id integer NOT NULL,
- user_id integer NOT NULL,
- vote float NOT NULL,
- FOREIGN KEY (task_id) REFERENCES tasks (id),
- FOREIGN KEY (user_id) REFERENCES users (id)
- )
- ''')
- cursor.execute('''
- CREATE TABLE IF NOT EXISTS tasks (
- id integer PRIMARY KEY,
- room_id integer NOT NULL,
- subject text NOT NULL,
- FOREIGN KEY (room_id) references rooms (id)
- )
- ''')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement