changed sql

- added create tables to anonymous block
pull/1/head
Trivernis 5 years ago
parent bf79df08ad
commit bf3be7d129

@ -79,6 +79,15 @@ export class QueryHelper {
this.pool = pgPool; this.pool = pgPool;
} }
/**
* Async init function
*/
public async init() {
await this.pool.connect();
await this.createTables();
await this.updateTableDefinitions();
}
/** /**
* creates all tables needed if a filepath was given with the constructor * creates all tables needed if a filepath was given with the constructor
*/ */

@ -42,8 +42,12 @@ namespace dataaccess {
* Initializes everything that needs to be initialized asynchronous. * Initializes everything that needs to be initialized asynchronous.
*/ */
export async function init() { export async function init() {
await queryHelper.createTables(); try {
await queryHelper.updateTableDefinitions(); await queryHelper.init();
} catch (err) {
globals.logger.error(err.message);
globals.logger.debug(err.stack);
}
} }
/** /**

@ -49,6 +49,7 @@ DO $$ BEGIN
END$$; END$$;
-- create tables -- create tables
DO $$ BEGIN
CREATE TABLE IF NOT EXISTS "user_sessions" ( CREATE TABLE IF NOT EXISTS "user_sessions" (
"sid" varchar NOT NULL, "sid" varchar NOT NULL,
@ -126,3 +127,5 @@ CREATE TABLE IF NOT EXISTS requests (
type requesttype DEFAULT 'FRIENDREQUEST', type requesttype DEFAULT 'FRIENDREQUEST',
PRIMARY KEY (sender, receiver, type) PRIMARY KEY (sender, receiver, type)
); );
END $$;

Loading…
Cancel
Save