directus

Форк
0
/
20201029A-remove-system-relations.ts 
128 строк · 2.9 Кб
1
import type { Knex } from 'knex';
2
import { merge } from 'lodash-es';
3

4
export async function up(knex: Knex): Promise<void> {
5
	await knex('directus_relations')
6
		.delete()
7
		.where('many_collection', 'like', 'directus_%')
8
		.andWhere('one_collection', 'like', 'directus_%');
9
}
10

11
export async function down(knex: Knex): Promise<void> {
12
	const defaults = {
13
		many_collection: 'directus_users',
14
		many_field: null,
15
		many_primary: null,
16
		one_collection: null,
17
		one_field: null,
18
		one_primary: null,
19
		junction_field: null,
20
	};
21

22
	const systemRelations = [
23
		{
24
			many_collection: 'directus_users',
25
			many_field: 'role',
26
			many_primary: 'id',
27
			one_collection: 'directus_roles',
28
			one_field: 'users',
29
			one_primary: 'id',
30
		},
31
		{
32
			many_collection: 'directus_users',
33
			many_field: 'avatar',
34
			many_primary: 'id',
35
			one_collection: 'directus_files',
36
			one_primary: 'id',
37
		},
38
		{
39
			many_collection: 'directus_revisions',
40
			many_field: 'activity',
41
			many_primary: 'id',
42
			one_collection: 'directus_activity',
43
			one_field: 'revisions',
44
			one_primary: 'id',
45
		},
46
		{
47
			many_collection: 'directus_presets',
48
			many_field: 'user',
49
			many_primary: 'id',
50
			one_collection: 'directus_users',
51
			one_primary: 'id',
52
		},
53
		{
54
			many_collection: 'directus_presets',
55
			many_field: 'role',
56
			many_primary: 'id',
57
			one_collection: 'directus_roles',
58
			one_primary: 'id',
59
		},
60
		{
61
			many_collection: 'directus_folders',
62
			many_field: 'parent',
63
			many_primary: 'id',
64
			one_collection: 'directus_folders',
65
			one_primary: 'id',
66
		},
67
		{
68
			many_collection: 'directus_files',
69
			many_field: 'folder',
70
			many_primary: 'id',
71
			one_collection: 'directus_folders',
72
			one_primary: 'id',
73
		},
74
		{
75
			many_collection: 'directus_files',
76
			many_field: 'uploaded_by',
77
			many_primary: 'id',
78
			one_collection: 'directus_users',
79
			one_primary: 'id',
80
		},
81
		{
82
			many_collection: 'directus_fields',
83
			many_field: 'collection',
84
			many_primary: 'id',
85
			one_collection: 'directus_collections',
86
			one_field: 'fields',
87
			one_primary: 'collection',
88
		},
89
		{
90
			many_collection: 'directus_activity',
91
			many_field: 'user',
92
			many_primary: 'id',
93
			one_collection: 'directus_users',
94
			one_primary: 'id',
95
		},
96
		{
97
			many_collection: 'directus_settings',
98
			many_field: 'project_logo',
99
			many_primary: 'id',
100
			one_collection: 'directus_files',
101
			one_primary: 'id',
102
		},
103
		{
104
			many_collection: 'directus_settings',
105
			many_field: 'public_foreground',
106
			many_primary: 'id',
107
			one_collection: 'directus_files',
108
			one_primary: 'id',
109
		},
110
		{
111
			many_collection: 'directus_settings',
112
			many_field: 'public_background',
113
			many_primary: 'id',
114
			one_collection: 'directus_files',
115
			one_primary: 'id',
116
		},
117
	].map((row) => {
118
		for (const [key, value] of Object.entries(row)) {
119
			if (value !== null && (typeof value === 'object' || Array.isArray(value))) {
120
				(row as any)[key] = JSON.stringify(value);
121
			}
122
		}
123

124
		return merge({}, defaults, row);
125
	});
126

127
	await knex.insert(systemRelations).into('directus_relations');
128
}
129

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.