connect-session-knex icon indicating copy to clipboard operation
connect-session-knex copied to clipboard

Add example Knex Migration to docs

Open thirionlogan opened this issue 4 years ago • 3 comments

It would be very useful to provide an example knex migration creating a sessions table in the documentation. I am not sure if I have this right, but this is what I have so far:

exports.up = (knex) => {
  return knex.schema
    .createTable('sessions', (table) => {
      table.string('sid').notNullable();
      table.json('sess').notNullable();
      table.timestamp('expired').notNullable();
    });
};

exports.down = (knex) => {
  return knex.schema.dropTableIfExists('sessions');
};

thirionlogan avatar Jan 10 '21 08:01 thirionlogan

FYI it seems to be doing okay for me so far 👍

thirionlogan avatar Jan 10 '21 08:01 thirionlogan

FWIW, you're missing an index on the sess and expired columns, and a primary key index on sid.

index.js should be already doing this for you: https://github.com/ggcode1/connect-session-knex/blob/master/lib/index.js#L103

mceachen avatar Feb 13 '21 03:02 mceachen

Example with indexes and in TS

import { Knex } from 'knex';

export async function up(knex: Knex): Promise<void> {
    return knex.schema.createTable('sessions', (table) => {
        table.string('sid').notNullable().primary();
        table.json('sess').notNullable();
        table.timestamp('expired').notNullable().index();
    });
}

export async function down(knex: Knex): Promise<void> {
    return knex.schema.dropTableIfExists('sessions');
}

ZeRego avatar Jul 22 '21 10:07 ZeRego