Overview
Theitems table stores the main item data for the Cat Data API. Each item has a name, optional description, and references an image through a foreign key relationship.
Schema
Primary key. Auto-incrementing integer identifier for the item.
Unique item name. Cannot be null and must be unique across all items.
Optional text description of the item. Can be null.
Foreign key reference to the
images table. Links this item to an image. Can be null.Timestamp when the item record was created. Automatically set by the database.
Timestamp when the item record was last updated. Automatically updated by the database.
Constraints
- Primary Key:
id - Unique:
name- Each item must have a unique name - Not Null:
name- Item name is required - Foreign Key:
image_idreferencesimages(id)
Relationships
Images Relationship
- Many-to-One: Multiple items can reference the same image
- Foreign Key:
image_id→images.id - Cascade Delete: When an image is deleted, all items referencing that image are automatically deleted
Tags Relationship
- Many-to-Many: Items can have multiple tags through the
items_to_tagsjunction table - Junction Table:
items_to_tagslinks items and tags - Cascade Delete: When an item is deleted, all associations in
items_to_tagsare automatically removed
Delete Behavior
TheCASCADE delete behavior ensures referential integrity:
- If an image is deleted → all items with that
image_idare automatically deleted - If an item is deleted → all tag associations in
items_to_tagsare automatically deleted
Migration
The items table is created using Knex.js migration:20250717082805_create_items_table.js