A
A
Alexander Sobolev2021-08-31 18:48:04
Algorithms
Alexander Sobolev, 2021-08-31 18:48:04

Users and work schedule: how to store?

Hello!
There are a number of users: Array U (user)
There is a work schedule, an array of dates D (date) with different states T (type): Working day, Day off, Sick leave, Day off, etc.

Brain torment for the second day already.. in what form is it better to store this array in the database..

[user_id][date] =[type]
[user_id][date_type] = {date, date2..date N}
[date] =[ [ user:type],[user2:type].. ]

to make it as easy as possible to make selections by dates and states for users ?
What is the best way to get away?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Adamos, 2021-08-31
@Adamos

[user_id, date, type, INDEX(user_id), INDEX(date), UNIQUE(iser_id, date)]

A
Akina, 2021-08-31
@Akina

What is the best way to store this array in the database?

There is a trivial "many-to-many" relationship. And, accordingly, storage - two tables of related entities and a linking table. Those.
1) User(user_id, name, ...);
2) Dates (date, type, ...);
3) UsersDates(user_id references User(user_id), date references Dates(date));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question