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

1.9 KB
Raw Blame
import { PieceSelectionMode, PieceSet, Platform, RequiredActionsMode } from '@activepieces/shared'
import { EntitySchema } from 'typeorm'
import {
    ApIdSchema,
    BaseColumnSchemaPart,
} from '../../../database/database-common'

type PieceSetSchema = {
    platform: Platform
} & PieceSet

export const PieceSetEntity = new EntitySchema<PieceSetSchema>({
    name: 'piece_set',
    columns: {
        ...BaseColumnSchemaPart,
        platformId: {
            ...ApIdSchema,
        },
        name: {
            type: String,
        },
        key: {
            type: String,
            nullable: true,
        },
        isDefault: {
            type: Boolean,
            default: false,
        },
        generatedForProjectId: {
            ...ApIdSchema,
            nullable: true,
        },
        config: {
            type: 'jsonb',
            default: { pieces: { mode: PieceSelectionMode.INCLUDE_ALL, exceptions: [] }, selectedActions: {}, selectedTriggers: {}, requiredActions: { mode: RequiredActionsMode.ANY, actions: {} } },
        },
    },
    indices: [
        {
            name: 'idx_piece_set_platform_id_created_id',
            columns: ['platformId', 'created', 'id'],
            unique: false,
        },
        {
            name: 'idx_piece_set_platform_id_is_default',
            columns: ['platformId'],
            where: '"isDefault" = true',
            unique: true,
        },
        {
            name: 'idx_piece_set_platform_id_key',
            columns: ['platformId', 'key'],
            where: '"key" IS NOT NULL',
            unique: true,
        },
    ],
    relations: {
        platform: {
            type: 'many-to-one',
            target: 'platform',
            onDelete: 'CASCADE',
            joinColumn: {
                name: 'platformId',
                foreignKeyConstraintName: 'fk_piece_set_platform_id',
            },
        },
    },
})