fix: field record not updated

This commit is contained in:
chenos 2022-11-25 12:12:44 +08:00
parent f4c195e576
commit 024cc102ea
2 changed files with 16 additions and 17 deletions
packages/plugins/collection-manager/src

View File

@ -1,10 +1,10 @@
import { Database, MigrationContext } from '@nocobase/database';
import Migrator from '../../migrations/20221121111112-update-id-to-bigint';
import Migrator from '../../migrations/20221121111113-update-id-to-bigint';
const excludeSqlite = () => (process.env.DB_DIALECT != 'sqlite' ? describe : describe.skip);
import { createApp } from '../index';
import { MockServer } from '@nocobase/test';
import { createApp } from '../index';
excludeSqlite()('update id to bigint test', () => {
let app: MockServer;

View File

@ -1,5 +1,5 @@
import { Migration } from '@nocobase/server';
import { DataTypes } from '@nocobase/database';
import { Migration } from '@nocobase/server';
export default class UpdateIdToBigIntMigrator extends Migration {
async up() {
@ -32,6 +32,19 @@ export default class UpdateIdToBigIntMigrator extends Migration {
const updateToBigInt = async (model, fieldName) => {
let sql;
const fieldRecord = await db.getCollection('fields').repository.findOne({
filter: {
collectionName: model.name,
name: fieldName,
type: 'integer',
},
});
if (fieldRecord) {
fieldRecord.set('type', 'bigInt');
await fieldRecord.save();
}
const tableName = model.tableName;
if (model.rawAttributes[fieldName].type instanceof DataTypes.INTEGER) {
@ -67,20 +80,6 @@ export default class UpdateIdToBigIntMigrator extends Migration {
throw err;
}
const collection = db.modelCollection.get(model);
const fieldRecord = await db.getCollection('fields').repository.findOne({
filter: {
collectionName: collection.name,
name: fieldName,
type: 'integer',
},
});
if (fieldRecord) {
fieldRecord.set('type', 'bigInt');
await fieldRecord.save();
}
if (db.inDialect('postgres')) {
const sequenceQuery = `SELECT pg_get_serial_sequence('"${model.tableName}"', '${fieldName}');`;
const [result] = await this.sequelize.query(sequenceQuery, {});