mirror of
https://github.com/directus/directus.git
synced 2026-01-29 13:38:05 -05:00
Setup migrations
This commit is contained in:
@@ -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));
|
||||
|
||||
0
src/database/migrations/.gitkeep
Normal file
0
src/database/migrations/.gitkeep
Normal file
19
src/database/seeds/activity.ts
Normal file
19
src/database/seeds/activity.ts
Normal 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();
|
||||
});
|
||||
}
|
||||
19
src/database/seeds/collection-presets.ts
Normal file
19
src/database/seeds/collection-presets.ts
Normal 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();
|
||||
});
|
||||
}
|
||||
4
src/database/seeds/readme.md
Normal file
4
src/database/seeds/readme.md
Normal 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
|
||||
Reference in New Issue
Block a user