mirror of
https://github.com/morten-olsen/mini-loader.git
synced 2026-02-08 01:36:26 +01:00
init
This commit is contained in:
56
packages/server/src/database/migrations/migration.init.ts
Normal file
56
packages/server/src/database/migrations/migration.init.ts
Normal 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 };
|
||||
19
packages/server/src/database/migrations/migrations.source.ts
Normal file
19
packages/server/src/database/migrations/migrations.source.ts
Normal 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 };
|
||||
Reference in New Issue
Block a user