refactor: convert IDs to uuid

This commit is contained in:
Ali BARIN
2022-03-03 21:42:16 +01:00
committed by Ömer Faruk Aydın
parent 0c183eeadd
commit 02af7948e5
17 changed files with 45 additions and 31 deletions

View File

@@ -18,6 +18,7 @@
"dependencies": {
"@automatisch/web": "0.1.0",
"@octokit/oauth-methods": "^1.2.6",
"ajv-formats": "^2.1.1",
"axios": "0.24.0",
"bcrypt": "^5.0.1",
"cors": "^2.8.5",

View File

@@ -2,7 +2,7 @@ import { Knex } from "knex";
export async function up(knex: Knex): Promise<void> {
return knex.schema.createTable('users', (table) => {
table.increments('id');
table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()'));
table.string('email').unique().notNullable();
table.string('password').notNullable();

View File

@@ -2,11 +2,11 @@ import { Knex } from "knex";
export async function up(knex: Knex): Promise<void> {
return knex.schema.createTable('credentials', (table) => {
table.increments('id');
table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()'))
table.string('key').notNullable();
table.string('display_name').notNullable();
table.text('data').notNullable();
table.integer('user_id').references('id').inTable('users');
table.uuid('user_id').references('id').inTable('users');
table.boolean('verified').defaultTo(false);
table.timestamps(true, true);

View File

@@ -2,11 +2,11 @@ import { Knex } from 'knex';
export async function up(knex: Knex): Promise<void> {
return knex.schema.createTable('steps', (table) => {
table.increments('id');
table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()'))
table.string('key').notNullable();
table.string('app_key').notNullable();
table.string('type').notNullable();
table.integer('connection_id').references('id').inTable('connections');
table.uuid('connection_id').references('id').inTable('connections');
table.text('parameters');
table.timestamps(true, true);

View File

@@ -2,9 +2,9 @@ import { Knex } from "knex";
export async function up(knex: Knex): Promise<void> {
return knex.schema.createTable('flows', (table) => {
table.increments('id');
table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()'))
table.string('name');
table.integer('user_id').references('id').inTable('users');
table.uuid('user_id').references('id').inTable('users');
table.timestamps(true, true);
});

View File

@@ -3,7 +3,7 @@ import { Knex } from "knex";
export async function up(knex: Knex): Promise<void> {
return knex.schema.table('steps', (table) => {
table
.integer('flow_id')
.uuid('flow_id')
.references('id')
.inTable('flows');
});

View File

@@ -2,8 +2,8 @@ import { Knex } from 'knex';
export async function up(knex: Knex): Promise<void> {
return knex.schema.createTable('executions', (table) => {
table.increments('id');
table.integer('flow_id').references('id').inTable('flows');
table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()'))
table.uuid('flow_id').references('id').inTable('flows');
table.boolean('test_run').notNullable().defaultTo(false);
table.timestamps(true, true);

View File

@@ -2,9 +2,9 @@ import { Knex } from 'knex';
export async function up(knex: Knex): Promise<void> {
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.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()'))
table.uuid('execution_id').references('id').inTable('executions');
table.uuid('step_id').references('id').inTable('steps');
table.string('status');
table.text('data_in');
table.text('data_out');

View File

@@ -2,7 +2,7 @@ import { Knex } from 'knex';
export async function up(knex: Knex): Promise<void> {
return knex.schema.alterTable('steps', (table) => {
table.jsonb('parameters').alter();
table.jsonb('parameters').defaultTo('{}').alter();
});
}

View File

@@ -7,13 +7,13 @@ type Params = {
key: string;
appKey: string;
flow: {
id: number;
id: string;
};
connection: {
id: number;
id: string;
};
previousStep: {
id: number;
id: string;
};
};
};
@@ -43,7 +43,6 @@ const createStepResolver = async (
appKey: input.appKey,
type: 'action',
position: previousStep.position + 1,
parameters: {},
});
const nextSteps = await flow

View File

@@ -1,5 +1,6 @@
import { Model, snakeCaseMappers } from 'objection';
import { AjvValidator, Model, snakeCaseMappers } from 'objection';
import type { QueryContext, ModelOptions, ColumnNameMappers } from 'objection';
import addFormats from 'ajv-formats';
class Base extends Model {
createdAt!: string;
@@ -9,6 +10,19 @@ class Base extends Model {
return snakeCaseMappers();
}
static createValidator() {
return new AjvValidator({
onCreateAjv: (ajv) => {
addFormats.default(ajv);
},
options: {
allErrors: true,
validateSchema: true,
ownProperties: true,
},
});
}
async $beforeInsert(queryContext: QueryContext): Promise<void> {
await super.$beforeInsert(queryContext);

View File

@@ -20,10 +20,10 @@ class Connection extends Base {
required: ['key', 'data'],
properties: {
id: { type: 'string' },
id: { type: 'string', format: 'uuid' },
key: { type: 'string', minLength: 1, maxLength: 255 },
data: { type: 'object' },
userId: { type: 'string' },
userId: { type: 'string', format: 'uuid' },
verified: { type: 'boolean' },
},
};

View File

@@ -16,8 +16,8 @@ class ExecutionStep extends Base {
type: 'object',
properties: {
id: { type: 'string' },
executionId: { type: 'string' },
id: { type: 'string', format: 'uuid' },
executionId: { type: 'string', format: 'uuid' },
stepId: { type: 'string' },
dataIn: { type: 'object' },
dataOut: { type: 'object' },

View File

@@ -14,8 +14,8 @@ class Execution extends Base {
type: 'object',
properties: {
id: { type: 'string' },
flowId: { type: 'integer' },
id: { type: 'string', format: 'uuid' },
flowId: { type: 'string', format: 'uuid' },
testRun: { type: 'boolean' },
},
};

View File

@@ -15,9 +15,9 @@ class Flow extends Base {
type: 'object',
properties: {
id: { type: 'string' },
id: { type: 'string', format: 'uuid' },
name: { type: 'string' },
userId: { type: 'string' },
userId: { type: 'string', format: 'uuid' },
active: { type: 'boolean' },
},
};

View File

@@ -25,12 +25,12 @@ class Step extends Base {
required: ['type'],
properties: {
id: { type: 'string' },
flowId: { type: 'string' },
id: { type: 'string', format: 'uuid' },
flowId: { type: 'string', format: 'uuid' },
key: { type: ['string', 'null'] },
appKey: { type: ['string', 'null'], minLength: 1, maxLength: 255 },
type: { type: 'string', enum: ['action', 'trigger'] },
connectionId: { type: ['string', 'null'] },
connectionId: { type: ['string', 'null'], format: 'uuid' },
status: { type: 'string', enum: ['incomplete', 'completed'] },
position: { type: 'integer' },
parameters: { type: 'object' },

View File

@@ -20,7 +20,7 @@ class User extends Base {
required: ['email', 'password'],
properties: {
id: { type: 'string' },
id: { type: 'string', format: 'uuid' },
email: { type: 'string', format: 'email', minLength: 1, maxLength: 255 },
password: { type: 'string', minLength: 1, maxLength: 255 },
},