feat: Create template model

This commit is contained in:
Faruk AYDIN
2025-02-17 14:48:25 +01:00
parent 3fa677f3d0
commit 2e279d4709
4 changed files with 74 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
export async function up(knex) {
return knex.schema.createTable('templates', (table) => {
table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()'));
table.string('name');
table.jsonb('flow_data');
table.timestamps(true, true);
});
}
export async function down(knex) {
return knex.schema.dropTable('templates');
}

View File

@@ -0,0 +1,29 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`Template model > jsonSchema should have correct validations 1`] = `
{
"properties": {
"createdAt": {
"type": "string",
},
"flowData": {
"type": "object",
},
"id": {
"format": "uuid",
"type": "string",
},
"name": {
"minLength": 1,
"type": "string",
},
"updatedAt": {
"type": "string",
},
},
"required": [
"name",
],
"type": "object",
}
`;

View File

@@ -0,0 +1,20 @@
import Base from './base.js';
class Template extends Base {
static tableName = 'templates';
static jsonSchema = {
type: 'object',
required: ['name'],
properties: {
id: { type: 'string', format: 'uuid' },
name: { type: 'string', minLength: 1 },
flowData: { type: 'object' },
createdAt: { type: 'string' },
updatedAt: { type: 'string' },
},
};
}
export default Template;

View File

@@ -0,0 +1,12 @@
import { describe, it, expect } from 'vitest';
import Template from './template.js';
describe('Template model', () => {
it('tableName should return correct name', () => {
expect(Template.tableName).toBe('templates');
});
it('jsonSchema should have correct validations', () => {
expect(Template.jsonSchema).toMatchSnapshot();
});
});