fix: field record not updated
This commit is contained in:
parent
f4c195e576
commit
024cc102ea
packages/plugins/collection-manager/src
@ -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;
|
||||
|
@ -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, {});
|
Loading…
Reference in New Issue
Block a user