directus

Форк
0
/
20210506A-rename-interfaces.ts 
82 строки · 2.7 Кб
1
import { parseJSON } from '@directus/utils';
2
import type { Knex } from 'knex';
3

4
// [before, after, after-option additions]
5
const changes: [string, string, Record<string, any>?][] = [
6
	['button-links', 'presentation-links'],
7
	['checkboxes', 'select-multiple-checkbox'],
8
	['code', 'input-code'],
9
	['color', 'select-color'],
10
	['datetime', 'datetime'],
11
	['divider', 'presentation-divider'],
12
	['dropdown', 'select-dropdown'],
13
	['dropdown-multiselect', 'select-multiple-dropdown'],
14
	['file', 'file'],
15
	['hash', 'input-hash'],
16
	['icon', 'select-icon'],
17
	['image', 'file-image'],
18
	['m2a-builder', 'list-m2a'],
19
	['many-to-many', 'list-m2m'],
20
	['many-to-one', 'select-dropdown-m2o'],
21
	['markdown', 'input-rich-text-md'],
22
	['notice', 'presentation-notice'],
23
	['numeric', 'input'],
24
	['one-to-many', 'list-o2m'],
25
	['radio-buttons', 'select-radio'],
26
	['repeater', 'list'],
27
	['slider', 'slider'],
28
	['slug', 'input', { slug: true }],
29
	['tags', 'tags'],
30
	['text-input', 'input'],
31
	['textarea', 'input-multiline'],
32
	['toggle', 'boolean'],
33
	['translations', 'translations'],
34
	['tree-view', 'list-o2m-tree-view'],
35
	['user', 'select-dropdown-m2o', { template: '{{avatar.$thumbnail}} {{first_name}} {{last_name}}' }],
36
	['wysiwyg', 'input-rich-text-html'],
37

38
	// System:
39
	['collection', 'system-collection'],
40
	['collections', 'system-collection-multiple'],
41
	['display-template', 'system-display-template'],
42
	['field', 'system-field'],
43
	['interface', 'system-interface'],
44
	['interface-options', 'system-interface-options'],
45
	['scope', 'system-scope'],
46
	['system-language', 'system-language'],
47
	['tfa-setup', 'system-mfa-setup'],
48
];
49

50
export async function up(knex: Knex): Promise<void> {
51
	for (const [before, after, options] of changes) {
52
		// If any options need to be added, update the fields one by one in order to update the pre-existing field options
53
		if (options) {
54
			const fields = await knex
55
				.select<{ id: number; options: Record<string, unknown> }[]>('id', 'options')
56
				.from('directus_fields')
57
				.where({ interface: before });
58

59
			for (const { id, options: existingOptionsRaw } of fields) {
60
				const existingOptions =
61
					typeof existingOptionsRaw === 'string' ? parseJSON(existingOptionsRaw) : existingOptionsRaw;
62

63
				const newOptions = {
64
					...(existingOptions || {}),
65
					...options,
66
				};
67

68
				await knex('directus_fields')
69
					.update({ interface: after, options: JSON.stringify(newOptions) })
70
					.where({ id });
71
			}
72
		} else {
73
			await knex('directus_fields').update({ interface: after }).where({ interface: before });
74
		}
75
	}
76
}
77

78
export async function down(knex: Knex): Promise<void> {
79
	for (const [before, after] of changes) {
80
		await knex('directus_fields').update({ interface: before }).where({ interface: after });
81
	}
82
}
83

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

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

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

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