19 lines
920 B
SQL
19 lines
920 B
SQL
-- Payments table
|
|
CREATE TABLE payments (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
order_id UUID NOT NULL REFERENCES orders(id) ON DELETE CASCADE,
|
|
payment_method_id UUID NOT NULL REFERENCES payment_methods(id) ON DELETE RESTRICT,
|
|
amount DECIMAL(10,2) NOT NULL CHECK (amount >= 0),
|
|
status VARCHAR(50) DEFAULT 'pending' CHECK (status IN ('pending', 'completed', 'failed', 'refunded')),
|
|
transaction_id VARCHAR(255),
|
|
metadata JSONB DEFAULT '{}',
|
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
);
|
|
|
|
-- Indexes
|
|
CREATE INDEX idx_payments_order_id ON payments(order_id);
|
|
CREATE INDEX idx_payments_payment_method_id ON payments(payment_method_id);
|
|
CREATE INDEX idx_payments_status ON payments(status);
|
|
CREATE INDEX idx_payments_transaction_id ON payments(transaction_id);
|
|
CREATE INDEX idx_payments_created_at ON payments(created_at); |