19 lines
781 B
TypeScript
19 lines
781 B
TypeScript
import type { Knex } from 'knex';
|
|
|
|
export async function up(knex: Knex): Promise<void> {
|
|
await knex.schema.createTable('login_attempts', (t) => {
|
|
t.string('id', 26).primary();
|
|
t.string('username', 64).notNullable();
|
|
t.specificType('ip_address', 'inet').notNullable();
|
|
t.boolean('success').notNullable().defaultTo(false);
|
|
t.timestamp('created_at', { useTz: true }).notNullable().defaultTo(knex.fn.now());
|
|
});
|
|
|
|
await knex.schema.raw('CREATE INDEX idx_login_attempts_username_created ON login_attempts(username, created_at)');
|
|
await knex.schema.raw('CREATE INDEX idx_login_attempts_ip_created ON login_attempts(ip_address, created_at)');
|
|
}
|
|
|
|
export async function down(knex: Knex): Promise<void> {
|
|
await knex.schema.dropTableIfExists('login_attempts');
|
|
}
|