2
0

012_createDateNotesTable.ts 828 B

123456789101112131415161718192021222324
  1. import type { MigrationLiveDefinition } from '@d8d-appcontainer/types'
  2. const createDateNotesTable: MigrationLiveDefinition = {
  3. name: "create_date_notes",
  4. up: async (api) => {
  5. await api.schema.createTable('date_notes', (table) => {
  6. table.increments("id").primary();
  7. table.string("code").notNullable().comment("股票代码");
  8. table.timestamp("note_date").notNullable().comment("备注日期");
  9. table.string("note").notNullable().comment("备注内容");
  10. table.timestamps(true, true);
  11. // 添加索引
  12. table.index("code");
  13. table.index("note_date");
  14. table.unique(["code", "note_date"]); // 确保同一只股票同一天只有一条备注
  15. });
  16. },
  17. down: async (api) => {
  18. await api.schema.dropTable('date_notes');
  19. }
  20. }
  21. export default createDateNotesTable;