*Start user groups concept

This commit is contained in:
Bryan Ashby 2015-05-10 21:39:39 -06:00
parent 62da937bf0
commit ca3453ecfb
3 changed files with 54 additions and 56 deletions

View file

@ -20,8 +20,9 @@ function initializeDatabases() {
// :TODO: this will need to change if more DB's are added
dbs.user = new sqlite3.Database(getDatabasePath('user'));
dbs.user.serialize(function onSerialized() {
dbs.user.serialize(function serialized() {
createUserTables();
createInitialValues();
});
}
@ -45,4 +46,28 @@ function createUserTables() {
' FOREIGN KEY(user_id) REFERENCES user(id) ON DELETE CASCADE' +
');'
);
dbs.user.run(
'CREATE TABLE IF NOT EXISTS user_group (' +
' group_id INTEGER PRIMARY KEY,' +
' group_name VARCHAR NOT NULL,' +
' UNIQUE(group_name)' +
');'
);
dbs.user.run(
'CREATE TABLE IF NOT EXISTS user_group_member (' +
' group_id INTEGER NOT NULL,' +
' user_id INTEGER NOT NULL,' +
' UNIQUE(group_id, user_id),' +
' FOREIGN KEY(group_id) REFERENCES user_group(group_id) ON DELETE CASCADE' +
');'
);
}
function createInitialValues() {
dbs.user.run(
'INSERT OR IGNORE INTO user_group ' +
'VALUES(1, "users");'
);
}