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;