37241-vm/db/migrations/006_add_payments.sql
2026-01-03 08:40:36 +00:00

25 lines
1.1 KiB
SQL

CREATE TABLE IF NOT EXISTS payments (
id CHAR(36) NOT NULL PRIMARY KEY,
student_id CHAR(36) NOT NULL,
payment_date DATE NOT NULL,
amount_received DECIMAL(10, 2) NOT NULL,
payment_method VARCHAR(50) NOT NULL CHECK (payment_method IN ('Cash', 'Bank Transfer', 'Mobile Money', 'Other')),
reference_number VARCHAR(255) NULL,
journal_entry_id CHAR(36) DEFAULT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
FOREIGN KEY (student_id) REFERENCES students(id),
FOREIGN KEY (journal_entry_id) REFERENCES journal_entries(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS payment_lines (
id CHAR(36) NOT NULL PRIMARY KEY,
payment_id CHAR(36) NOT NULL,
invoice_id CHAR(36) NOT NULL,
amount_applied DECIMAL(10, 2) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
FOREIGN KEY (payment_id) REFERENCES payments(id) ON DELETE CASCADE,
FOREIGN KEY (invoice_id) REFERENCES invoices(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;