SQL

CREATE TABLE agent_transactions  (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  agent_id INTEGER NOT NULL,
  transaction_type TEXT NOT NULL CHECK (transaction_type IN ('deposit', 'withdrawal', 'voucher_sale', 'monthly_payment', 'commission', 'balance_request')),
  amount DECIMAL(15,2) NOT NULL,
  description TEXT,
  reference_id TEXT,
  status TEXT DEFAULT 'completed' CHECK (status IN ('pending', 'completed', 'failed', 'cancelled')),
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (agent_id) REFERENCES agents(id) ON DELETE CASCADE
)

+ Add column

Columns

Column Data type Allow null Primary key Actions
id INTEGER Rename | Drop
agent_id INTEGER Rename | Drop
transaction_type TEXT Rename | Drop
amount DECIMAL(15,2) Rename | Drop
description TEXT Rename | Drop
reference_id TEXT Rename | Drop
status TEXT Rename | Drop
created_at DATETIME Rename | Drop

Foreign Keys

Column Destination
agent_id agents.id

+ Add index

Indexes

Name Columns Unique SQL Drop?
idx_agent_transactions_agent_id agent_id SQL
CREATE INDEX idx_agent_transactions_agent_id
ON agent_transactions(agent_id)
Drop
idx_agent_transactions_created_at created_at SQL
CREATE INDEX idx_agent_transactions_created_at
ON agent_transactions(created_at)
Drop
idx_agent_transactions_type transaction_type SQL
CREATE INDEX idx_agent_transactions_type
ON agent_transactions(transaction_type)
Drop