Add defaults to migrations

This commit is contained in:
rijkvanzanten
2020-10-29 14:22:22 -04:00
parent bcb4041ff9
commit b54f9a9ab1
3 changed files with 46 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
import Knex from 'knex';
import { merge } from 'lodash';
export async function up(knex: Knex) {
await knex('directus_relations')
@@ -8,6 +9,16 @@ export async function up(knex: Knex) {
}
export async function down(knex: Knex) {
const defaults = {
many_collection: 'directus_users',
many_field: null,
many_primary: null,
one_collection: null,
one_field: null,
one_primary: null,
junction_field: null,
};
const systemRelations = [
{
many_collection: 'directus_users',
@@ -103,7 +114,7 @@ export async function down(knex: Knex) {
one_collection: 'directus_files',
one_primary: 'id',
},
];
].map((row) => merge({}, defaults, row));
await knex.insert(systemRelations).into('directus_relations');
}

View File

@@ -1,10 +1,21 @@
import Knex from 'knex';
import { merge } from 'lodash';
export async function up(knex: Knex) {
await knex('directus_collections').delete().where('collection', 'like', 'directus_%');
}
export async function down(knex: Knex) {
const defaults = {
collection: null,
hidden: false,
singleton: false,
icon: null,
note: null,
translations: null,
display_template: null,
};
const systemCollections = [
{
collection: 'directus_activity',
@@ -74,7 +85,7 @@ export async function down(knex: Knex) {
collection: 'directus_webhooks',
note: 'Configuration for event-based HTTP requests',
},
];
].map((row) => merge({}, defaults, row));
await knex.insert(systemCollections).into('directus_collections');
}

View File

@@ -1,5 +1,23 @@
import Knex from 'knex';
import { uniq } from 'lodash';
import { uniq, merge } from 'lodash';
const defaults = {
collection: null,
field: null,
special: null,
interface: null,
options: null,
display: null,
display_options: null,
locked: false,
readonly: false,
hidden: false,
sort: null,
width: 'full',
group: null,
translations: null,
note: null,
};
const systemFields = [
{
@@ -1612,10 +1630,11 @@ const systemFields = [
locked: true,
special: 'csv',
},
];
].map((row) => merge({}, defaults, row));
export async function up(knex: Knex) {
const fieldKeys = uniq(systemFields.map((field) => field.field));
const fieldKeys = uniq(systemFields.map((field: any) => field.field));
await knex('directus_fields')
.delete()
.where('collection', 'like', 'directus_%')