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

Add example Knex Migration to docs #77

Closed
thirionlogan opened this issue Jan 10, 2021 · 3 comments
Closed

Add example Knex Migration to docs #77

thirionlogan opened this issue Jan 10, 2021 · 3 comments

Comments

@thirionlogan
Copy link

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
Copy link
Author

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

@mceachen
Copy link

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

@ZeRego
Copy link

ZeRego commented Jul 22, 2021

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');
}

@gx0r gx0r closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants