Skip to content

Instantly share code, notes, and snippets.

@ahouts
Created October 31, 2025 15:05
Show Gist options
  • Select an option

  • Save ahouts/33d06b9677ba9f8562c41f5d2465ca1a to your computer and use it in GitHub Desktop.

Select an option

Save ahouts/33d06b9677ba9f8562c41f5d2465ca1a to your computer and use it in GitHub Desktop.
Schema of the trades table
CREATE TABLE portfolio
(
id BIGINT AUTO_INCREMENT PRIMARY KEY
);
CREATE TABLE trades
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
portfolio_id BIGINT NOT NULL,
type VARCHAR(255) NOT NULL,
date DATETIME NOT NULL,
quantity DECIMAL(20, 5) NOT NULL,
CONSTRAINT fk_trades_portfolio_id
FOREIGN KEY (portfolio_id) REFERENCES portfolios (id)
);
CREATE INDEX trades_portfolio_type_date
ON trades (portfolio_id, type, date);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment