Move sortField to relationship setup (#4304)

* Add migration

* Add sort field to relation types

* Remove sortfield options in favor of relationship

* Add sort field configuration to relational setup

* Save m2a sortfield on the correct row

* Add default sort field to system data
This commit is contained in:
Rijk van Zanten
2021-02-25 19:13:36 -05:00
committed by GitHub
parent f088074d48
commit db30acbb8a
23 changed files with 611 additions and 754 deletions

View File

@@ -0,0 +1,33 @@
import Knex from 'knex';
export async function up(knex: Knex) {
await knex.schema.alterTable('directus_relations', (table) => {
table.string('sort_field');
});
const fieldsWithSort = await knex
.select('collection', 'field', 'options')
.from('directus_fields')
.whereIn('interface', ['one-to-many', 'm2a-builder', 'many-to-many']);
for (const field of fieldsWithSort) {
const options = typeof field.options === 'string' ? JSON.parse(field.options) : field.options ?? {};
if ('sortField' in options) {
await knex('directus_relations')
.update({
sort_field: options.sortField,
})
.where({
one_collection: field.collection,
one_field: field.field,
});
}
}
}
export async function down(knex: Knex) {
await knex.schema.alterTable('directus_relations', (table) => {
table.dropColumn('sort_field');
});
}

View File

@@ -8,6 +8,7 @@ defaults:
one_field: null
one_primary: null
junction_field: null
sort_field: null
data:
- many_collection: directus_users

View File

@@ -11,4 +11,7 @@ export type Relation = {
one_collection_field: string | null;
one_allowed_collections: string | null;
junction_field: string | null;
sort_field: string | null;
};