Add foreign key constraint to enforce proper parent field in users table
This commit is contained in:
parent
1980ef2c08
commit
c2ee55e5e9
|
@ -39,6 +39,7 @@ def add_user(db, *, username, password, email, parent, status):
|
||||||
|
|
||||||
# Add the user into the database
|
# Add the user into the database
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
|
cursor.execute('PRAGMA foreign_keys = ON;') # Fail if we insert a user with bogus parent field
|
||||||
cursor.execute('INSERT INTO users VALUES (?, ?, ?, ?, ?, ?, ?);', (userid, parent, status, password, username, email, ''))
|
cursor.execute('INSERT INTO users VALUES (?, ?, ?, ?, ?, ?, ?);', (userid, parent, status, password, username, email, ''))
|
||||||
|
|
||||||
def initialize_users(db, admin_user, admin_password):
|
def initialize_users(db, admin_user, admin_password):
|
||||||
|
@ -58,7 +59,9 @@ def initialize_users(db, admin_user, admin_password):
|
||||||
username text NOT NULL,
|
username text NOT NULL,
|
||||||
email text NOT NULL,
|
email text NOT NULL,
|
||||||
|
|
||||||
comment text NOT NULL
|
comment text NOT NULL,
|
||||||
|
|
||||||
|
FOREIGN KEY(parent) REFERENCES users(id)
|
||||||
);''')
|
);''')
|
||||||
|
|
||||||
add_user(db, username = admin_user, password = admin_password, email = '', parent = None, status = userstatus.admin)
|
add_user(db, username = admin_user, password = admin_password, email = '', parent = None, status = userstatus.admin)
|
||||||
|
|
Loading…
Reference in New Issue