Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createTableIfMissing not working #200

Closed
vogler opened this issue Mar 8, 2021 · 17 comments
Closed

createTableIfMissing not working #200

vogler opened this issue Mar 8, 2021 · 17 comments
Assignees
Labels

Comments

@vogler
Copy link

vogler commented Mar 8, 2021

With the following

import connectPgSimple from 'connect-pg-simple';
const store = new (connectPgSimple(session))({createTableIfMissing: true} as any);
app.use(session({secret: '...', saveUninitialized: true, resave: false, store})); // defaults: httpOnly

I just get Failed to prune sessions: relation "session" does not exist on start and error: relation "session" does not exist on the first request.

Also, without as any I get Argument of type '{ createTableIfMissing: boolean; }' is not assignable to parameter of type 'PGStoreOptions'., so @types/connect-pg-simple seems to be outdated.

    "@types/connect-pg-simple": "^4.2.2",
    "connect-pg-simple": "^6.2.1",
    "express": "^4.17.1",
    "express-session": "^1.17.1",
    "typescript": "^4.1.5",
@voxpelli
Copy link
Owner

voxpelli commented Mar 9, 2021

The @types/connect-pg-simple should not be used, connect-pg-simple comes with its own types, I should look into getting that one deprecated.

Regarding main issue: I'll give it a look

@voxpelli voxpelli added the bug label Mar 9, 2021
@voxpelli voxpelli self-assigned this Mar 9, 2021
@voxpelli
Copy link
Owner

Sorry, I misspoke earlier, this is the one of my modules that actually doesn't yet generate its own types, see #155

I unfortunately also got sidetracked with an issue in another project that affected this project, so never got around to look at this in the weekend, sorry :/

@vogler
Copy link
Author

vogler commented Mar 18, 2021

No problem, I'm using https://github.com/kleydon/prisma-session-store - since I'm using Prisma anyway this is a better fit.

@prionkor
Copy link

prionkor commented May 6, 2021

Hello, I am having the same issue. Table is not created if I set createTableIfMissing as true

Code sample:

const PgSession = pgSession(session);
const pool = new Pool({
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASS,
  database: process.env.DB_NAME,
});

const store = new PgSession({
  createTableIfMissing: true,
  tableName: 'UserSessions',
  pool,
});

This flag is very useful for containerised environments.

@prionkor
Copy link

This bug makes the module unusable for my use cases. So I have to move to a new module. https://www.npmjs.com/package/connect-session-sequelize

@voxpelli
Copy link
Owner

@prionkor You can always set up the tables yourself, as shown in: https://github.com/voxpelli/node-connect-pg-simple#installation

The createTableIfMissing is a helper for those who can't.

I haven't got that much to go on here and I'm quite short on time at the moment so I would have to debug it deeper, and can't promise when I get time to do that.

But for future reference, for those who might arrive here: If createTableIfMissing doesn't work, just go with the default behavior of seting up the table yourself.

@lf94
Copy link

lf94 commented Jul 20, 2021

I too am hitting this bug. It just won't create itself.

@lf94
Copy link

lf94 commented Jul 20, 2021

The @types/connect-pg-simple should not be used, connect-pg-simple comes with its own types, I should look into getting that one deprecated.

I don't see its types declared anywhere? How are you using its types? (Looking at it, tsconfig points to index.js, and there is lots of annotations)

@lf94
Copy link

lf94 commented Jul 21, 2021

I suggest anyone coming to the repo try out https://www.npmjs.com/package/connect-session-sequelize instead, which is much more maintained. Nothing against voxpelli, they have done excellent work with connect-pg-simple. connect-pg-simple works but does not fit my need of TypeScript + auto creating the tables.

@voxpelli
Copy link
Owner

I don't see its types declared anywhere? How are you using its types? (Looking at it, tsconfig points to index.js, and there is lots of annotations)

I corrected myself earlier:

Sorry, I misspoke earlier, this is the one of my modules that actually doesn't yet generate its own types, see #155

Part of the reason is that this has to interact with express-session and for a long time those types were a bit so-so, making it hard to make something useful of it.

Apart from that: The focus of this module is to be the simplest postgres session module for express, thus depending on nothing but the pg module itself, enabling it to be used for most scenarios.

If one needs a more complex solution, then it’s correct to look for that in another solution.

If one believes this module fails in delivering what it intends to deliver, then let’s fix it 🙂

@lf94
Copy link

lf94 commented Jul 21, 2021

Well said 🙂 I want to heavily emphasize I am not implying anything negative about the work - it is once again, excellent. I would try to fix the mentioned issues myself, I just don't have the time either right now. 😆

@rafgk
Copy link

rafgk commented Aug 27, 2021

I am facing the same problem, I think the issue is with the sql script for the table creation. When running the table.sql in my database I get SQL Error [42P01]: ERROR: relation "session" does not exist.

I found that removing WITH (OIDS=FALSE); from the script fixes the issue and creates the table. I made the change in the project files but for some reason the error doesn't go away when launching the app without an existing table. I just figured it would be good to share this finding.

@vladtabachuk
Copy link

vladtabachuk commented Aug 29, 2021

Hello Mr. voxpelli as i understand for now we better use this?
`CREATE TABLE "session" (
"sid" varchar NOT NULL COLLATE "default",
"sess" json NOT NULL,
"expire" timestamp(6) NOT NULL
)
WITH (OIDS=FALSE);

ALTER TABLE "session" ADD CONSTRAINT "session_pkey" PRIMARY KEY ("sid") NOT DEFERRABLE INITIALLY IMMEDIATE;

CREATE INDEX "IDX_session_expire" ON "session" ("expire");
`

@aboqasem
Copy link

aboqasem commented Sep 6, 2021

Make sure you install connect-pg-simple@next everyone!

The @types/connect-pg-simple has the createTableIfMissing option, but latest connect-pg-simple (6.2.1) does not. Thus, you have to install the next version (^7.0.0-0).

@voxpelli
Copy link
Owner

voxpelli commented Sep 6, 2021

Thanks @aboqasem, I had forgotten that 7.0.0 was still in a prerelease state, I have now released a stable 7.0.0.

Sorry everyone for not thinking of this myself earlier. I'll close this issue as solved for now, if an update to 7.0.0 does not solve it, then comment and I can reopen.

@voxpelli voxpelli closed this as completed Sep 6, 2021
@JadedChara
Copy link

I've come across the same error as specified prior:

Failed to prune sessions: relation "sessions" does not exist
node:events:368
      throw er; // Unhandled 'error' event
      ^

I currently remain unable to implement database storage because of this.

@isaacgr
Copy link

isaacgr commented May 28, 2022

Thanks @aboqasem, I had forgotten that 7.0.0 was still in a prerelease state, I have now released a stable 7.0.0.

Sorry everyone for not thinking of this myself earlier. I'll close this issue as solved for now, if an update to 7.0.0 does not solve it, then comment and I can reopen.

I'm seeing this with 7.0.0. Once created manually theres no issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants