Executing an order in PHP / MySQL CMS and working with concurrency

I have the following tables:

=======================           =======================
| galleries           |           | images              |
|---------------------|           |---------------------|
| PK | gallery_id     |<--\       | PK | image_id       |
|    | name           |    \      |    | title          |
|    | description    |     \     |    | description    |
|    | max_images     |      \    |    | filename       |
=======================       \-->| FK | gallery_id     |
                                  =======================

I need to implement a way in which images associated with a gallery are sorted in a specific order. As I understand it, relational databases are not designed for hierarchical ordering.

I also want to prepare for the concurrency feature, although this is unlikely to be a problem in my current project, as it is a single-user application. (So, the priority here is to allow the user to reorder).

I am not sure if this is the best way since I have never implemented orders in a database and not new to concurrency. Because of this, I read about locking MySQL tables and am not sure if this is a situation where I have to implement it.

Here are my two ideas:

  • order_num images. , .

  • order_num images ( 1 ). .

!

+3
3

: - , . , , , .

, , , , . 1 , , , .. , , , , , 2 , .

: , , , javascript. , , . order_num .

, , - , 1 2 , , , , . , , , .

, , , , . , , , .

, .

+4

, " " order_num . InnoDB , .

+1

: id (auto increment) . . id, parent.

Concurrency: concurrency. . , 1 , , . .

0

Source: https://habr.com/ru/post/1751324/


All Articles