diff --git a/packages/backend/src/db/migrations/20220219100800_create_execution_steps.ts b/packages/backend/src/db/migrations/20220219100800_create_execution_steps.ts new file mode 100644 index 00000000..eef61a81 --- /dev/null +++ b/packages/backend/src/db/migrations/20220219100800_create_execution_steps.ts @@ -0,0 +1,18 @@ +import { Knex } from 'knex'; + +export async function up(knex: Knex): Promise { + return knex.schema.createTable('execution_steps', (table) => { + table.increments('id'); + table.integer('execution_id').references('id').inTable('executions'); + table.integer('step_id').references('id').inTable('steps'); + table.string('status'); + table.text('data_in'); + table.text('data_out'); + + table.timestamps(true, true); + }); +} + +export async function down(knex: Knex): Promise { + return knex.schema.dropTable('execution_steps'); +} diff --git a/packages/backend/src/models/execution-step.ts b/packages/backend/src/models/execution-step.ts new file mode 100644 index 00000000..d4743a99 --- /dev/null +++ b/packages/backend/src/models/execution-step.ts @@ -0,0 +1,39 @@ +import Base from './base'; +import Execution from './execution'; + +class ExecutionStep extends Base { + id!: string; + executionId!: number; + stepId!: number; + dataIn!: any; + dataOut!: any; + status: string; + + static tableName = 'execution_steps'; + + static jsonSchema = { + type: 'object', + + properties: { + id: { type: 'string' }, + executionId: { type: 'integer' }, + stepId: { type: 'integer' }, + dataIn: { type: 'object' }, + dataOut: { type: 'object' }, + status: { type: 'string', enum: ['success', 'failure'] }, + }, + }; + + static relationMappings = () => ({ + execution: { + relation: Base.BelongsToOneRelation, + modelClass: Execution, + join: { + from: 'execution_steps.execution_id', + to: 'executions.id', + }, + }, + }); +} + +export default ExecutionStep;