@hedhog/admin 0.0.32 → 0.0.33

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hedhog/admin",
3
- "version": "0.0.32",
3
+ "version": "0.0.33",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -10,12 +10,18 @@ export class Migrate implements MigrationInterface {
10
10
  public async up(queryRunner: QueryRunner): Promise<void> {
11
11
  await queryRunner.createTable(
12
12
  new Table({
13
- name: 'settings',
13
+ name: 'setting_groups',
14
14
  columns: [
15
15
  idColumn(),
16
16
  {
17
- name: 'name',
17
+ name: 'icon',
18
+ type: 'varchar',
19
+ length: '31',
20
+ },
21
+ {
22
+ name: 'slug',
18
23
  type: 'varchar',
24
+ length: '63',
19
25
  },
20
26
  timestampColumn(),
21
27
  timestampColumn('updated_at'),
@@ -25,54 +31,144 @@ export class Migrate implements MigrationInterface {
25
31
 
26
32
  await queryRunner.createTable(
27
33
  new Table({
28
- name: 'setting_values',
34
+ name: 'setting_group_translations',
29
35
  columns: [
30
- idColumn(),
31
36
  {
32
- name: 'value',
33
- type: 'varchar',
34
- length: '1023',
37
+ name: 'locale_id',
38
+ type: 'int',
39
+ unsigned: true,
40
+ },
41
+ {
42
+ name: 'group_id',
43
+ type: 'int',
44
+ unsigned: true,
35
45
  },
36
46
  {
37
47
  name: 'name',
38
48
  type: 'varchar',
39
- isUnique: true,
49
+ length: '63',
40
50
  },
41
51
  {
42
52
  name: 'description',
43
53
  type: 'varchar',
54
+ length: '255',
44
55
  isNullable: true,
45
56
  },
57
+ timestampColumn(),
58
+ timestampColumn('updated_at'),
59
+ ],
60
+ foreignKeys: [
61
+ {
62
+ columnNames: ['locale_id'],
63
+ referencedColumnNames: ['id'],
64
+ referencedTableName: 'locales',
65
+ onDelete: 'CASCADE',
66
+ },
46
67
  {
47
- name: 'label',
68
+ columnNames: ['group_id'],
69
+ referencedColumnNames: ['id'],
70
+ referencedTableName: 'setting_groups',
71
+ onDelete: 'CASCADE',
72
+ },
73
+ ],
74
+ }),
75
+ );
76
+
77
+ await queryRunner.createTable(
78
+ new Table({
79
+ name: 'settings',
80
+ columns: [
81
+ idColumn(),
82
+ {
83
+ name: 'slug',
48
84
  type: 'varchar',
49
- isNullable: true,
85
+ isUnique: true,
86
+ length: '63',
50
87
  },
51
88
  {
52
- name: 'setting_id',
89
+ name: 'group_id',
53
90
  type: 'int',
54
91
  unsigned: true,
55
92
  },
93
+ {
94
+ name: 'type',
95
+ type: 'enum',
96
+ enum: ['string', 'number', 'boolean', 'json'],
97
+ default: 'string',
98
+ },
99
+ {
100
+ name: 'value',
101
+ type: 'varchar',
102
+ length: '1023',
103
+ isNullable: true,
104
+ },
56
105
  timestampColumn(),
57
106
  timestampColumn('updated_at'),
58
107
  ],
108
+ foreignKeys: [
109
+ {
110
+ columnNames: ['group_id'],
111
+ referencedColumnNames: ['id'],
112
+ referencedTableName: 'setting_groups',
113
+ onDelete: 'CASCADE',
114
+ },
115
+ ],
59
116
  }),
60
117
  );
61
118
 
62
- // Criação das foreign keys
63
- await queryRunner.createForeignKey(
64
- 'setting_values',
65
- new TableForeignKey({
66
- columnNames: ['setting_id'],
67
- referencedColumnNames: ['id'],
68
- referencedTableName: 'settings',
69
- onDelete: 'CASCADE',
119
+ await queryRunner.createTable(
120
+ new Table({
121
+ name: 'setting_translations',
122
+ columns: [
123
+ {
124
+ name: 'locale_id',
125
+ type: 'int',
126
+ unsigned: true,
127
+ isPrimary: true,
128
+ },
129
+ {
130
+ name: 'setting_id',
131
+ type: 'int',
132
+ unsigned: true,
133
+ isPrimary: true,
134
+ },
135
+ {
136
+ name: 'description',
137
+ type: 'varchar',
138
+ isNullable: true,
139
+ length: '255',
140
+ },
141
+ {
142
+ name: 'name',
143
+ type: 'varchar',
144
+ isNullable: true,
145
+ length: '63',
146
+ },
147
+ timestampColumn(),
148
+ timestampColumn('updated_at'),
149
+ ],
150
+ foreignKeys: [
151
+ {
152
+ columnNames: ['locale_id'],
153
+ referencedColumnNames: ['id'],
154
+ referencedTableName: 'locales',
155
+ onDelete: 'CASCADE',
156
+ },
157
+ {
158
+ columnNames: ['setting_id'],
159
+ referencedColumnNames: ['id'],
160
+ referencedTableName: 'settings',
161
+ onDelete: 'CASCADE',
162
+ },
163
+ ],
70
164
  }),
71
165
  );
72
166
  }
73
167
 
74
168
  public async down(queryRunner: QueryRunner): Promise<void> {
75
- await queryRunner.dropTable('setting_values');
169
+ await queryRunner.dropTable('setting_translations');
76
170
  await queryRunner.dropTable('settings');
171
+ await queryRunner.dropTable('setting_group_translations');
172
+ await queryRunner.dropTable('setting_groups');
77
173
  }
78
174
  }
@@ -0,0 +1,198 @@
1
+ import { MigrationInterface, QueryRunner } from 'typeorm';
2
+
3
+ export class Migrate implements MigrationInterface {
4
+ public async up(queryRunner: QueryRunner): Promise<void> {
5
+ const groups = [
6
+ {
7
+ icon: 'world',
8
+ slug: 'localization',
9
+ name_en: 'Localization',
10
+ name_pt: 'Localização',
11
+ description_en: 'Settings related to localization',
12
+ description_pt: 'Definições relacionadas com a localização',
13
+ settings: [
14
+ {
15
+ slug: 'language',
16
+ type: 'string',
17
+ name_en: 'Language',
18
+ name_pt: 'Idioma',
19
+ description_en: 'The language to use',
20
+ description_pt: 'O idioma a utilizar',
21
+ value: 'en',
22
+ },
23
+ {
24
+ slug: 'timezone',
25
+ type: 'string',
26
+ name_en: 'Timezone',
27
+ name_pt: 'Fuso Horário',
28
+ description_en: 'The timezone to use',
29
+ description_pt: 'O fuso horário a utilizar',
30
+ value: 'UTC',
31
+ },
32
+ ],
33
+ },
34
+ {
35
+ icon: 'paint-brush',
36
+ slug: 'appearance',
37
+ name_en: 'Appearance',
38
+ name_pt: 'Aparência',
39
+ description_en: 'Settings related to appearance',
40
+ description_pt: 'Definições relacionadas com a aparência',
41
+ settings: [
42
+ {
43
+ slug: 'primary',
44
+ type: 'string',
45
+ name_en: 'Primary Color',
46
+ name_pt: 'Cor Primária',
47
+ description_en: 'The primary color to use',
48
+ description_pt: 'A cor primária a utilizar',
49
+ value: '#000000',
50
+ },
51
+ {
52
+ slug: 'secondary',
53
+ type: 'string',
54
+ name_en: 'Secondary Color',
55
+ name_pt: 'Cor Secundária',
56
+ description_en: 'The secondary color to use',
57
+ description_pt: 'A cor secundária a utilizar',
58
+ value: '#FFFFFF',
59
+ },
60
+ {
61
+ slug: 'accent',
62
+ type: 'string',
63
+ name_en: 'Accent Color',
64
+ name_pt: 'Cor de Realce',
65
+ description_en: 'The accent color to use',
66
+ description_pt: 'A cor de realce a utilizar',
67
+ value: '#000000',
68
+ },
69
+ {
70
+ slug: 'background',
71
+ type: 'string',
72
+ name_en: 'Background Color',
73
+ name_pt: 'Cor de Fundo',
74
+ description_en: 'The background color to use',
75
+ description_pt: 'A cor de fundo a utilizar',
76
+ value: '#FFFFFF',
77
+ },
78
+ {
79
+ slug: 'muted',
80
+ type: 'string',
81
+ name_en: 'Muted Color',
82
+ name_pt: 'Cor Suave',
83
+ description_en: 'The muted color to use',
84
+ description_pt: 'A cor suave a utilizar',
85
+ value: '#000000',
86
+ },
87
+ {
88
+ slug: 'radius',
89
+ type: 'number',
90
+ name_en: 'Border Radius',
91
+ name_pt: 'Raio da Borda',
92
+ description_en: 'The border radius to use',
93
+ description_pt: 'O raio da borda a utilizar',
94
+ value: 0.5,
95
+ },
96
+ {
97
+ slug: 'font',
98
+ type: 'string',
99
+ name_en: 'Font Family',
100
+ name_pt: 'Família de Fontes',
101
+ description_en: 'The font family to use',
102
+ description_pt: 'A família de fontes a utilizar',
103
+ value: 'ui-sans-serif, system-ui, sans-serif',
104
+ },
105
+ ],
106
+ },
107
+ ];
108
+
109
+ for (const group of groups) {
110
+ const settingGroup = await queryRunner.manager
111
+ .createQueryBuilder()
112
+ .insert()
113
+ .into('setting_groups', ['icon', 'slug'])
114
+ .values({
115
+ icon: group.icon,
116
+ slug: group.slug,
117
+ })
118
+ .returning('id')
119
+ .execute();
120
+
121
+ const settingGroupId = settingGroup.identifiers[0].id;
122
+
123
+ await queryRunner.manager
124
+ .createQueryBuilder()
125
+ .insert()
126
+ .into('setting_group_translations', [
127
+ 'locale_id',
128
+ 'group_id',
129
+ 'name',
130
+ 'description',
131
+ ])
132
+ .values([
133
+ {
134
+ locale_id: 1,
135
+ group_id: settingGroupId,
136
+ name: group.name_en,
137
+ description: group.description_en,
138
+ },
139
+ {
140
+ locale_id: 2,
141
+ group_id: settingGroupId,
142
+ name: group.name_pt,
143
+ description: group.description_pt,
144
+ },
145
+ ])
146
+ .execute();
147
+
148
+ for (const s of group.settings) {
149
+ const setting = await queryRunner.manager
150
+ .createQueryBuilder()
151
+ .insert()
152
+ .into('settings', ['slug', 'group_id', 'type', 'value'])
153
+ .values({
154
+ slug: s.slug,
155
+ group_id: settingGroupId,
156
+ type: s.type,
157
+ value: s.value,
158
+ })
159
+ .returning('id')
160
+ .execute();
161
+
162
+ const settingId = setting.identifiers[0].id;
163
+
164
+ await queryRunner.manager
165
+ .createQueryBuilder()
166
+ .insert()
167
+ .into('setting_translations', [
168
+ 'locale_id',
169
+ 'setting_id',
170
+ 'name',
171
+ 'description',
172
+ ])
173
+ .values([
174
+ {
175
+ locale_id: 1,
176
+ setting_id: settingId,
177
+ name: s.name_en,
178
+ description: s.description_en,
179
+ },
180
+ {
181
+ locale_id: 2,
182
+ setting_id: settingId,
183
+ name: s.name_pt,
184
+ description: s.description_pt,
185
+ },
186
+ ])
187
+ .execute();
188
+ }
189
+ }
190
+ }
191
+
192
+ public async down(queryRunner: QueryRunner): Promise<void> {
193
+ await queryRunner.query('DELETE FROM setting_translations');
194
+ await queryRunner.query('DELETE FROM settings');
195
+ await queryRunner.query('DELETE FROM setting_group_translations');
196
+ await queryRunner.query('DELETE FROM setting_groups');
197
+ }
198
+ }