This commit is contained in:
Morten Olsen
2024-01-11 09:03:14 +01:00
commit 0ac0c918fa
81 changed files with 6979 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
import { Knex } from 'knex';
const name = 'init';
const up = async (knex: Knex) => {
await knex.schema.createTable('loads', (table) => {
table.string('id').primary();
table.string('name').nullable();
table.string('script').notNullable();
});
await knex.schema.createTable('runs', (table) => {
table.string('id').primary();
table.string('loadId').notNullable();
table.string('status').notNullable();
table.string('script').notNullable();
table.string('input').nullable();
table.string('error').nullable();
table.timestamp('startedAt').nullable();
table.timestamp('endedAt').nullable();
table.index('loadId');
table.index('status');
});
await knex.schema.createTable('logs', (table) => {
table.string('id').primary();
table.string('runId').notNullable();
table.string('loadId').notNullable();
table.string('severity').notNullable();
table.string('message').notNullable();
table.jsonb('data').nullable();
table.timestamp('timestamp').notNullable();
table.index('runId');
});
await knex.schema.createTable('artifacts', (table) => {
table.string('id').primary();
table.string('name').notNullable();
table.string('runId').notNullable();
table.string('loadId').notNullable();
table.text('data').notNullable();
table.index('runId');
});
};
const down = async (knex: Knex) => {
await knex.schema.dropTable('loads');
await knex.schema.dropTable('runs');
await knex.schema.dropTable('logs');
await knex.schema.dropTable('artifacts');
};
export { name, up, down };

View File

@@ -0,0 +1,19 @@
import { Knex } from 'knex';
import * as init from './migration.init.js';
type Migration = {
name: string;
up: (knex: Knex) => Promise<void>;
down: (knex: Knex) => Promise<void>;
};
const migrations = [init] satisfies Migration[];
const source: Knex.MigrationSource<Migration> = {
getMigrations: async () => migrations,
getMigration: async (migration) => migration,
getMigrationName: (migration) => migration.name,
};
export { source };