directus

Форк
0
/
20230927A-themes.ts 
60 строк · 2.1 Кб
1
import type { Knex } from 'knex';
2

3
export async function up(knex: Knex): Promise<void> {
4
	/**
5
	 * Knex doesn't support setting defaults to null (you'll end up with `NULL::character varying`),
6
	 * so we'll have to create a new column, copy over the relevant bits, and remove the old
7
	 */
8
	await knex.schema.alterTable('directus_users', (table) => {
9
		table.string('appearance');
10
	});
11

12
	await knex('directus_users').update({ appearance: 'dark' }).where({ theme: 'dark' });
13
	await knex('directus_users').update({ appearance: 'light' }).where({ theme: 'light' });
14

15
	await knex.schema.alterTable('directus_users', (table) => {
16
		table.dropColumn('theme');
17
		table.string('theme_dark');
18
		table.string('theme_light');
19
		table.json('theme_light_overrides');
20
		table.json('theme_dark_overrides');
21
	});
22

23
	await knex('directus_settings').update({ project_color: '#6644ff' }).whereNull('project_color');
24

25
	await knex.schema.alterTable('directus_settings', (table) => {
26
		table.string('project_color').defaultTo('#6644FF').notNullable().alter();
27
		table.uuid('public_favicon').references('directus_files.id');
28

29
		table.string('default_appearance').defaultTo('auto').notNullable();
30
		table.string('default_theme_light');
31
		table.json('theme_light_overrides');
32
		table.string('default_theme_dark');
33
		table.json('theme_dark_overrides');
34
	});
35
}
36

37
export async function down(knex: Knex): Promise<void> {
38
	await knex.schema.alterTable('directus_users', (table) => {
39
		table.renameColumn('appearance', 'theme');
40
	});
41

42
	await knex.schema.alterTable('directus_users', (table) => {
43
		table.string('theme').defaultTo('auto').alter();
44
		table.dropColumn('theme_dark');
45
		table.dropColumn('theme_light');
46
		table.dropColumn('theme_light_overrides');
47
		table.dropColumn('theme_dark_overrides');
48
	});
49

50
	await knex.schema.alterTable('directus_settings', (table) => {
51
		table.string('project_color').defaultTo(null).nullable().alter();
52

53
		table.dropColumn('public_favicon');
54
		table.dropColumn('default_appearance');
55
		table.dropColumn('default_theme_light');
56
		table.dropColumn('theme_light_overrides');
57
		table.dropColumn('default_theme_dark');
58
		table.dropColumn('theme_dark_overrides');
59
	});
60
}
61

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

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

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

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