Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions db/migrations/20260226000000_create_sessions_table.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Migration to create the sessions table for token revocation and session management.
*/
exports.up = async function up(knex) {
await knex.schema.createTable('sessions', (table) => {
table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()'))
table.string('user_id', 255).notNullable()
table.string('jti', 255).notNullable().unique()
table.timestamp('revoked_at', { useTz: true }).nullable()
table.timestamp('expires_at', { useTz: true }).notNullable()
table.timestamp('created_at', { useTz: true }).notNullable().defaultTo(knex.fn.now())
})

await knex.schema.alterTable('sessions', (table) => {
table.index(['user_id'], 'idx_sessions_user_id')
table.index(['jti'], 'idx_sessions_jti')
})
}

exports.down = async function down(knex) {
await knex.schema.dropTableIfExists('sessions')
}
45 changes: 45 additions & 0 deletions db/migrations/20260226010000_create_enterprise_models.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Migration for Enterprise Organization & Team Models
*/
exports.up = async function up(knex) {
// Organizations table
await knex.schema.createTable('organizations', (table) => {
table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()'))
table.string('name', 255).notNullable()
table.string('slug', 255).notNullable().unique()
table.jsonb('metadata').nullable()
table.timestamp('created_at', { useTz: true }).notNullable().defaultTo(knex.fn.now())
table.timestamp('updated_at', { useTz: true }).notNullable().defaultTo(knex.fn.now())
})

// Teams table
await knex.schema.createTable('teams', (table) => {
table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()'))
table.string('name', 255).notNullable()
table.string('slug', 255).notNullable()
table.uuid('organization_id').notNullable().references('id').inTable('organizations').onDelete('CASCADE')
table.jsonb('metadata').nullable()
table.timestamp('created_at', { useTz: true }).notNullable().defaultTo(knex.fn.now())
table.timestamp('updated_at', { useTz: true }).notNullable().defaultTo(knex.fn.now())

table.unique(['organization_id', 'slug'])
})

// Memberships table
await knex.schema.createTable('memberships', (table) => {
table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()'))
table.string('user_id', 255).notNullable() // Assuming user_id is string from existing auth
table.uuid('organization_id').notNullable().references('id').inTable('organizations').onDelete('CASCADE')
table.uuid('team_id').nullable().references('id').inTable('teams').onDelete('CASCADE')
table.string('role', 50).notNullable().defaultTo('member')
table.timestamp('created_at', { useTz: true }).notNullable().defaultTo(knex.fn.now())

table.unique(['user_id', 'organization_id', 'team_id'])
})
}

exports.down = async function down(knex) {
await knex.schema.dropTableIfExists('memberships')
await knex.schema.dropTableIfExists('teams')
await knex.schema.dropTableIfExists('organizations')
}
Loading