From 1868a8a5f369fcfb379d2da638f2a400496216c5 Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 21 Dec 2022 10:01:39 +0800 Subject: [PATCH] fix(collection-manager): update timestamps to true --- .../hooks/afterCreateForForeignKeyField.ts | 2 +- .../migrations/20221221103219-timestamps.ts | 23 +++++++++++++++++++ .../src/repositories/collection-repository.ts | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 packages/plugins/collection-manager/src/migrations/20221221103219-timestamps.ts diff --git a/packages/plugins/collection-manager/src/hooks/afterCreateForForeignKeyField.ts b/packages/plugins/collection-manager/src/hooks/afterCreateForForeignKeyField.ts index 028c766bb..07972363d 100644 --- a/packages/plugins/collection-manager/src/hooks/afterCreateForForeignKeyField.ts +++ b/packages/plugins/collection-manager/src/hooks/afterCreateForForeignKeyField.ts @@ -143,7 +143,7 @@ export function afterCreateForForeignKeyField(db: Database) { values: { name: through, title: through, - timestamps: false, + timestamps: true, autoGenId: false, hidden: true, autoCreate: true, diff --git a/packages/plugins/collection-manager/src/migrations/20221221103219-timestamps.ts b/packages/plugins/collection-manager/src/migrations/20221221103219-timestamps.ts new file mode 100644 index 000000000..7dcf6b082 --- /dev/null +++ b/packages/plugins/collection-manager/src/migrations/20221221103219-timestamps.ts @@ -0,0 +1,23 @@ +import { Migration } from '@nocobase/server'; + +export default class extends Migration { + async up() { + const result = await this.app.version.satisfies('<=0.8.0-alpha.13'); + if (!result) { + return; + } + try { + const collections = await this.app.db.getRepository('collections').find(); + console.log('migrating...'); + for (const collection of collections) { + if (collection.get('autoCreate') && collection.get('isThrough')) { + collection.set('timestamps', true); + await collection.save(); + console.log(`collection name: ${collection.name}`); + } + } + } catch (error) { + console.error(error); + } + } +} diff --git a/packages/plugins/collection-manager/src/repositories/collection-repository.ts b/packages/plugins/collection-manager/src/repositories/collection-repository.ts index 1a00c34cd..4c9908be8 100644 --- a/packages/plugins/collection-manager/src/repositories/collection-repository.ts +++ b/packages/plugins/collection-manager/src/repositories/collection-repository.ts @@ -1,6 +1,6 @@ +import Topo from '@hapi/topo'; import { Model, Repository } from '@nocobase/database'; import { CollectionModel } from '../models/collection'; -import Topo from '@hapi/topo'; interface LoadOptions { filter?: any;