【发布时间】:2013-02-09 22:42:58
【问题描述】:
我有一个存储产品图像元数据的数据库架构,如下所示:
image_sizes (this is purely metadata - what sizes to create of given image, eg "thumb", "main image", "sidebar widget icon of the product", etc):
image_size_id (auto-increment, pk)
name (thumb, main)
max_width
max_height
crop (flag, to crop or just resize to fit)
images table:
image_id (auto-increment, pk)
image_size_id (fk to image_sizes)
image_batch_id (fk to batches, when there is uploaded image for the product, an image is created for each product size, all the images have same batch_id, described below)
location (relative path to the project eg uploads/products/thumbs)
width (result after processing, in pixels
height (result after processing, in pixels)
size (in bytes)
image_batches tables:
image_batch_id (auto-increment, pk)
product_id (fk, to which product it belongs)
original_filename (eg the file was called 123.jpg when uploaded)
is_default (if the product 10 images, one is default)
因此,此架构允许我获取产品的所有“缩略图”并显示它们。现在的问题是我想为应用程序中的用户或其他实体(也可以说场所)使用相同的架构。
如果我修改下面的架构是否合适,以便:
image_batches 有额外的列image_type_id。将有image_type 用于products、users、everything else that needs images。而不是product_id 有entry_id 哪个image_type products 将是产品ID,对于图像类型users 将是user_id 等等。
我知道这是可能导致问题的非规范化(如果应用程序端存在错误)。但是,如果我需要新类型实体的图像来创建一组 3 个新表来处理相同的问题,这似乎开销太大。同样,在应用程序端也会有(某种)代码重复。
你有什么建议?
【问题讨论】:
标签: mysql database normalization denormalization