-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
27 lines (25 loc) · 704 Bytes
/
database.py
File metadata and controls
27 lines (25 loc) · 704 Bytes
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
import sqlite3
DB_NAME = 'orguser.db'
def init_db():
conn = sqlite3.connect(DB_NAME)
c = conn.cursor()
# Organizations table
c.execute('''
CREATE TABLE IF NOT EXISTS organizations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
address TEXT
)
''')
# Users table
c.execute('''
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT NOT NULL UNIQUE,
organization_id INTEGER NOT NULL,
FOREIGN KEY(organization_id) REFERENCES organizations(id)
)
''')
conn.commit()
conn.close()