Banking App (MySQL with Drizzle ORM)
This document outlines the MySQL database schema for a sample banking application. The schema is designed to be efficient, scalable, and easy to understand. We use Drizzle ORM for defining our data models with TypeScript.
The core of our application revolves around four main tables: User, Account, Transaction and Ledger.
Installation Guide
To add these schemas to your project, run:
npx servercn-cli add schema banking-appIf you install schema individually, the relationships between them won't be automatic—you'll need to implement them manually.
1. User Schema
The User schema stores essential information about the customer. This includes personal details and security credentials.
Path: src/drizzle/schemas/user.schema.ts
Installation
npx servercn-cli add schema banking-app/user2. Account Schema
The Account schema stores user bank accounts (e.g., savings, current). A user can own multiple accounts with different types, currencies, and statuses.
Path: src/drizzle/schemas/account.schema.ts
Installation
npx servercn-cli add schema banking-app/account3. Transaction Schema
The Transaction schema records money movements between accounts, including transfers, deposits, and withdrawals.
Path: src/drizzle/schemas/transaction.schema.ts
Installation
npx servercn-cli add schema banking-app/transaction4. Ledger Schema
The Ledger schema records all financial movements such as deposits, withdrawals, and transfers. Each entry represents a finalized financial event.
Path: src/drizzle/schemas/ledger.schema.ts
Ledger entries are immutable in business logic. Application layer should prevent updates/deletes.
Installation
npx servercn-cli add schema banking-app/ledger5. Relations
Defines relationships between database tables for seamless data fetching with Drizzle ORM.
Path: src/drizzle/schemas/relations.ts
6. Export all schemas
All database schemas must be re-exported from a single entry point. This allows Drizzle to load every table definition from one file during migration generation.
File Path: src/drizzle/index.ts
7. drizzle.config.ts
Create a drizzle.config.ts file at the project root.
This file defines how Drizzle connects to the database and where it should read schemas and write migrations.
File Path: drizzle.config.ts