25 lines
967 B
TypeScript
25 lines
967 B
TypeScript
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; |