Files
d8d-admin-mobile-starter-pu…/server/migrations/002_createLoginHistoryTable.ts
2025-05-13 13:22:50 +00:00

26 lines
885 B
TypeScript

import type { MigrationLiveDefinition } from '@d8d-appcontainer/types'
const createLoginHistoryTable: MigrationLiveDefinition = {
name: "create_login_history_table",
up: async (api) => {
await api.schema.createTable('login_history', (table) => {
table.increments('id').primary()
table.integer('user_id').unsigned().references('id').inTable('users').onDelete('CASCADE')
table.timestamp('login_time').defaultTo(api.fn.now())
table.string('ip_address')
table.text('user_agent')
table.decimal('longitude', 10, 6).nullable()
table.decimal('latitude', 10, 6).nullable()
table.string('location_name').nullable()
// 添加索引
table.index('user_id');
table.index('login_time');
})
},
down: async (api) => {
await api.schema.dropTable('login_history')
}
}
export default createLoginHistoryTable;