mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add defaults to migrations
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
@@ -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_%')
|
||||
|
||||
Reference in New Issue
Block a user