feat: Create template model
This commit is contained in:
@@ -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');
|
||||
}
|
||||
@@ -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",
|
||||
}
|
||||
`;
|
||||
20
packages/backend/src/models/template.js
Normal file
20
packages/backend/src/models/template.js
Normal 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;
|
||||
12
packages/backend/src/models/template.test.js
Normal file
12
packages/backend/src/models/template.test.js
Normal 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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user