forked from ebhomengo/niki
feat: add product entity and migrations
This commit is contained in:
parent
a193abeb56
commit
60c2ff3d8e
|
|
@ -0,0 +1,10 @@
|
|||
-- +migrate Up
|
||||
CREATE TABLE `categories` (
|
||||
`id` INT PRIMARY KEY AUTO_INCREMENT,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`slug` VARCHAR(255) NOT NULL UNIQUE,
|
||||
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_persian_ci;
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE IF EXISTS `categories`;
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
-- +migrate Up
|
||||
CREATE TABLE `products` (
|
||||
`id` INT PRIMARY KEY AUTO_INCREMENT,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`slug` VARCHAR(255) NOT NULL UNIQUE,
|
||||
`description` TEXT,
|
||||
`price` DECIMAL(10, 2) NOT NULL,
|
||||
`stock` INT DEFAULT 0,
|
||||
`is_active` BOOLEAN DEFAULT TRUE,
|
||||
`features` JSON DEFAULT NULL,
|
||||
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`deleted_at` TIMESTAMP DEFAULT NULL,
|
||||
FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE SET NULL
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_persian_ci;
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE IF EXISTS `products`;
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
-- +migrate Up
|
||||
CREATE TABLE `category_products` (
|
||||
`category_id` INT NOT NULL,
|
||||
`product_id` INT NOT NULL,
|
||||
PRIMARY KEY (`category_id`, `product_id`),
|
||||
FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE CASCADE,
|
||||
FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_persian_ci;
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE IF EXISTS `category_products`;
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
-- +migrate Up
|
||||
CREATE TABLE `product_images` (
|
||||
`id` INT PRIMARY KEY AUTO_INCREMENT,
|
||||
`product_id` INT NOT NULL,
|
||||
`image_path` VARCHAR(255) NOT NULL,
|
||||
`is_primary` BOOLEAN DEFAULT FALSE,
|
||||
FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_persian_ci;
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE IF EXISTS `product_images`;
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package category
|
||||
|
||||
import "time"
|
||||
|
||||
type Category struct {
|
||||
ID uint
|
||||
Name string
|
||||
Slug string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package category
|
||||
|
|
@ -0,0 +1 @@
|
|||
package category
|
||||
|
|
@ -0,0 +1 @@
|
|||
package category
|
||||
|
|
@ -1 +0,0 @@
|
|||
package service
|
||||
|
|
@ -1 +0,0 @@
|
|||
package service
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package product
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Product struct {
|
||||
ID uint
|
||||
Name string
|
||||
Slug string
|
||||
Description string
|
||||
Price float64
|
||||
Stock int
|
||||
IsActive bool
|
||||
Features string
|
||||
CreatedAt time.Time
|
||||
DeletedAt sql.NullTime
|
||||
}
|
||||
|
||||
type ProductImage struct {
|
||||
ID uint
|
||||
ProductID uint
|
||||
ImagePath string
|
||||
IsPrimary bool
|
||||
}
|
||||
|
||||
type CategoryProduct struct {
|
||||
CategoryID uint
|
||||
ProductID uint
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package product
|
||||
|
|
@ -0,0 +1 @@
|
|||
package product
|
||||
|
|
@ -0,0 +1 @@
|
|||
package product
|
||||
|
|
@ -1 +0,0 @@
|
|||
package service
|
||||
|
|
@ -1 +0,0 @@
|
|||
package service
|
||||
Loading…
Reference in New Issue