增加 迁移回滚功能实现
This commit is contained in:
25
server/migrations/008_createMessagesTable.ts
Normal file
25
server/migrations/008_createMessagesTable.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import type { MigrationLiveDefinition } from '@d8d-appcontainer/types'
|
||||
|
||||
const createMessagesTable: MigrationLiveDefinition = {
|
||||
name: "create_messages_table",
|
||||
up: async (api) => {
|
||||
await api.schema.createTable('messages', (table) => {
|
||||
table.increments('id').primary().comment('消息ID');
|
||||
table.string('title').notNullable().comment('消息标题');
|
||||
table.text('content').notNullable().comment('消息内容');
|
||||
table.enum('type', ['system', 'private', 'announce']).notNullable().comment('消息类型');
|
||||
table.integer('sender_id').unsigned().references('id').inTable('users').onDelete('SET NULL').comment('发送者ID');
|
||||
table.string('sender_name').comment('发送者名称');
|
||||
table.timestamps(true, true);
|
||||
|
||||
// 添加索引
|
||||
table.index('type');
|
||||
table.index('sender_id');
|
||||
});
|
||||
},
|
||||
down: async (api) => {
|
||||
await api.schema.dropTable('messages');
|
||||
}
|
||||
}
|
||||
|
||||
export default createMessagesTable;
|
||||
Reference in New Issue
Block a user