Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new design for design page #1204

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/nestjs-backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ExportOpenApiModule } from './features/export/open-api/export-open-api.
import { FieldOpenApiModule } from './features/field/open-api/field-open-api.module';
import { HealthModule } from './features/health/health.module';
import { ImportOpenApiModule } from './features/import/open-api/import-open-api.module';
import { IntegrityModule } from './features/integrity/integrity.module';
import { InvitationModule } from './features/invitation/invitation.module';
import { NextModule } from './features/next/next.module';
import { NotificationModule } from './features/notification/notification.module';
Expand All @@ -44,6 +45,7 @@ export const appModules = {
NextModule,
FieldOpenApiModule,
BaseModule,
IntegrityModule,
ChatModule,
AttachmentsModule,
WsModule,
Expand Down
6 changes: 4 additions & 2 deletions apps/nestjs-backend/src/db-provider/db.provider.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DriverClient, IFilter, ILookupOptionsVo, ISortItem } from '@teable/core';
import type { DriverClient, FieldType, IFilter, ILookupOptionsVo, ISortItem } from '@teable/core';
import type { Prisma } from '@teable/db-main-prisma';
import type { IAggregationField, ISearchIndexByQueryRo } from '@teable/openapi';
import type { Knex } from 'knex';
Expand Down Expand Up @@ -72,6 +72,8 @@ export interface IDbProvider {
prisma: Prisma.TransactionClient
): Promise<boolean>;

checkTableExist(tableName: string): string;

dropColumnAndIndex(tableName: string, columnName: string, indexName: string): string[];

modifyColumnSchema(tableName: string, columnName: string, schemaType: SchemaType): string[];
Expand Down Expand Up @@ -165,5 +167,5 @@ export interface IDbProvider {

lookupOptionsQuery(optionsKey: keyof ILookupOptionsVo, value: string): string;

optionsQuery(optionsKey: string, value: string): string;
optionsQuery(type: FieldType, optionsKey: string, value: string): string;
}
23 changes: 21 additions & 2 deletions apps/nestjs-backend/src/db-provider/postgres.provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable sonarjs/no-duplicate-string */
import { Logger } from '@nestjs/common';
import type { IFilter, ILookupOptionsVo, ISortItem } from '@teable/core';
import type { FieldType, IFilter, ILookupOptionsVo, ISortItem } from '@teable/core';
import { DriverClient } from '@teable/core';
import type { PrismaClient } from '@teable/db-main-prisma';
import type { IAggregationField, ISearchIndexByQueryRo } from '@teable/openapi';
Expand Down Expand Up @@ -75,6 +75,16 @@ export class PostgresProvider implements IDbProvider {
return res[0].exists;
}

checkTableExist(tableName: string): string {
const [schemaName, dbTableName] = this.splitTableName(tableName);
return this.knex
.raw(
'SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = ? AND table_name = ?) AS exists',
[schemaName, dbTableName]
)
.toQuery();
}

