增加 迁移回滚功能实现
This commit is contained in:
37
server/migrations/005_createFileLibraryTable.ts
Normal file
37
server/migrations/005_createFileLibraryTable.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { MigrationLiveDefinition } from '@d8d-appcontainer/types'
|
||||
import { EnableStatus, DeleteStatus } from '../../client/share/types.ts'
|
||||
|
||||
const createFileLibraryTable: MigrationLiveDefinition = {
|
||||
name: "create_file_library_table",
|
||||
up: async (api) => {
|
||||
await api.schema.createTable('file_library', (table) => {
|
||||
table.increments('id').primary();
|
||||
table.string('file_name').notNullable().comment('文件名称');
|
||||
table.string('original_filename').comment('原始文件名');
|
||||
table.string('file_path').notNullable().comment('文件路径');
|
||||
table.string('file_type').comment('文件类型');
|
||||
table.integer('file_size').unsigned().comment('文件大小(字节)');
|
||||
table.integer('uploader_id').unsigned().references('id').inTable('users').onDelete('SET NULL').comment('上传用户ID');
|
||||
table.string('uploader_name').comment('上传者名称');
|
||||
table.integer('category_id').unsigned().references('id').inTable('file_categories').onDelete('SET NULL').comment('文件分类');
|
||||
table.string('tags').comment('文件标签');
|
||||
table.text('description').comment('文件描述');
|
||||
table.integer('download_count').defaultTo(0).comment('下载次数');
|
||||
table.integer('is_disabled').defaultTo(EnableStatus.DISABLED).comment('是否禁用 (0否 1是)');
|
||||
table.integer('is_deleted').defaultTo(DeleteStatus.NOT_DELETED).comment('是否被删除 (0否 1是)');
|
||||
table.timestamps(true, true);
|
||||
|
||||
// 添加索引
|
||||
table.index('file_name');
|
||||
table.index('file_type');
|
||||
table.index('category_id');
|
||||
table.index('uploader_id');
|
||||
table.index('is_deleted');
|
||||
});
|
||||
},
|
||||
down: async (api) => {
|
||||
await api.schema.dropTable('file_library');
|
||||
}
|
||||
}
|
||||
|
||||
export default createFileLibraryTable;
|
||||
Reference in New Issue
Block a user