17 KiB
Database Schema Diagrams
Entity-relationship overview for the online-back PostgreSQL schema (db/migrations/20260702125108_init.up.sql).
Full ER diagram (Mermaid)
Renders on GitHub, GitLab, and most Markdown viewers with Mermaid support.
erDiagram
admin {
bigserial id PK
varchar login
varchar password
varchar fullname
varchar username
varchar phone_number
varchar avatar
json social_media
int light_mode
varchar role
boolean status
timestamp created_at
timestamp updated_at
}
province {
bigserial id PK
json title
timestamp created_at
timestamp updated_at
}
location {
bigserial id PK
bigint province_id FK
json title
boolean status
timestamp created_at
timestamp updated_at
}
branches {
bigserial id PK
json title
bigint province_id FK
bigint location_id FK
varchar unikal_nomer UK
json address
varchar billing_login
varchar billing_password
varchar billing_username_sber
varchar billing_password_sber
varchar billing_username_visa
timestamp created_at
timestamp updated_at
}
payment_cards {
bigserial id PK
numeric price
json title
json content
boolean status
timestamp created_at
timestamp updated_at
}
reasons_cards {
bigserial id PK
json title
numeric price
json content
timestamp created_at
timestamp updated_at
}
loan_types {
bigserial id PK
json title
numeric tax
varchar loan_term
json content
timestamp created_at
timestamp updated_at
}
loans_documents {
bigserial id PK
json title
text content_en
text content_ru
text content_tm
boolean status
timestamp created_at
timestamp updated_at
}
province ||--o{ location : "has"
province ||--o{ branches : "has"
location ||--o{ branches : "has"
Draw.io-style entity boxes
Visual layout similar to a draw.io canvas — boxes with columns and relationship arrows.
┌──────────────────────────────────────────────────────────────────────────────────────────────┐
│ GEOGRAPHY & BRANCHES │
└──────────────────────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────┐
│ province │
├─────────────────────────┤
│ 🔑 id bigserial│
│ title json │ { en, ru, tm }
│ created_at timestamp│
│ updated_at timestamp│
└───────────┬─────────────┘
│
│ 1 ──────────< N
▼
┌─────────────────────────┐ ┌─────────────────────────┐
│ location │ │ branches │
├─────────────────────────┤ ├─────────────────────────┤
│ 🔑 id bigserial│ │ 🔑 id bigserial│
│ 🔗 province_id bigint │◄────────│ 🔗 province_id bigint │
│ title json │ │ 🔗 location_id bigint │◄──┐
│ status boolean │ │ title json │ │
│ created_at timestamp│ │ ⭐ unikal_nomer varchar │ │
│ updated_at timestamp│ │ address json │ │
└───────────┬─────────────┘ │ billing_login │ │
│ │ billing_password │ │
│ 1 ──────────< N │ billing_username_sber│ │
└──────────────────────►│ billing_password_sber│ │
│ billing_username_visa│ │
│ created_at timestamp│ │
│ updated_at timestamp│ │
└─────────────────────────┘ │
│
location 1 ───────────────────────────────────────────┘
┌──────────────────────────────────────────────────────────────────────────────────────────────┐
│ AUTH │
└──────────────────────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────┐
│ admin │
├─────────────────────────┤
│ 🔑 id bigserial│
│ login varchar │
│ password varchar │ (bcrypt hash)
│ fullname varchar │
│ username varchar │
│ phone_number varchar │
│ avatar varchar │
│ social_media json │
│ light_mode integer │
│ role varchar │
│ status boolean │
│ created_at timestamp│
│ updated_at timestamp│
└─────────────────────────┘
(no FK to other tables)
┌──────────────────────────────────────────────────────────────────────────────────────────────┐
│ PAYMENTS & CARDS (standalone) │
└──────────────────────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────┐ ┌─────────────────────────┐
│ payment_cards │ │ reasons_cards │
├─────────────────────────┤ ├─────────────────────────┤
│ 🔑 id bigserial│ │ 🔑 id bigserial│
│ price numeric │ │ title json │ { en, ru, tm }
│ title json │ │ price numeric │
│ content json │ │ content json │ { en, ru, tm }
│ status boolean │ │ created_at timestamp│
│ created_at timestamp│ │ updated_at timestamp│
│ updated_at timestamp│ └─────────────────────────┘
└─────────────────────────┘
┌──────────────────────────────────────────────────────────────────────────────────────────────┐
│ LOANS (standalone) │
└──────────────────────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────┐ ┌─────────────────────────┐
│ loan_types │ │ loans_documents │
├─────────────────────────┤ ├─────────────────────────┤
│ 🔑 id bigserial│ │ 🔑 id bigserial│
│ title json │ │ title json │ { en, ru, tm }
│ tax numeric │ │ content_en text │
│ loan_term varchar │ │ content_ru text │
│ content json │ │ content_tm text │
│ created_at timestamp│ │ status boolean │
│ updated_at timestamp│ │ created_at timestamp│
└─────────────────────────┘ │ updated_at timestamp│
└─────────────────────────┘
Relationships summary
| From table | Column | To table | To column | On delete |
|---|---|---|---|---|
location |
province_id |
province |
id |
CASCADE |
branches |
province_id |
province |
id |
CASCADE |
branches |
location_id |
location |
id |
CASCADE |
All other tables (admin, payment_cards, reasons_cards, loan_types, loans_documents) are standalone — no foreign keys.
Tables reference
admin
Admin users for the back-office panel.
| Column | Type | Notes |
|---|---|---|
| id | bigserial | Primary key |
| login | varchar(250) | Email / login |
| password | varchar(250) | bcrypt hash |
| fullname | varchar(250) | |
| username | varchar(250) | |
| phone_number | varchar(250) | |
| avatar | varchar(250) | |
| social_media | json | |
| light_mode | integer | Default 1 |
| role | varchar(250) | Default 'user' |
| status | boolean | Default true |
| created_at | timestamp UTC | |
| updated_at | timestamp UTC |
province
Regions / provinces with localized title.
| Column | Type | Notes |
|---|---|---|
| id | bigserial | Primary key |
| title | json | { en, ru, tm } |
| created_at | timestamp UTC | |
| updated_at | timestamp UTC |
location
Cities or districts within a province.
| Column | Type | Notes |
|---|---|---|
| id | bigserial | Primary key |
| province_id | bigint | FK → province.id |
| title | json | { en, ru, tm } |
| status | boolean | Default true |
| created_at | timestamp UTC | |
| updated_at | timestamp UTC |
branches
Bank branches linked to province and location.
| Column | Type | Notes |
|---|---|---|
| id | bigserial | Primary key |
| title | json | { en, ru, tm } |
| province_id | bigint | FK → province.id |
| location_id | bigint | FK → location.id |
| unikal_nomer | varchar(250) | Unique branch number |
| address | json | { en, ru, tm } |
| billing_login | varchar(250) | |
| billing_password | varchar(250) | |
| billing_username_sber | varchar(250) | |
| billing_password_sber | varchar(250) | |
| billing_username_visa | varchar(250) | |
| created_at | timestamp UTC | |
| updated_at | timestamp UTC |
payment_cards
Payment card products / tariffs.
| Column | Type | Notes |
|---|---|---|
| id | bigserial | Primary key |
| price | numeric(12,2) | Default 0 |
| title | json | { en, ru, tm } |
| content | json | { en, ru, tm } |
| status | boolean | Default true |
| created_at | timestamp UTC | |
| updated_at | timestamp UTC |
reasons_cards
Reason cards for payments (title, price, content).
| Column | Type | Notes |
|---|---|---|
| id | bigserial | Primary key |
| title | json | { en, ru, tm } |
| price | numeric(12,2) | Default 0 |
| content | json | { en, ru, tm } |
| created_at | timestamp UTC | |
| updated_at | timestamp UTC |
loan_types
Loan product types (tax rate, term, description).
| Column | Type | Notes |
|---|---|---|
| id | bigserial | Primary key |
| title | json | { en, ru, tm } |
| tax | numeric(12,2) | Default 0 |
| loan_term | varchar(250) | e.g. "12 months" |
| content | json | { en, ru, tm } |
| created_at | timestamp UTC | |
| updated_at | timestamp UTC |
loans_documents
Required documents for loan applications.
| Column | Type | Notes |
|---|---|---|
| id | bigserial | Primary key |
| title | json | { en, ru, tm } |
| content_en | text | English body |
| content_ru | text | Russian body |
| content_tm | text | Turkmen body |
| status | boolean | Default true |
| created_at | timestamp UTC | |
| updated_at | timestamp UTC |
API modules mapped to tables
| Table | Admin route | Package |
|---|---|---|
admin |
/auth/* |
internal/admin/auth |
province |
/provinces |
internal/admin/province |
location |
/locations |
internal/admin/location |
branches |
/branches |
internal/admin/branches |
payment_cards |
/payment-cards |
internal/admin/paymentcard |
reasons_cards |
/reasons-cards |
internal/admin/reasonscard |
loan_types |
/loan-types |
internal/admin/loantype |
loans_documents |
/loans-documents |
internal/admin/loansdocument |
Import into draw.io
- Open draw.io (or diagrams.net).
- Arrange → Insert → Advanced → Mermaid — paste the Mermaid block from the top of this file.
- Or recreate manually using the ASCII boxes above as a layout guide.
Legend used in ASCII diagrams:
| Symbol | Meaning |
|---|---|
| 🔑 | Primary key |
| 🔗 | Foreign key |
| ⭐ | Unique column |