fix schema
This commit is contained in:
parent
cd08b7abe8
commit
5fc96512e2
|
|
@ -43,6 +43,8 @@ CREATE TABLE IF NOT EXISTS categories (
|
|||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
description TEXT,
|
||||
image_url VARCHAR(500),
|
||||
show_on_homepage BOOLEAN DEFAULT FALSE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
INDEX idx_name (name)
|
||||
|
|
@ -55,9 +57,14 @@ CREATE TABLE IF NOT EXISTS products (
|
|||
name VARCHAR(255) NOT NULL,
|
||||
description TEXT,
|
||||
price DECIMAL(10, 2) NOT NULL,
|
||||
original_price DECIMAL(10, 2),
|
||||
stock INT DEFAULT 0,
|
||||
product_condition VARCHAR(50) DEFAULT 'Begagnad',
|
||||
badge_text VARCHAR(50),
|
||||
badge_color VARCHAR(20),
|
||||
image_url VARCHAR(500),
|
||||
show_on_homepage BOOLEAN DEFAULT FALSE,
|
||||
brand VARCHAR(100),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE RESTRICT,
|
||||
|
|
@ -66,6 +73,15 @@ CREATE TABLE IF NOT EXISTS products (
|
|||
INDEX idx_price (price)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- 6a. Create product_categories table (Many-to-Many)
|
||||
CREATE TABLE IF NOT EXISTS product_categories (
|
||||
product_id INT NOT NULL,
|
||||
category_id INT NOT NULL,
|
||||
PRIMARY KEY (product_id, category_id),
|
||||
FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- 6b. Create product_images table
|
||||
CREATE TABLE IF NOT EXISTS product_images (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
|
|
|
|||
Loading…
Reference in New Issue