011_createZichanCategoryTable.ts 1.2 KB

123456789101112131415161718192021222324252627282930
  1. import type { MigrationLiveDefinition } from '@d8d-appcontainer/types'
  2. import { DeleteStatus, EnableStatus } from "../../client/share/types.ts";
  3. // 定义资产分类表迁移
  4. const createZichanCategoryTable: MigrationLiveDefinition = {
  5. name: "create_zichan_category_table",
  6. up: async (api) => {
  7. await api.schema.createTable('zichan_category', (table) => {
  8. table.increments('id').primary();
  9. table.string('name').notNullable().comment('分类名称');
  10. table.string('code').notNullable().unique().comment('分类编码');
  11. table.string('image_url').comment('分类图片');
  12. table.text('description').comment('分类描述');
  13. table.integer('is_enabled').defaultTo(EnableStatus.ENABLED).comment('是否启用 (0否 1是)');
  14. table.integer('is_deleted').defaultTo(DeleteStatus.NOT_DELETED).comment('是否被删除 (0否 1是)');
  15. table.timestamps(true, true);
  16. // 添加索引
  17. table.index('name');
  18. table.index('code');
  19. table.index('is_enabled');
  20. table.index('is_deleted');
  21. });
  22. },
  23. down: async (api) => {
  24. await api.schema.dropTable('zichan_category');
  25. }
  26. };
  27. export default createZichanCategoryTable;