Setup migrations

This commit is contained in:
rijkvanzanten
2020-07-08 14:41:12 -04:00
parent 0f607f5ca7
commit 760112475c
5 changed files with 53 additions and 0 deletions

View File

@@ -1,8 +1,11 @@
import knex from 'knex';
import logger from '../logger';
import dotenv from 'dotenv';
import SchemaInspector from '../knex-schema-inspector/lib/index';
dotenv.config();
const log = logger.child({ module: 'sql' });
const database = knex({
@@ -14,6 +17,14 @@ const database = knex({
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
},
migrations: {
extension: 'ts',
directory: './src/database/migrations',
},
seeds: {
extension: 'ts',
directory: './src/database/seeds/',
},
});
database.on('query', (data) => log.trace(data.sql));

View File

View File

@@ -0,0 +1,19 @@
import * as Knex from 'knex';
export async function seed(knex: Knex): Promise<any> {
await knex.schema.dropTableIfExists('directus_activity');
await knex.schema.createTable('directus_activity', (table) => {
table.increments().notNullable();
table.string('action', 45).notNullable();
table.uuid('action_by').nullable();
// table.foreign('action_by').references('directus_users.id');
table.timestamp('action_on').defaultTo(knex.fn.now()).notNullable();
table.string('ip', 50).notNullable();
table.string('user_agent').notNullable();
table.string('collection', 64).notNullable();
// table.foreign('collection').references('directus_collections.collection');
table.string('item').notNullable();
table.text('comment').nullable();
});
}

View File

@@ -0,0 +1,19 @@
import * as Knex from 'knex';
export async function seed(knex: Knex): Promise<any> {
await knex.schema.dropTableIfExists('directus_collection_presets');
await knex.schema.createTable('directus_collection_presets', (table) => {
table.increments().notNullable();
table.string('title').nullable();
table.uuid('user').nullable();
table.string('collection', 64).notNullable();
// table.foreign('collection').references('directus_collections.collection');
table.string('search_query', 100).nullable();
table.json('filters').nullable();
table.string('view_type', 100).notNullable();
table.json('view_query').nullable();
table.json('view_options').nullable();
table.uuid('role').nullable();
});
}

View File

@@ -0,0 +1,4 @@
This is obviously incomplete.
The DB schema is still being worked on. The seeds should be finished once we're closer to release and have a release ready
db schema