renameColumn(tableName: string, oldName: string, newName: string): string[] {
return this.knex.schema
.alterTable(tableName, (table) => {
Expand Down Expand Up @@ -424,20 +434,29 @@ export class PostgresProvider implements IDbProvider {
lookupOptionsQuery(optionsKey: keyof ILookupOptionsVo, value: string): string {
return this.knex('field')
.select({
tableId: 'table_id',
id: 'id',
type: 'type',
name: 'name',
lookupOptions: 'lookup_options',
})
.whereNull('deleted_time')
.whereRaw(`lookup_options::json->>'${optionsKey}' = ?`, [value])
.toQuery();
}

optionsQuery(optionsKey: string, value: string): string {
optionsQuery(type: FieldType, optionsKey: string, value: string): string {
return this.knex('field')
.select({
tableId: 'table_id',
id: 'id',
type: 'type',
name: 'name',
options: 'options',
})
.whereNull('deleted_time')
.whereRaw(`options::json->>'${optionsKey}' = ?`, [value])
.where('type', type)
.toQuery();
}
}
23 changes: 21 additions & 2 deletions apps/nestjs-backend/src/db-provider/sqlite.provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable sonarjs/no-duplicate-string */
import { Logger } from '@nestjs/common';
import type { IFilter, ILookupOptionsVo, ISortItem } from '@teable/core';
import type { FieldType, IFilter, ILookupOptionsVo, ISortItem } from '@teable/core';
import { DriverClient } from '@teable/core';
import type { PrismaClient } from '@teable/db-main-prisma';
import type { IAggregationField, ISearchIndexByQueryRo } from '@teable/openapi';
Expand Down Expand Up @@ -65,6 +65,18 @@ export class SqliteProvider implements IDbProvider {
return columns.some((column) => column.name === columnName);
}

checkTableExist(tableName: string): string {
return this.knex
.raw(
`SELECT EXISTS (
SELECT 1 FROM sqlite_master
WHERE type='table' AND name = ?
) as exists`,
[tableName]
)
.toQuery();
}

renameColumn(tableName: string, oldName: string, newName: string): string[] {
return [
this.knex
Expand Down Expand Up @@ -382,18 +394,25 @@ export class SqliteProvider implements IDbProvider {
return this.knex('field')
.select({
id: 'id',
type: 'type',
name: 'name',
lookupOptions: 'lookup_options',
})
.whereNull('deleted_time')
.whereRaw(`json_extract(lookup_options, '$."${optionsKey}"') = ?`, [value])
.toQuery();
}

optionsQuery(optionsKey: string, value: string): string {
optionsQuery(type: FieldType, optionsKey: string, value: string): string {
return this.knex('field')
.select({
id: 'id',
type: 'type',
name: 'name',
options: 'options',
})
.where('type', type)
.whereNull('deleted_time')
.whereRaw(`json_extract(options, '$."${optionsKey}"') = ?`, [value])
.toQuery();
}
Expand Down
2 changes: 1 addition & 1 deletion apps/nestjs-backend/src/features/base/base.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class BaseController {

@Permissions('base|db_connection')
@Post(':baseId/connection')
async createDbConnection(@Param('baseId') baseId: string): Promise<IDbConnectionVo> {
async createDbConnection(@Param('baseId') baseId: string): Promise<IDbConnectionVo | null> {
return await this.dbConnectionService.create(baseId);
}

Expand Down
13 changes: 7 additions & 6 deletions apps/nestjs-backend/src/features/base/db-connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
BadRequestException,
Injectable,
InternalServerErrorException,
NotFoundException,
Logger,
} from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import type { IDsn } from '@teable/core';
Expand All @@ -12,17 +12,16 @@ import type { IDbConnectionVo } from '@teable/openapi';
import { Knex } from 'knex';
import { nanoid } from 'nanoid';
import { InjectModel } from 'nest-knexjs';
import { ClsService } from 'nestjs-cls';
import { BaseConfig, type IBaseConfig } from '../../configs/base.config';
import { InjectDbProvider } from '../../db-provider/db.provider';
import { IDbProvider } from '../../db-provider/db.provider.interface';
import type { IClsStore } from '../../types/cls';

@Injectable()
export class DbConnectionService {
private readonly logger = new Logger(DbConnectionService.name);

constructor(
private readonly prismaService: PrismaService,
private readonly cls: ClsService<IClsStore>,
private readonly configService: ConfigService,
@InjectDbProvider() private readonly dbProvider: IDbProvider,
@InjectModel('CUSTOM_KNEX') private readonly knex: Knex,
Expand Down Expand Up @@ -118,7 +117,8 @@ export class DbConnectionService {
const readOnlyRole = `read_only_role_${baseId}`;
const publicDatabaseProxy = this.baseConfig.publicDatabaseProxy;
if (!publicDatabaseProxy) {
throw new NotFoundException('PUBLIC_DATABASE_PROXY is not found in env');
this.logger.error('PUBLIC_DATABASE_PROXY is not found in env');
return null;
}

const { hostname: dbHostProxy, port: dbPortProxy } = new URL(`https://${publicDatabaseProxy}`);
Expand Down Expand Up @@ -185,7 +185,8 @@ export class DbConnectionService {
const password = nanoid();
const publicDatabaseProxy = this.baseConfig.publicDatabaseProxy;
if (!publicDatabaseProxy) {
throw new NotFoundException('PUBLIC_DATABASE_PROXY is not found in env');
this.logger.error('PUBLIC_DATABASE_PROXY is not found in env');
return null;
}

const { hostname: dbHostProxy, port: dbPortProxy } = new URL(
Expand Down
12 changes: 12 additions & 0 deletions apps/nestjs-backend/src/features/calculation/reference.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ export class ReferenceService {
if (!fromRecordIds?.length && !toRecordIds?.length) {
continue;
}

console.log('order', JSON.stringify(order, null, 2));
console.log('order:fromRecordIds', fromRecordIds);
console.log('order:toRecordIds', toRecordIds);
const relatedRecordItems = await this.getAffectedRecordItems({
fieldId,
fieldMap,
Expand All @@ -351,6 +355,7 @@ export class ReferenceService {
fkRecordMap,
tableId2DbTableName,
});
console.log('relatedRecordItems', relatedRecordItems);

if (field.lookupOptions || field.type === FieldType.Link) {
await this.calculateLinkRelatedRecords({
Expand Down Expand Up @@ -583,6 +588,13 @@ export class ReferenceService {
: (field.options as ILinkFieldOptions);
const { relationship } = lookupOptions;
const linkFieldId = field.lookupOptions ? field.lookupOptions.linkFieldId : field.id;

if (!recordItem.record?.fields) {
console.log('recordItem', JSON.stringify(recordItem, null, 2));
console.log('recordItem.field', field);
throw new InternalServerErrorException('record fields is undefined');
}

const cellValue = recordItem.record.fields[linkFieldId];
const dependenciesIndexed = keyBy(dependencies, 'id');

Expand Down
23 changes: 23 additions & 0 deletions apps/nestjs-backend/src/features/integrity/integrity.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Controller, Get, Param, Post, UseGuards } from '@nestjs/common';
import type { IIntegrityCheckVo } from '@teable/openapi';
import { Permissions } from '../auth/decorators/permissions.decorator';
import { PermissionGuard } from '../auth/guard/permission.guard';
import { LinkIntegrityService } from './link-integrity.service';

@UseGuards(PermissionGuard)
@Controller('api/integrity')
export class IntegrityController {
constructor(private readonly linkIntegrityService: LinkIntegrityService) {}

@Permissions('table|create')
@Get('base/:baseId/link-check')
async checkBaseIntegrity(@Param('baseId') baseId: string): Promise<IIntegrityCheckVo> {
return await this.linkIntegrityService.linkIntegrityCheck(baseId);
}

@Permissions('table|create')
@Post('base/:baseId/link-fix')
async fixBaseIntegrity(@Param('baseId') baseId: string): Promise<void> {
return await this.linkIntegrityService.linkIntegrityFix(baseId);
}
}
10 changes: 10 additions & 0 deletions apps/nestjs-backend/src/features/integrity/integrity.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { IntegrityController } from './integrity.controller';
import { LinkIntegrityService } from './link-integrity.service';

@Module({
controllers: [IntegrityController],
providers: [LinkIntegrityService],
exports: [LinkIntegrityService],
})
export class IntegrityModule {}
Loading
Loading