Skip to content

Node.js based forum software built for the modern web

Only run the DDL for session storage on the primary instance. (#6788)

Ben Lubar11b655163ea8
diff --git a/src/database/postgres.js b/src/database/postgres.js
index df1ccf8784..f06c962c22 100644
--- a/src/database/postgres.js
+++ b/src/database/postgres.js
@@ -364,6 +364,21 @@ postgresModule.initSessionStore = function (callback) {
return callback();
}
+ function done() {
+ sessionStore = require('connect-pg-simple')(session);
+ postgresModule.sessionStore = new sessionStore({
+ pool: db,
+ ttl: ttl,
+ pruneSessionInterval: nconf.get('isPrimary') === 'true' ? 60 : false,
+ });
+
+ callback();
+ }
+
+ if (nconf.get('isPrimary') !== 'true') {
+ return done();
+ }
+
db.query(`
CREATE TABLE IF NOT EXISTS "session" (
"sid" CHAR(32) NOT NULL
@@ -382,14 +397,7 @@ ALTER TABLE "session"
return callback(err);
}
- sessionStore = require('connect-pg-simple')(session);
- postgresModule.sessionStore = new sessionStore({
- pool: db,
- ttl: ttl,
- pruneSessionInterval: nconf.get('isPrimary') === 'true' ? 60 : false,
- });
-
- callback();
+ done();
});
};