update project
This commit is contained in:
18
apps/api/src/db/migrations/004_create_login_attempts.ts
Normal file
18
apps/api/src/db/migrations/004_create_login_attempts.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
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');
|
||||
}
|
||||
Reference in New Issue
Block a user