v0.30: product pages, categories, sale prices and order status timeline
This commit is contained in:
@@ -77,6 +77,25 @@ func Migrate(ctx context.Context, pool *pgxpool.Pool) error {
|
||||
quantity INT NOT NULL CHECK (quantity > 0)
|
||||
)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_orders_user ON orders (user_id)`,
|
||||
`CREATE TABLE IF NOT EXISTS categories (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL UNIQUE,
|
||||
slug VARCHAR(100) NOT NULL UNIQUE,
|
||||
description TEXT NOT NULL DEFAULT '',
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
)`,
|
||||
`ALTER TABLE products ADD COLUMN IF NOT EXISTS category_id INT REFERENCES categories(id) ON DELETE SET NULL`,
|
||||
`ALTER TABLE products ADD COLUMN IF NOT EXISTS sale_price NUMERIC(10,2)`,
|
||||
`INSERT INTO categories (name, slug, sort_order) VALUES
|
||||
('Электроника', 'elektronika', 1),
|
||||
('Одежда', 'odezhda', 2),
|
||||
('Дом и сад', 'dom-i-sad', 3),
|
||||
('Аксессуары', 'aksessuary', 4),
|
||||
('Разное', 'raznoe', 5)
|
||||
ON CONFLICT (slug) DO NOTHING`,
|
||||
`UPDATE products p SET category_id = c.id
|
||||
FROM categories c WHERE p.category = c.name AND p.category_id IS NULL`,
|
||||
}
|
||||
|
||||
for _, q := range queries {
|
||||
|
||||
Reference in New Issue
Block a user