mirror of
https://github.com/3ybactuk/marketplace-go-service-project.git
synced 2025-10-30 14:03:45 +03:00
[hw-4] add postgres db
This commit is contained in:
20
loms/db/migrations/00001_create_orders.sql
Normal file
20
loms/db/migrations/00001_create_orders.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE
|
||||
orders (
|
||||
id bigserial PRIMARY KEY,
|
||||
status_name TEXT NOT NULL DEFAULT '',
|
||||
user_id BIGINT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE
|
||||
order_items (
|
||||
id bigserial PRIMARY KEY,
|
||||
order_id BIGINT NOT NULL REFERENCES orders (id) ON DELETE CASCADE,
|
||||
sku BIGINT NOT NULL,
|
||||
COUNT BIGINT NOT NULL CHECK (COUNT > 0)
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE order_items;
|
||||
|
||||
DROP TABLE orders;
|
||||
10
loms/db/migrations/00002_create_stocks.sql
Normal file
10
loms/db/migrations/00002_create_stocks.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE
|
||||
stocks (
|
||||
sku BIGINT PRIMARY KEY,
|
||||
total_count BIGINT NOT NULL,
|
||||
reserved BIGINT NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE stocks;
|
||||
24
loms/db/migrations/00003_add_stocks.sql
Normal file
24
loms/db/migrations/00003_add_stocks.sql
Normal file
@@ -0,0 +1,24 @@
|
||||
-- +goose Up
|
||||
INSERT INTO
|
||||
stocks (sku, total_count, reserved)
|
||||
VALUES
|
||||
(139275865, 65534, 0),
|
||||
(2956315, 100, 30),
|
||||
(1076963, 100, 35),
|
||||
(135717466, 100, 20),
|
||||
(135937324, 100, 30),
|
||||
(1625903, 10000, 0),
|
||||
(1148162, 100, 0);
|
||||
|
||||
-- +goose Down
|
||||
DELETE FROM stocks
|
||||
WHERE
|
||||
sku IN (
|
||||
139275865,
|
||||
2956315,
|
||||
1076963,
|
||||
135717466,
|
||||
135937324,
|
||||
1625903,
|
||||
1148162
|
||||
);
|
||||
Reference in New Issue
Block a user