* Initial start of message DB

This commit is contained in:
Bryan Ashby 2015-06-25 23:19:32 -06:00
parent 32fdbab88d
commit 5a4c2a3043
1 changed files with 30 additions and 1 deletions

View File

@ -19,11 +19,16 @@ function getDatabasePath(name) {
function initializeDatabases() {
// :TODO: this will need to change if more DB's are added
dbs.user = new sqlite3.Database(getDatabasePath('user'));
dbs.message = new sqlite3.Database(getDatabasePath('message'));
dbs.user.serialize(function serialized() {
createUserTables();
createInitialValues();
});
dbs.message.serialize(function serialized() {
createMessageBaseTables();
});
}
function createUserTables() {
@ -65,6 +70,30 @@ function createUserTables() {
);
}
function createMessageBaseTables() {
dbs.message.run(
'CREATE TABLE IF NOT EXISTS message (' +
' message_id INTEGER PRIMARY KEY,' +
' area_id INTEGER NOT NULL,' +
' message_uuid VARCHAR(36) NOT NULL,' +
' reply_to_id INTEGER,' +
' to_user_name VARCHAR NOT NULL,' +
' from_user_name VARCHAR NOT NULL,' +
' subject,' + // FTS
' message,' + // FTS
' modified_timestamp DATETIME' +
');'
);
dbs.message.run(
'CREATE VIRTUAL TABLE message_fts USING fts4 (' +
' content="message",' +
' subject,' +
' message' +
');'
);
}
function createInitialValues() {
dbs.user.run(
'INSERT OR IGNORE INTO user_group ' +