fix schema

This commit is contained in:
ismail 2026-02-02 18:14:54 +01:00
parent cd08b7abe8
commit 5fc96512e2
1 changed files with 16 additions and 0 deletions

View File

@ -43,6 +43,8 @@ CREATE TABLE IF NOT EXISTS categories (
id INT AUTO_INCREMENT PRIMARY KEY, id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
description TEXT, description TEXT,
image_url VARCHAR(500),
show_on_homepage BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_name (name) INDEX idx_name (name)
@ -55,9 +57,14 @@ CREATE TABLE IF NOT EXISTS products (
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
description TEXT, description TEXT,
price DECIMAL(10, 2) NOT NULL, price DECIMAL(10, 2) NOT NULL,
original_price DECIMAL(10, 2),
stock INT DEFAULT 0, stock INT DEFAULT 0,
product_condition VARCHAR(50) DEFAULT 'Begagnad',
badge_text VARCHAR(50),
badge_color VARCHAR(20),
image_url VARCHAR(500), image_url VARCHAR(500),
show_on_homepage BOOLEAN DEFAULT FALSE, show_on_homepage BOOLEAN DEFAULT FALSE,
brand VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE RESTRICT, FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE RESTRICT,
@ -66,6 +73,15 @@ CREATE TABLE IF NOT EXISTS products (
INDEX idx_price (price) INDEX idx_price (price)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ) 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 -- 6b. Create product_images table
CREATE TABLE IF NOT EXISTS product_images ( CREATE TABLE IF NOT EXISTS product_images (
id INT AUTO_INCREMENT PRIMARY KEY, id INT AUTO_INCREMENT PRIMARY KEY,