voxpelli / node-connect-pg-simple

A simple, minimal PostgreSQL session store for Express
https://www.npmjs.com/package/connect-pg-simple
MIT License
234 stars 74 forks source link

createTableIfMissing is not working in version: 9.0.0 #296

Closed MuttakinHasib closed 10 months ago

MuttakinHasib commented 10 months ago

Hi @voxpelli

I am using connect-pg-simple: "9.0.0" with Nest.js but it is not creating the table sessions though it's working fine on connect-pg-simple: "8.0.0"

Here is my implementation:

import 'colors';
import { Logger, ValidationPipe } from '@nestjs/common';
import { ConfigurationService } from '@aafiyah/common';
import { NestFactory } from '@nestjs/core';
import passport from 'passport';
import session from 'express-session';
import PostgresStore from 'connect-pg-simple';
import helmet from 'helmet';

import { AppModule } from './app/app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

const pgSession = PostgresStore(session);

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const configurationService =
    app.get<ConfigurationService>(ConfigurationService);

  app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true }));

  app.enableCors({
    credentials: true,
    origin: [configurationService.WEB_URL],
  });

  app.use(helmet());

  // Swagger Setup
  const config = new DocumentBuilder()
    .setTitle(
      `${configurationService.APP_NAME} - An Islamic E-Commerce Web Application`
    )
    .setDescription(`${configurationService.APP_NAME} API description`)
    .setVersion('1.0')
    .addServer(configurationService.API_URL)
    .build();

  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('docs', app, document);

  app.use(
    session({
      secret: configurationService.SESSION_SECRET_KEY,
      resave: false,
      saveUninitialized: false,
      cookie: {
        maxAge: 30 * 24 * 60 * 60 * 1000, // 30 days
        httpOnly: true,
        sameSite: 'lax',
        secure: false,
      },
      store: new pgSession({
        conString: process.env.POSTGRES_DB_URL,
        createTableIfMissing: true,
      }),
    })
  );

  app.use(passport.initialize());
  app.use(passport.session());

  const port = process.env.PORT || 3333;
  await app.listen(port);

  Logger.log(
    `🚀 Alhamdulillah! Application is running on: ${await app.getUrl()}`.bgCyan
      .black
  );
}

bootstrap();
voxpelli commented 10 months ago

Which version of Node.js are you running? Lets get this fixed, inshallah (I'm studying arabic)

voxpelli commented 10 months ago

There are tests for this and they are passing on Node 16, 18 and 20 with three different versions of Postgres being tested with it: https://github.com/voxpelli/node-connect-pg-simple/blob/d7be62902c8c9e9450b9ea22da712d58d6fdfec8/test/integration/basic.spec.js#L42-L53

Which version of postgres are you running?

MuttakinHasib commented 10 months ago

Which version of Node.js are you running? Lets get this fixed, inshallah (I'm studying arabic)

In Sha Allah, Brother ❤️

I am using Node.js version: v20.9.0 and PostgresSQL: 16

MuttakinHasib commented 10 months ago

Jazakallahu Khairan ❤️ @voxpelli Now version: 9.0.1 is working fine.

voxpelli commented 10 months ago

Alhamdulillah @MuttakinHasib 🙏