feat: workspace sync (#3505)
* feat: wip workspace sync * feat: wip lot of debugging * feat: refactor and fix sync * fix: clean fix: clean * feat: add simple comparator tests * fix: remove debug * feat: wip drop table * fix: main merge * fix: some issues, and prepare storage system to handle complex deletion * feat: wip clean and fix * fix: reflect issue when using array instead of map and clean * fix: test & sync * fix: yarn files * fix: unecesary if-else * fix: if condition not needed * fix: remove debug * fix: replace EQUAL by SKIP * fix: sync metadata relation not applied properly * fix: lint issues * fix: merge issue
This commit is contained in:
@ -2,7 +2,7 @@ import { UseGuards } from '@nestjs/common';
|
||||
import { Args, Mutation, Resolver } from '@nestjs/graphql';
|
||||
|
||||
import { Workspace } from 'src/core/workspace/workspace.entity';
|
||||
import { AuthWorkspace } from 'src/decorators/auth-workspace.decorator';
|
||||
import { AuthWorkspace } from 'src/decorators/auth/auth-workspace.decorator';
|
||||
import { JwtAuthGuard } from 'src/guards/jwt.auth.guard';
|
||||
import { CreateOneFieldMetadataInput } from 'src/metadata/field-metadata/dtos/create-field.input';
|
||||
import { FieldMetadataDTO } from 'src/metadata/field-metadata/dtos/field-metadata.dto';
|
||||
|
||||
@ -24,6 +24,7 @@ import { DataSourceService } from 'src/metadata/data-source/data-source.service'
|
||||
import { UpdateFieldInput } from 'src/metadata/field-metadata/dtos/update-field.input';
|
||||
import { WorkspaceMigrationFactory } from 'src/metadata/workspace-migration/workspace-migration.factory';
|
||||
import { computeObjectTargetTable } from 'src/workspace/utils/compute-object-target-table.util';
|
||||
import { generateMigrationName } from 'src/metadata/workspace-migration/utils/generate-migration-name.util';
|
||||
|
||||
import {
|
||||
FieldMetadataEntity,
|
||||
@ -111,6 +112,7 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
|
||||
});
|
||||
|
||||
await this.workspaceMigrationService.createCustomMigration(
|
||||
generateMigrationName(`create-${createdFieldMetadata.name}`),
|
||||
fieldMetadataInput.workspaceId,
|
||||
[
|
||||
{
|
||||
@ -228,6 +230,7 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
|
||||
|
||||
if (fieldMetadataInput.options || fieldMetadataInput.defaultValue) {
|
||||
await this.workspaceMigrationService.createCustomMigration(
|
||||
generateMigrationName(`update-${updatedFieldMetadata.name}`),
|
||||
existingFieldMetadata.workspaceId,
|
||||
[
|
||||
{
|
||||
|
||||
@ -2,7 +2,7 @@ import { UseGuards } from '@nestjs/common';
|
||||
import { Args, Mutation, Resolver } from '@nestjs/graphql';
|
||||
|
||||
import { Workspace } from 'src/core/workspace/workspace.entity';
|
||||
import { AuthWorkspace } from 'src/decorators/auth-workspace.decorator';
|
||||
import { AuthWorkspace } from 'src/decorators/auth/auth-workspace.decorator';
|
||||
import { JwtAuthGuard } from 'src/guards/jwt.auth.guard';
|
||||
import { ObjectMetadataDTO } from 'src/metadata/object-metadata/dtos/object-metadata.dto';
|
||||
import { DeleteOneObjectInput } from 'src/metadata/object-metadata/dtos/delete-object.input';
|
||||
|
||||
@ -35,6 +35,7 @@ import {
|
||||
} from 'src/workspace/utils/compute-object-target-table.util';
|
||||
import { DeleteOneObjectInput } from 'src/metadata/object-metadata/dtos/delete-object.input';
|
||||
import { RelationToDelete } from 'src/metadata/relation-metadata/types/relation-to-delete';
|
||||
import { generateMigrationName } from 'src/metadata/workspace-migration/utils/generate-migration-name.util';
|
||||
|
||||
import { ObjectMetadataEntity } from './object-metadata.entity';
|
||||
|
||||
@ -152,6 +153,9 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
||||
|
||||
if (relationToDelete.direction === 'from') {
|
||||
await this.workspaceMigrationService.createCustomMigration(
|
||||
generateMigrationName(
|
||||
`delete-${relationToDelete.fromObjectName}-${relationToDelete.toObjectName}`,
|
||||
),
|
||||
workspaceId,
|
||||
[
|
||||
{
|
||||
@ -178,12 +182,16 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
||||
await this.objectMetadataRepository.delete(objectMetadata.id);
|
||||
|
||||
// DROP TABLE
|
||||
await this.workspaceMigrationService.createCustomMigration(workspaceId, [
|
||||
{
|
||||
name: computeObjectTargetTable(objectMetadata),
|
||||
action: 'drop',
|
||||
},
|
||||
]);
|
||||
await this.workspaceMigrationService.createCustomMigration(
|
||||
generateMigrationName(`delete-${objectMetadata.nameSingular}`),
|
||||
workspaceId,
|
||||
[
|
||||
{
|
||||
name: computeObjectTargetTable(objectMetadata),
|
||||
action: 'drop',
|
||||
},
|
||||
],
|
||||
);
|
||||
|
||||
await this.workspaceMigrationRunnerService.executeMigrationFromPendingMigrations(
|
||||
workspaceId,
|
||||
@ -298,6 +306,7 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
||||
);
|
||||
|
||||
await this.workspaceMigrationService.createCustomMigration(
|
||||
generateMigrationName(`create-${createdObjectMetadata.nameSingular}`),
|
||||
createdObjectMetadata.workspaceId,
|
||||
[
|
||||
{
|
||||
|
||||
@ -21,6 +21,7 @@ import { ObjectMetadataEntity } from 'src/metadata/object-metadata/object-metada
|
||||
import { createCustomColumnName } from 'src/metadata/utils/create-custom-column-name.util';
|
||||
import { computeObjectTargetTable } from 'src/workspace/utils/compute-object-target-table.util';
|
||||
import { createRelationForeignKeyColumnName } from 'src/metadata/relation-metadata/utils/create-relation-foreign-key-column-name.util';
|
||||
import { generateMigrationName } from 'src/metadata/workspace-migration/utils/generate-migration-name.util';
|
||||
|
||||
import {
|
||||
RelationMetadataEntity,
|
||||
@ -173,6 +174,7 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
|
||||
foreignKeyColumnName: string,
|
||||
) {
|
||||
await this.workspaceMigrationService.createCustomMigration(
|
||||
generateMigrationName(`create-${relationMetadataInput.fromName}`),
|
||||
relationMetadataInput.workspaceId,
|
||||
[
|
||||
// Create the column
|
||||
|
||||
@ -11,4 +11,4 @@ export type RelationToDelete = {
|
||||
toFieldMetadataIsCustom: boolean;
|
||||
toObjectMetadataIsCustom: boolean;
|
||||
direction: string;
|
||||
};
|
||||
};
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
export function generateMigrationName(name?: string): string {
|
||||
return `${new Date().getTime()}${name ? `-${name}` : ''}`;
|
||||
}
|
||||
@ -70,7 +70,7 @@ export class WorkspaceMigrationEntity {
|
||||
@Column({ nullable: true, type: 'jsonb' })
|
||||
migrations: WorkspaceMigrationTableAction[];
|
||||
|
||||
@Column({ nullable: true })
|
||||
@Column({ nullable: false })
|
||||
name: string;
|
||||
|
||||
@Column({ default: false })
|
||||
|
||||
@ -57,10 +57,12 @@ export class WorkspaceMigrationService {
|
||||
* @param migrations
|
||||
*/
|
||||
public async createCustomMigration(
|
||||
name: string,
|
||||
workspaceId: string,
|
||||
migrations: WorkspaceMigrationTableAction[],
|
||||
) {
|
||||
await this.workspaceMigrationRepository.save({
|
||||
name,
|
||||
migrations,
|
||||
workspaceId,
|
||||
isCustom: true,
|
||||
|
||||
Reference in New Issue
Block a user