增加 迁移回滚功能实现
This commit is contained in:
26
server/migrations/002_createLoginHistoryTable.ts
Normal file
26
server/migrations/002_createLoginHistoryTable.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user