U
U
Uglik2016-01-29 11:34:53
MySQL
Uglik, 2016-01-29 11:34:53

Database design. Links between profiles?

Hello.
Database design question. How would you design the databases in the example below and organize the communication between them.
There is a profile of the Hairdresser and the Client. As I understand it, a USERS table is created where authorization data is stored (id, login, email, password, usergroup) and there are 2 profiles, they have only one thing in common (avatar, and full name).
Hairdresser Profile: stores data (full name, profile picture, city of residence [separate table in cities by one-to-many connection], haircuts [separate table with haircut names], prices, contacts [separate table with contacts {landline phone, mobile phone, skype and td}], about yourself, portfolio [separate table with photos], testimonials [separate table with reviews for each hairdresser]) and link to the appointment table (date, time and place).
Client profile : stores full name and avatar data and a connection with the hairdresser's preliminary reservation table for a specific date and time.
Interested in how to be with profiles? How would you design this relationship in this situation? Would you create 2 profile tables, one for the client and one for the hairdresser, and keep your data for each, or would you combine everything into one?
One more thing about expansion. For example, if in the future you add a make-up artist and, as I assume, he will have his own profile with his information.
How to competently and correctly design this task and link the user table with the profiles of the client and the hairdresser or makeup artist?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Andrey, 2016-01-29
@VladimirAndreev

different tables

S
Stanislav Makarov, 2016-01-29
@Nipheris

martinfowler.com/eaaCatalog/classTableInheritance.html

P
Peter, 2016-01-29
@petermzg

Why can't a client be a hairdresser? Therefore, a separate table of people profiles is required. (name, addresses, avatars)
And then a table of hairdressers in which there is a link to a person, and then the specific data of a hairdresser.

A
Alexey Lebedev, 2016-01-29
@swanrnd

One table, the difference is not significant, there will be a couple of empty fields and that's it.

U
Uglik, 2016-01-29
@Uglik

Even more confused. So one table of profiles to do or 2?
Option one :
Users:

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Номер записи',
  `username` varchar(255) NOT NULL COMMENT 'Имя пользователя',
  `email` varchar(255) NOT NULL COMMENT 'Электропочта',
  `password` varchar(255) NOT NULL COMMENT 'Пароль',
   PRIMARY KEY (`id`)
)

Group of users:
CREATE TABLE `groups` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Номер записи',
  `name` varchar(255) NOT NULL COMMENT 'Имя группы пользователей',
   PRIMARY KEY (`id`)
)

Sets of groups that each user belongs to
CREATE TABLE `usergroups` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Номер записи',
  `user_id` int(11) NOT NULL COMMENT 'ID пользователя',
  `group_id` int(11) NOT NULL COMMENT 'ID группы пользователей',
   PRIMARY KEY (`id`)
)

And one table with profiles:
CREATE TABLE `profile` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Номер записи',
  `user_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Номер записи',
  `avatar` varchar(255) NOT NULL COMMENT 'Аватарка',
  `firstname` varchar(255) NOT NULL COMMENT 'Имя пользователя',
  `lastname` varchar(255) NOT NULL COMMENT 'Фамилия пользователя',
  `about` text COMMENT 'О себе',
  `location_id` int(11) NOT NULL COMMENT 'Индификатор города',
  `haircut_id` int(11) NOT NULL COMMENT 'Индификатор стрижки',
  `price` decimal(10,2) NOT NULL COMMENT 'Индификатор стрижки',
  `contacts_id` int(11) NOT NULL COMMENT 'Индификатор контакта',
  `portfolio_id` int(11) NOT NULL COMMENT 'Индификатор портфолио',
  `reviews_id` int(11) NOT NULL COMMENT 'Индификатор отзыва',
   PRIMARY KEY (`id`)
)

In this case, there will be many fields empty, but many fields NOT NULL with indicators of other tables with data. How to be in this situation.
Option two : The
same only 2 profile tables:
Hairdressers
CREATE TABLE `profile_hairdresser` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Номер записи',
  `user_id` int(11) NOT NULL COMMENT 'Номер записи',
  `avatar` varchar(255) NOT NULL COMMENT 'Аватарка',
  `firstname` varchar(255) NOT NULL COMMENT 'Имя пользователя',
  `lastname` varchar(255) NOT NULL COMMENT 'Фамилия пользователя',
  `about` text COMMENT 'О себе',
  `location_id` int(11) NOT NULL COMMENT 'Индификатор города',
  `haircut_id` int(11) NOT NULL COMMENT 'Индификатор стрижки',
  `price` decimal(10,2) NOT NULL COMMENT 'Индификатор стрижки',
  `contacts_id` int(11) NOT NULL COMMENT 'Индификатор контакта',
  `portfolio_id` int(11) NOT NULL COMMENT 'Индификатор портфолио',
  `reviews_id` int(11) NOT NULL COMMENT 'Индификатор отзыва',
   PRIMARY KEY (`id`)
)

Clients
CREATE TABLE `profile_client` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Номер записи',
  `user_id` int(11) NOT NULL COMMENT 'Номер записи',
  `avatar` varchar(255) NOT NULL COMMENT 'Аватарка',
  `firstname` varchar(255) NOT NULL COMMENT 'Имя пользователя',
  `lastname` varchar(255) NOT NULL COMMENT 'Фамилия пользователя',
   PRIMARY KEY (`id`)
)

In this situation, I then do not understand how to link profiles with users through a many-to-many relationship. Please send an example if you don't mind.
An intermediate table is obtained like:
CREATE TABLE `profile_client_hairdresser` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Номер записи',
  `user_id` int(11) NOT NULL COMMENT 'ID пользователя',
  `profile_id` int(11) NOT NULL COMMENT 'ID профиля пользователей',
   PRIMARY KEY (`id`)
)

BUT we have 2 profiles!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question