Merge branch 'main' into fix/pg-schema-with-inherit

This commit is contained in:
ChengLei Shao 2023-02-15 15:08:06 +00:00
commit 6b40c92d49
9 changed files with 45 additions and 10 deletions

13
.gitpod.yml Normal file
View File

@ -0,0 +1,13 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
# and commit this file to your remote git repository to share the goodness with others.
# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart
image: gitpod/workspace-postgres
tasks:
- init: yarn install && yarn run build
command: yarn run start

View File

@ -3,6 +3,9 @@ import { LOG_TYPE_CREATE } from '../constants';
export function afterCreate(app: Application) { export function afterCreate(app: Application) {
return async (model, options) => { return async (model, options) => {
if (options.logging === false) {
return;
}
const db = app.db; const db = app.db;
const collection = db.getCollection(model.constructor.name); const collection = db.getCollection(model.constructor.name);
if (!collection || !collection.options.logging) { if (!collection || !collection.options.logging) {

View File

@ -1,8 +1,8 @@
import { Database, MigrationContext} from '@nocobase/database'; import { Database, MigrationContext } from '@nocobase/database';
import UpdateCollectionsHiddenMigration from '../../migrations/20221104151410-update-collections-hidden'; import UpdateCollectionsHiddenMigration from '../../migrations/20221104151410-update-collections-hidden';
import { createApp } from '../index';
import { MockServer } from '@nocobase/test'; import { MockServer } from '@nocobase/test';
import { createApp } from '../index';
describe('migration 20221104151410-update-collections-hidden test', () => { describe('migration 20221104151410-update-collections-hidden test', () => {
let app: MockServer; let app: MockServer;

View File

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

View File

@ -60,6 +60,7 @@ export default {
foreignKey: 'collectionName', foreignKey: 'collectionName',
otherKey: 'categoryId', otherKey: 'categoryId',
targetKey: 'id', targetKey: 'id',
sortBy: 'sort',
through: 'collectionCategory', through: 'collectionCategory',
}, },
], ],

View File

@ -3,6 +3,10 @@ import { Migration } from '@nocobase/server';
export default class UpdateIdToBigIntMigrator extends Migration { export default class UpdateIdToBigIntMigrator extends Migration {
async up() { async up() {
const result = await this.app.version.satisfies('<0.9.0-alpha.1');
if (!result) {
return;
}
const db = this.app.db; const db = this.app.db;
await db.getCollection('fields').repository.update({ await db.getCollection('fields').repository.update({

View File

@ -3,6 +3,10 @@ import { Migration } from '@nocobase/server';
export default class UpdateIdToBigIntMigrator extends Migration { export default class UpdateIdToBigIntMigrator extends Migration {
async up() { async up() {
const result = await this.app.version.satisfies('<0.9.0-alpha.1');
if (!result) {
return;
}
const db = this.app.db; const db = this.app.db;
await db.getCollection('fields').repository.update({ await db.getCollection('fields').repository.update({

View File

@ -23,7 +23,7 @@ export async function importXlsx(ctx: Context, next: Next) {
} = xlsx.parse(file.buffer); } = xlsx.parse(file.buffer);
const failureData = originalList.splice(IMPORT_LIMIT_COUNT + 1); const failureData = originalList.splice(IMPORT_LIMIT_COUNT + 1);
const titles = originalList.shift(); const titles = originalList.shift();
const legalList = []; const legalList: any[] = [];
if (originalList.length > 0 && titles?.length === columns.length) { if (originalList.length > 0 && titles?.length === columns.length) {
// const results = ( // const results = (
// await Promise.allSettled<any>( // await Promise.allSettled<any>(
@ -38,12 +38,12 @@ export async function importXlsx(ctx: Context, next: Next) {
// }), // }),
// ) // )
// ).filter((item) => 'value' in item && item.value !== undefined); // ).filter((item) => 'value' in item && item.value !== undefined);
const values = []; const values: any[] = [];
for (const item of originalList) { for (const item of originalList) {
try { try {
const transformResult = await transform({ ctx, record: item, columns, fields: collectionFields }); const transformResult = await transform({ ctx, record: item, columns, fields: collectionFields });
values.push(transformResult); values.push(transformResult);
legalList.push(cloneDeep(item)); legalList.push(cloneDeep<any>(item));
} catch (error) { } catch (error) {
failureData.unshift([...item, error.message]); failureData.unshift([...item, error.message]);
} }
@ -51,14 +51,24 @@ export async function importXlsx(ctx: Context, next: Next) {
//@ts-ignore //@ts-ignore
// const values = results.map((r) => r.value); // const values = results.map((r) => r.value);
const result = await ctx.db.sequelize.transaction(async (transaction) => { const result = await ctx.db.sequelize.transaction(async (transaction) => {
let sort: number = 0;
if (collection.options.sortable) {
sort = await repository.model.max<number, any>('sort', { transaction });
}
for (const [index, val] of values.entries()) { for (const [index, val] of values.entries()) {
if (val === undefined || val === null) { if (val === undefined || val === null) {
continue; continue;
} }
try { try {
let values = { ...val };
if (collection.options.sortable) {
sort += 1;
values['sort'] = sort;
}
await repository.create({ await repository.create({
values: { ...val }, values,
transaction, transaction,
logging: false,
}); });
} catch (error) { } catch (error) {
const failData = legalList[index]; const failData = legalList[index];

View File

@ -12,10 +12,10 @@ const ReadPretty = (props) => {
const field = useField(); const field = useField();
useEffect(() => { useEffect(() => {
if (!field.title) { if (!field.title && collectionField?.uiSchema?.title) {
field.title = collectionField.uiSchema.title; field.title = collectionField.uiSchema.title;
} }
}, collectionField.title); }, collectionField?.title);
if (!readOnly) if (!readOnly)
return ( return (