Adding stripe integration by making the server logic independent of the input fields: - query factories (remote server, foreign data wrapper, foreign table) to loop on fields and values without hardcoding the names of the fields - adding stripe input and type - add the logic to handle static schema. Simply creating a big object to store into the server Additional work: - rename username field to user. This is the input intended for postgres user mapping and we now need a matching by name --------- Co-authored-by: Thomas Trompette <thomast@twenty.com>
140 lines
3.7 KiB
TypeScript
140 lines
3.7 KiB
TypeScript
import {
|
|
Column,
|
|
CreateDateColumn,
|
|
Entity,
|
|
PrimaryGeneratedColumn,
|
|
} from 'typeorm';
|
|
|
|
import { RelationOnDeleteAction } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
|
|
|
export enum WorkspaceMigrationColumnActionType {
|
|
CREATE = 'CREATE',
|
|
ALTER = 'ALTER',
|
|
CREATE_FOREIGN_KEY = 'CREATE_FOREIGN_KEY',
|
|
DROP_FOREIGN_KEY = 'DROP_FOREIGN_KEY',
|
|
DROP = 'DROP',
|
|
CREATE_COMMENT = 'CREATE_COMMENT',
|
|
}
|
|
export type WorkspaceMigrationRenamedEnum = { from: string; to: string };
|
|
export type WorkspaceMigrationEnum = string | WorkspaceMigrationRenamedEnum;
|
|
|
|
export interface WorkspaceMigrationColumnDefinition {
|
|
columnName: string;
|
|
columnType: string;
|
|
enum?: WorkspaceMigrationEnum[];
|
|
isArray?: boolean;
|
|
isNullable?: boolean;
|
|
defaultValue?: any;
|
|
}
|
|
|
|
export interface WorkspaceMigrationColumnCreate
|
|
extends WorkspaceMigrationColumnDefinition {
|
|
action: WorkspaceMigrationColumnActionType.CREATE;
|
|
}
|
|
|
|
export type WorkspaceMigrationColumnAlter = {
|
|
action: WorkspaceMigrationColumnActionType.ALTER;
|
|
currentColumnDefinition: WorkspaceMigrationColumnDefinition;
|
|
alteredColumnDefinition: WorkspaceMigrationColumnDefinition;
|
|
};
|
|
|
|
export type WorkspaceMigrationColumnCreateRelation = {
|
|
action: WorkspaceMigrationColumnActionType.CREATE_FOREIGN_KEY;
|
|
columnName: string;
|
|
referencedTableName: string;
|
|
referencedTableColumnName: string;
|
|
isUnique?: boolean;
|
|
onDelete?: RelationOnDeleteAction;
|
|
};
|
|
|
|
export type WorkspaceMigrationColumnDropRelation = {
|
|
action: WorkspaceMigrationColumnActionType.DROP_FOREIGN_KEY;
|
|
columnName: string;
|
|
};
|
|
|
|
export type WorkspaceMigrationColumnDrop = {
|
|
action: WorkspaceMigrationColumnActionType.DROP;
|
|
columnName: string;
|
|
};
|
|
|
|
export type WorkspaceMigrationCreateComment = {
|
|
action: WorkspaceMigrationColumnActionType.CREATE_COMMENT;
|
|
comment: string;
|
|
};
|
|
|
|
export type WorkspaceMigrationForeignColumnDefinition =
|
|
WorkspaceMigrationColumnDefinition & {
|
|
distantColumnName: string;
|
|
};
|
|
|
|
type ReferencedObject = {
|
|
object: string;
|
|
};
|
|
|
|
type ReferencedTableWithSchema = {
|
|
table_name: string;
|
|
schema_name: string;
|
|
};
|
|
|
|
export type ReferencedTable = ReferencedObject | ReferencedTableWithSchema;
|
|
|
|
export type WorkspaceMigrationForeignTable = {
|
|
columns: WorkspaceMigrationForeignColumnDefinition[];
|
|
referencedTable: ReferencedObject | ReferencedTableWithSchema;
|
|
foreignDataWrapperId: string;
|
|
};
|
|
|
|
export type WorkspaceMigrationColumnAction = {
|
|
action: WorkspaceMigrationColumnActionType;
|
|
} & (
|
|
| WorkspaceMigrationColumnCreate
|
|
| WorkspaceMigrationColumnAlter
|
|
| WorkspaceMigrationColumnCreateRelation
|
|
| WorkspaceMigrationColumnDropRelation
|
|
| WorkspaceMigrationColumnDrop
|
|
| 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;
|
|
newName?: string;
|
|
action: WorkspaceMigrationTableActionType;
|
|
columns?: WorkspaceMigrationColumnAction[];
|
|
foreignTable?: WorkspaceMigrationForeignTable;
|
|
};
|
|
|
|
@Entity('workspaceMigration')
|
|
export class WorkspaceMigrationEntity {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id: string;
|
|
|
|
@Column({ nullable: true, type: 'jsonb' })
|
|
migrations: WorkspaceMigrationTableAction[];
|
|
|
|
@Column({ nullable: false })
|
|
name: string;
|
|
|
|
@Column({ default: false })
|
|
isCustom: boolean;
|
|
|
|
@Column({ nullable: true, type: 'timestamptz' })
|
|
appliedAt?: Date;
|
|
|
|
@Column({ nullable: false, type: 'uuid' })
|
|
workspaceId: string;
|
|
|
|
@CreateDateColumn({ type: 'timestamptz' })
|
|
createdAt: Date;
|
|
}
|