connect-session-knex
connect-session-knex copied to clipboard
Add example Knex Migration to docs
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');
};
FYI it seems to be doing okay for me so far 👍
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
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');
}