Within the database (in this case, PostgreSQL, but this is not the point) there are several small tables that contain practically immutable, but very often used data:
- page groups (pagegroups),
- pages (pages),
- templates
- Positions on pages (positions)
- modules (modules),
- user groups (usergroups).
Each table has the ID, title, alias, and display order fields. There are connections between the data:
- user groups have different access rights
- modules can be found at different positions on different pages,
- each page can have its own template,
- The template consists of positions (header, sidebar_left, canvas, sidebar_right, footer), which can be displayed or not , etc. (the list of links should remain open)
I want to put all the data in one table, where to present the data in the form of "key / value". Broke the whole head. Example database (PostgreSQL):
CREATE TABLE core ( id serial primary key, level int, group int, parent int references core, key text, value text );
Fragment of data:
INSERT INTO core (id, level, group, parent, key, value) VALUES (1, 0, 1, 0, 'type', 'coreelements'), (2, 0, 1, 0, 'name', 'Компоненты системы'), (3, 1, 2, 1, 'type', 'page'), (4, 1, 2, 1, 'name', 'Страницы'), (5, 1, 2, 1, 'order', ''), (6, 1, 3, 1, 'type', 'template'), (7, 1, 3, 1, 'name', 'Шаблоны'), (8, 1, 3, 1, 'order', ''), (9, 1, 4, 1, 'type', 'position'), (10, 1, 4, 1, 'name', 'Позиции'), (11, 1, 4, 1, 'order', '18,19,20,21,22'), (12, 1, 5, 1, 'type', 'module'), (13, 1, 5, 1, 'name', 'Модули'), (14, 1, 5, 1, 'order', ''), (15, 2, 18, 4, 'name', 'Шапка'), (16, 2, 18, 4, 'alias', 'header'), (17, 2, 19, 4, 'name', 'Рабочая зона'), (18, 2, 19, 4, 'alias', 'canvas'), (19, 2, 20, 4, 'name', 'Левый сайдбар'), (20, 2, 20, 4, 'alias', 'sidebar_left'), (21, 2, 21, 4, 'name', 'Правый сайдбар'), (22, 2, 21, 4, 'alias', 'sidebar_right'), (23, 2, 22, 4, 'name', 'Подвал'), (24, 2, 22, 4, 'alias', 'footer');
In addition to the general question about the structure of the table confuses me this:
- The need for the level field is not sure, remove?
- Since the parent and the dependent entries have several key / value pairs, how do you organize the connection? by ID, by group or the third way? In other words, what should be in the parent field?
- How to link, say, pages, modules and templates?
Example for the last question:
Страница 'settings', в header имеет модуль 6, в canvas - модули 1, 3 и 2, в остальных - ничего.
I fully admit that after such a table is obtained, I will return to the original - normalized - variant. But since there is an opportunity to try different options - I want to try this one too.