import { useContextKey } from '@kevisual/use-config/context'; import { sequelize } from '../modules/sequelize.ts'; import { MarkModel, syncMarkModel } from '../routes/mark/model.ts'; export const sequelize2 = useContextKey('sequelize', () => sequelize); const main = async () => { // 把所有markmodel的表的source字段的类型改为jsonb // const marks = await MarkModel.findAll(); // const mark = marks[0]; // for (const mark of marks) { // if (mark.source) { // try { // await MarkModel.update({ source: {} }, { where: { id: mark.id } }); // } catch (e) { // console.error('update source error:', e); // } // } // } console.log('update source success'); // await MarkModel.sync({ alter: true, logging: true }).catch((e) => { // console.error('MarkModel.sync error:', e); // }); await syncMarkModel({ alter: true, logging: true, sync: true }); }; main(); const sql = `ALTER TABLE "micro_mark" ALTER COLUMN "source" DROP NOT NULL;ALTER TABLE "micro_mark" ALTER COLUMN "source" SET DEFAULT '{}';ALTER TABLE "micro_mark" ALTER COLUMN "source" TYPE JSONB ; COMMENT ON COLUMN "micro_mark"."source" IS '需要的数据的来源,作为一个备注使用。';`; // sequelize /** * 失败 */ const runSql = async () => { sequelize .query(sql) .then(() => { console.log('update source success'); }) .catch((e) => { console.error('update source error:', e); }); }; // runSql();