002_createLoginHistoryTable.ts 885 B

1234567891011121314151617181920212223242526
  1. import type { MigrationLiveDefinition } from '@d8d-appcontainer/types'
  2. const createLoginHistoryTable: MigrationLiveDefinition = {
  3. name: "create_login_history_table",
  4. up: async (api) => {
  5. await api.schema.createTable('login_history', (table) => {
  6. table.increments('id').primary()
  7. table.integer('user_id').unsigned().references('id').inTable('users').onDelete('CASCADE')
  8. table.timestamp('login_time').defaultTo(api.fn.now())
  9. table.string('ip_address')
  10. table.text('user_agent')
  11. table.decimal('longitude', 10, 6).nullable()
  12. table.decimal('latitude', 10, 6).nullable()
  13. table.string('location_name').nullable()
  14. // 添加索引
  15. table.index('user_id');
  16. table.index('login_time');
  17. })
  18. },
  19. down: async (api) => {
  20. await api.schema.dropTable('login_history')
  21. }
  22. }
  23. export default createLoginHistoryTable;