Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

2.4 KB
Raw Blame
import { Flow, FlowVersion, User } from '@activepieces/shared'
import { EntitySchema } from 'typeorm'
import {
    ApIdSchema,
    BaseColumnSchemaPart,
} from '../../database/database-common'

export type FlowVersionSchema = {
    flow: Flow
    updatedByUser: User
} & FlowVersion

export const FlowVersionEntity = new EntitySchema<FlowVersionSchema>({
    name: 'flow_version',
    columns: {
        ...BaseColumnSchemaPart,
        flowId: ApIdSchema,
        displayName: {
            type: String,
        },
        schemaVersion: {
            type: String,
            nullable: true,
        },
        trigger: {
            type: 'jsonb',
            nullable: true,
        },
        connectionIds: {
            type: String,
            array: true,
            nullable: false,
        },
        agentIds: {
            type: String,
            array: true,
            nullable: false,
        },
        updatedBy: {
            type: String,
            nullable: true,
        },
        valid: {
            type: Boolean,
        },
        state: {
            type: String,
        },
        backupFiles: {
            type: 'jsonb',
            nullable: true,
        },
        notes: {
            type: 'jsonb',
            nullable: false,
        },
    },
    indices: [
        {
            name: 'idx_flow_version_flow_id_created_desc',
            columns: ['flowId', 'created'],
            unique: false,
        },
        {
            name: 'idx_flow_version_schema_version',
            columns: ['schemaVersion'],
            unique: false,
        },
        {
            name: 'idx_flow_version_updated_by',
            columns: ['updatedBy'],
        },
        {
            name: 'idx_flow_version_connection_ids_gin',
            columns: ['connectionIds'],
            synchronize: false,
        },
    ],
    relations: {
        updatedByUser: {
            type: 'many-to-one',
            target: 'user',
            cascade: true,
            onDelete: 'SET NULL',
            joinColumn: {
                name: 'updatedBy',
                foreignKeyConstraintName: 'fk_updated_by_user_flow',
            },
        },
        flow: {
            type: 'many-to-one',
            target: 'flow',
            cascade: true,
            onDelete: 'CASCADE',
            joinColumn: {
                name: 'flowId',
                foreignKeyConstraintName: 'fk_flow_version_flow',
            },
        },
    },
})