增加 迁移回滚功能实现

This commit is contained in:
yourname
2025-05-13 13:22:50 +00:00
parent 976e79894a
commit 8530fb5da6
13 changed files with 649 additions and 529 deletions

View 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;