Remove order_id, add created_at column
This commit is contained in:
parent
de42a7435b
commit
3092a3f89d
9
init.sql
9
init.sql
|
@ -40,12 +40,17 @@ CREATE TABLE invoices(
|
||||||
CREATE TYPE order_side AS ENUM ('BUY', 'SELL');
|
CREATE TYPE order_side AS ENUM ('BUY', 'SELL');
|
||||||
CREATE TABLE orders(
|
CREATE TABLE orders(
|
||||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
share_id UUID NOT NULL REFERENCES shares(id),
|
share_id UUID NOT NULL REFERENCES shares(id),
|
||||||
pubkey TEXT NOT NULL REFERENCES users(pubkey),
|
pubkey TEXT NOT NULL REFERENCES users(pubkey),
|
||||||
side ORDER_SIDE NOT NULL,
|
side ORDER_SIDE NOT NULL,
|
||||||
quantity BIGINT NOT NULL,
|
quantity BIGINT NOT NULL,
|
||||||
price BIGINT NOT NULL,
|
price BIGINT NOT NULL,
|
||||||
invoice_id UUID NOT NULL REFERENCES invoices(id),
|
invoice_id UUID NOT NULL REFERENCES invoices(id)
|
||||||
order_id UUID REFERENCES orders(id)
|
|
||||||
);
|
);
|
||||||
ALTER TABLE orders ADD CONSTRAINT order_price CHECK(price > 0 AND price < 100);
|
ALTER TABLE orders ADD CONSTRAINT order_price CHECK(price > 0 AND price < 100);
|
||||||
|
CREATE TABLE matches(
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
oid1 UUID NOT NULL REFERENCES orders(id),
|
||||||
|
oid2 UUID NOT NULL REFERENCES orders(id)
|
||||||
|
);
|
||||||
|
|
|
@ -77,7 +77,7 @@ type FetchOrdersWhere struct {
|
||||||
|
|
||||||
func (db *DB) FetchOrders(where *FetchOrdersWhere, orders *[]Order) error {
|
func (db *DB) FetchOrders(where *FetchOrdersWhere, orders *[]Order) error {
|
||||||
query := "" +
|
query := "" +
|
||||||
"SELECT o.id, share_id, o.pubkey, o.side, o.quantity, o.price, o.invoice_id, s.description, s.market_id, i.confirmed_at, o.order_id " +
|
"SELECT o.id, share_id, o.pubkey, o.side, o.quantity, o.price, o.invoice_id, o.created_at, s.description, s.market_id, i.confirmed_at " +
|
||||||
"FROM orders o " +
|
"FROM orders o " +
|
||||||
"JOIN invoices i ON o.invoice_id = i.id " +
|
"JOIN invoices i ON o.invoice_id = i.id " +
|
||||||
"JOIN shares s ON o.share_id = s.id " +
|
"JOIN shares s ON o.share_id = s.id " +
|
||||||
|
@ -102,7 +102,7 @@ func (db *DB) FetchOrders(where *FetchOrdersWhere, orders *[]Order) error {
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var order Order
|
var order Order
|
||||||
rows.Scan(&order.Id, &order.ShareId, &order.Pubkey, &order.Side, &order.Quantity, &order.Price, &order.InvoiceId, &order.Share.Description, &order.Share.MarketId, &order.Invoice.ConfirmedAt, &order.OrderId)
|
rows.Scan(&order.Id, &order.ShareId, &order.Pubkey, &order.Side, &order.Quantity, &order.Price, &order.InvoiceId, &order.CreatedAt, &order.Share.Description, &order.Share.MarketId, &order.Invoice.ConfirmedAt)
|
||||||
*orders = append(*orders, order)
|
*orders = append(*orders, order)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -34,8 +34,8 @@ type Order struct {
|
||||||
Side string `form:"side"`
|
Side string `form:"side"`
|
||||||
Price int `form:"price"`
|
Price int `form:"price"`
|
||||||
Quantity int `form:"quantity"`
|
Quantity int `form:"quantity"`
|
||||||
OrderId string
|
|
||||||
InvoiceId string
|
InvoiceId string
|
||||||
|
CreatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type Invoice struct {
|
type Invoice struct {
|
||||||
|
|
Loading…
Reference in New Issue