diff --git a/packages/backend/src/db/migrations/20220219093113_create_executions.ts b/packages/backend/src/db/migrations/20220219093113_create_executions.ts new file mode 100644 index 00000000..a5140d52 --- /dev/null +++ b/packages/backend/src/db/migrations/20220219093113_create_executions.ts @@ -0,0 +1,15 @@ +import { Knex } from 'knex'; + +export async function up(knex: Knex): Promise { + return knex.schema.createTable('executions', (table) => { + table.increments('id'); + table.integer('flow_id').references('id').inTable('flows'); + table.boolean('test_run').notNullable().defaultTo(false); + + table.timestamps(true, true); + }); +} + +export async function down(knex: Knex): Promise { + return knex.schema.dropTable('executions'); +} diff --git a/packages/backend/src/models/execution.ts b/packages/backend/src/models/execution.ts new file mode 100644 index 00000000..eaa74c08 --- /dev/null +++ b/packages/backend/src/models/execution.ts @@ -0,0 +1,33 @@ +import Base from './base'; +import Flow from './flow'; + +class Execution extends Base { + id!: string; + flowId!: number; + testRun: boolean; + + static tableName = 'executions'; + + static jsonSchema = { + type: 'object', + + properties: { + id: { type: 'string' }, + flowId: { type: 'integer' }, + testRun: { type: 'boolean' }, + }, + }; + + static relationMappings = () => ({ + flow: { + relation: Base.BelongsToOneRelation, + modelClass: Flow, + join: { + from: 'executions.flow_id', + to: 'flows.id', + }, + }, + }); +} + +export default Execution;