Skip to content

Commit

Permalink
feat: sync command missing ability to rename standard object (#4819)
Browse files Browse the repository at this point in the history
We've introduced in PR #4373 standard ids to be able to rename standard
fields and objects.
Fields part was working properly, but objects part was not yet
implemented.
This PR is adding the missing parts to make it work.
  • Loading branch information
magrinj authored Apr 9, 2024
1 parent b1242bb commit 35717fc
Show file tree
Hide file tree
Showing 16 changed files with 323 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
WorkspaceMigrationColumnActionType,
WorkspaceMigrationColumnDrop,
WorkspaceMigrationTableAction,
WorkspaceMigrationTableActionType,
} from 'src/engine/metadata-modules/workspace-migration/workspace-migration.entity';
import { TypeORMService } from 'src/database/typeorm/typeorm.service';
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
Expand Down Expand Up @@ -152,7 +153,7 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
[
{
name: computeObjectTargetTable(objectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: this.workspaceMigrationFactory.createColumnActions(
WorkspaceMigrationColumnActionType.CREATE,
createdFieldMetadata,
Expand Down Expand Up @@ -328,7 +329,7 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
[
{
name: computeObjectTargetTable(objectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: this.workspaceMigrationFactory.createColumnActions(
WorkspaceMigrationColumnActionType.ALTER,
existingFieldMetadata,
Expand Down Expand Up @@ -399,7 +400,7 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
[
{
name: computeObjectTargetTable(objectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.DROP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { WorkspaceMigrationRunnerService } from 'src/engine/workspace-manager/wo
import {
WorkspaceMigrationColumnActionType,
WorkspaceMigrationColumnDrop,
WorkspaceMigrationTableActionType,
} from 'src/engine/metadata-modules/workspace-migration/workspace-migration.entity';
import {
FieldMetadataEntity,
Expand Down Expand Up @@ -177,7 +178,7 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
relationToDelete.toObjectName,
relationToDelete.toObjectMetadataIsCustom,
),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.DROP,
Expand All @@ -203,7 +204,7 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
[
{
name: computeObjectTargetTable(objectMetadata),
action: 'drop',
action: WorkspaceMigrationTableActionType.DROP,
},
],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
WorkspaceMigrationTableAction,
WorkspaceMigrationColumnActionType,
WorkspaceMigrationColumnCreate,
WorkspaceMigrationTableActionType,
} from 'src/engine/metadata-modules/workspace-migration/workspace-migration.entity';
import { computeObjectTargetTable } from 'src/engine/utils/compute-object-target-table.util';

Expand All @@ -17,12 +18,12 @@ export const buildWorkspaceMigrationsForCustomObject = (
): WorkspaceMigrationTableAction[] => [
{
name: computeObjectTargetTable(createdObjectMetadata),
action: 'create',
action: WorkspaceMigrationTableActionType.CREATE,
} satisfies WorkspaceMigrationTableAction,
// Add activity target relation
{
name: computeObjectTargetTable(activityTargetObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE,
Expand All @@ -36,7 +37,7 @@ export const buildWorkspaceMigrationsForCustomObject = (
},
{
name: computeObjectTargetTable(activityTargetObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE_FOREIGN_KEY,
Expand All @@ -52,7 +53,7 @@ export const buildWorkspaceMigrationsForCustomObject = (
// Add attachment relation
{
name: computeObjectTargetTable(attachmentObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE,
Expand All @@ -66,7 +67,7 @@ export const buildWorkspaceMigrationsForCustomObject = (
},
{
name: computeObjectTargetTable(attachmentObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE_FOREIGN_KEY,
Expand All @@ -82,7 +83,7 @@ export const buildWorkspaceMigrationsForCustomObject = (
// Add event relation
{
name: computeObjectTargetTable(eventObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE,
Expand All @@ -96,7 +97,7 @@ export const buildWorkspaceMigrationsForCustomObject = (
},
{
name: computeObjectTargetTable(eventObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE_FOREIGN_KEY,
Expand All @@ -112,7 +113,7 @@ export const buildWorkspaceMigrationsForCustomObject = (
// Add favorite relation
{
name: computeObjectTargetTable(favoriteObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE,
Expand All @@ -126,7 +127,7 @@ export const buildWorkspaceMigrationsForCustomObject = (
},
{
name: computeObjectTargetTable(favoriteObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE_FOREIGN_KEY,
Expand All @@ -141,7 +142,7 @@ export const buildWorkspaceMigrationsForCustomObject = (
},
{
name: computeObjectTargetTable(createdObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE,
Expand All @@ -154,7 +155,7 @@ export const buildWorkspaceMigrationsForCustomObject = (
// This is temporary until we implement mainIdentifier
{
name: computeObjectTargetTable(createdObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
WorkspaceMigrationTableAction,
WorkspaceMigrationColumnActionType,
WorkspaceMigrationColumnCreate,
WorkspaceMigrationTableActionType,
} from 'src/engine/metadata-modules/workspace-migration/workspace-migration.entity';
import { computeObjectTargetTable } from 'src/engine/utils/compute-object-target-table.util';

Expand Down Expand Up @@ -61,7 +62,7 @@ export const buildWorkspaceMigrationsForRemoteObject = async (
return [
{
name: computeObjectTargetTable(activityTargetObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE,
Expand All @@ -75,7 +76,7 @@ export const buildWorkspaceMigrationsForRemoteObject = async (
},
{
name: computeObjectTargetTable(activityTargetObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE,
Expand All @@ -88,7 +89,7 @@ export const buildWorkspaceMigrationsForRemoteObject = async (
},
{
name: computeObjectTargetTable(activityTargetObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE_COMMENT,
Expand All @@ -104,7 +105,7 @@ export const buildWorkspaceMigrationsForRemoteObject = async (
// Add attachment relation
{
name: computeObjectTargetTable(attachmentObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE,
Expand All @@ -118,7 +119,7 @@ export const buildWorkspaceMigrationsForRemoteObject = async (
},
{
name: computeObjectTargetTable(attachmentObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE,
Expand All @@ -131,7 +132,7 @@ export const buildWorkspaceMigrationsForRemoteObject = async (
},
{
name: computeObjectTargetTable(attachmentObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE_COMMENT,
Expand All @@ -147,7 +148,7 @@ export const buildWorkspaceMigrationsForRemoteObject = async (
// Add event relation
{
name: computeObjectTargetTable(eventObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE,
Expand All @@ -161,7 +162,7 @@ export const buildWorkspaceMigrationsForRemoteObject = async (
},
{
name: computeObjectTargetTable(eventObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE,
Expand All @@ -174,7 +175,7 @@ export const buildWorkspaceMigrationsForRemoteObject = async (
},
{
name: computeObjectTargetTable(eventObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE_COMMENT,
Expand All @@ -190,7 +191,7 @@ export const buildWorkspaceMigrationsForRemoteObject = async (
// Add favorite relation
{
name: computeObjectTargetTable(favoriteObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE,
Expand All @@ -204,7 +205,7 @@ export const buildWorkspaceMigrationsForRemoteObject = async (
},
{
name: computeObjectTargetTable(favoriteObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE,
Expand All @@ -217,7 +218,7 @@ export const buildWorkspaceMigrationsForRemoteObject = async (
},
{
name: computeObjectTargetTable(favoriteObjectMetadata),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE_COMMENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import { CreateRelationInput } from 'src/engine/metadata-modules/relation-metada
import { WorkspaceMigrationRunnerService } from 'src/engine/workspace-manager/workspace-migration-runner/workspace-migration-runner.service';
import { WorkspaceMigrationService } from 'src/engine/metadata-modules/workspace-migration/workspace-migration.service';
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
import { WorkspaceMigrationColumnActionType } from 'src/engine/metadata-modules/workspace-migration/workspace-migration.entity';
import {
WorkspaceMigrationColumnActionType,
WorkspaceMigrationTableActionType,
} from 'src/engine/metadata-modules/workspace-migration/workspace-migration.entity';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { computeObjectTargetTable } from 'src/engine/utils/compute-object-target-table.util';
import { generateMigrationName } from 'src/engine/metadata-modules/workspace-migration/utils/generate-migration-name.util';
Expand Down Expand Up @@ -171,7 +174,7 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
name: computeObjectTargetTable(
objectMetadataMap[relationMetadataInput.toObjectMetadataId],
),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE,
Expand All @@ -186,7 +189,7 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
name: computeObjectTargetTable(
objectMetadataMap[relationMetadataInput.toObjectMetadataId],
),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.CREATE_FOREIGN_KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { generateMigrationName } from 'src/engine/metadata-modules/workspace-mig
import {
WorkspaceMigrationColumnDefinition,
WorkspaceMigrationForeignTable,
WorkspaceMigrationTableActionType,
} from 'src/engine/metadata-modules/workspace-migration/workspace-migration.entity';
import { RemoteTableColumn } from 'src/engine/metadata-modules/remote-server/remote-table/types/remote-table-column';
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
Expand Down Expand Up @@ -165,7 +166,7 @@ export class RemoteTableService {
[
{
name: remoteTableName,
action: 'create_foreign_table',
action: WorkspaceMigrationTableActionType.CREATE_FOREIGN_TABLE,
foreignTable: {
columns: remoteTableColumns.map(
(column) =>
Expand Down Expand Up @@ -252,7 +253,7 @@ export class RemoteTableService {
[
{
name: remoteTableName,
action: 'drop_foreign_table',
action: WorkspaceMigrationTableActionType.DROP_FOREIGN_TABLE,
},
],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,21 @@ export type WorkspaceMigrationColumnAction = {
| WorkspaceMigrationCreateComment
);

/**
* Enum values are lowercase to avoid issues with already existing enum values
*/
export enum WorkspaceMigrationTableActionType {
CREATE = 'create',
ALTER = 'alter',
DROP = 'drop',
CREATE_FOREIGN_TABLE = 'create_foreign_table',
DROP_FOREIGN_TABLE = 'drop_foreign_table'
}

export type WorkspaceMigrationTableAction = {
name: string;
action:
| 'create'
| 'alter'
| 'drop'
| 'create_foreign_table'
| 'drop_foreign_table';
newName?: string;
action: WorkspaceMigrationTableActionType;
columns?: WorkspaceMigrationColumnAction[];
foreignTable?: WorkspaceMigrationForeignTable;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
WorkspaceMigrationColumnActionType,
WorkspaceMigrationEntity,
WorkspaceMigrationTableAction,
WorkspaceMigrationTableActionType,
} from 'src/engine/metadata-modules/workspace-migration/workspace-migration.entity';
import { computeObjectTargetTable } from 'src/engine/utils/compute-object-target-table.util';
import { WorkspaceMigrationFactory } from 'src/engine/metadata-modules/workspace-migration/workspace-migration.factory';
Expand Down Expand Up @@ -94,7 +95,7 @@ export class WorkspaceMigrationFieldFactory {
name: computeObjectTargetTable(
originalObjectMetadataMap[fieldMetadata.objectMetadataId],
),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: this.workspaceMigrationFactory.createColumnActions(
WorkspaceMigrationColumnActionType.CREATE,
fieldMetadata,
Expand Down Expand Up @@ -132,7 +133,7 @@ export class WorkspaceMigrationFieldFactory {
fieldMetadataUpdate.current.objectMetadataId
],
),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: this.workspaceMigrationFactory.createColumnActions(
WorkspaceMigrationColumnActionType.ALTER,
fieldMetadataUpdate.current,
Expand Down Expand Up @@ -171,7 +172,7 @@ export class WorkspaceMigrationFieldFactory {
name: computeObjectTargetTable(
originalObjectMetadataMap[fieldMetadata.objectMetadataId],
),
action: 'alter',
action: WorkspaceMigrationTableActionType.ALTER,
columns: [
{
action: WorkspaceMigrationColumnActionType.DROP,
Expand Down
Loading

0 comments on commit 35717fc

Please sign in to comment.