Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,12 @@ Database administrators use it to create the migration scripts.

**Learn-dev MPD Diagram**:

> TODO: ![MPD](docs/database/merise/learn-dev_mpd.svg)
> ![MPD](docs/database/merise/mpd/schema.svg)

The MPD is generated by [`tbls`](https://github.com/k1LoW/tbls) from the **live
PostgreSQL database** (not from the MCD), so it always reflects the real schema.
Run `make mpd` to regenerate it; per-table documentation is in
`docs/database/merise/mpd/` (`public.<table>.md` / `.svg`).


#### ERD Diagram
Expand Down
23 changes: 18 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Display the syntax with available targets
help:
@echo "Available targets:"
@echo " make diagrams — generate MCD, MLD, and MPD"
@echo " make diagrams — generate Merise MCD, MLD, and MPD diagrams"
@echo " make mcd — generate MCD"
@echo " make mld — generate MLD"
@echo " make mpd — generate MPD"
Expand Down Expand Up @@ -41,12 +41,25 @@ mld:
mocodo --input docs/database/merise/learn-dev_mld.mcd --output_dir docs/database/merise --colors ocean
@echo "MLD generated: docs/database/merise/learn-dev_mld.svg"

# Generate MPD from the PostgreSQL database
# Generate MPD from the PostgreSQL database.
# Percent-encode the password because it may contain URL-reserved characters.
mpd:
@echo "Generating MPD from PostgreSQL Database..."
@test -n "$(TBLS_DSN)" || (echo "TBLS_DSN is required (e.g., postgres://user:pass@host:5432/dbname)" >&2; exit 1)
tbls doc "$(TBLS_DSN)" docs/database/merise --force
@echo "MPD generated in docs/database/merise/"
@if [ -e .env ]; then \
while IFS= read -r line; do \
case "$$line" in [A-Za-z_]*=*) export "$$line";; esac; \
done < .env; \
fi; \
if [ -n "$$TBLS_DSN" ]; then \
DSN="$$TBLS_DSN"; \
elif [ -n "$$LEARNDEV_DB_USER" ]; then \
ENC_LEARNDEV_DB_PASSWORD=$$(printf '%s' "$$LEARNDEV_DB_PASSWORD" | python3 -c 'import sys,urllib.parse; print(urllib.parse.quote(sys.stdin.read(), safe=""))'); \
DSN="postgres://$$LEARNDEV_DB_USER:$$ENC_LEARNDEV_DB_PASSWORD@$$POSTGRES_HOST:$$POSTGRES_PORT/$$LEARNDEV_DB_NAME?sslmode=disable"; \
else \
echo "TBLS_DSN is required (or define LEARNDEV_DB_* / POSTGRES_* in .env)" >&2; exit 1; \
fi; \
tbls doc "$$DSN" docs/database/merise/mpd --force
@echo "MPD generated in docs/database/merise/mpd/"

# Clean up generated diagram files
clean:
Expand Down
2 changes: 1 addition & 1 deletion docs/database/merise/learn-dev.mcd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

:
Email Token: token_id, token, expires_at, used_at
Audit Log: log_id, action_type, entity_type, entity_id, description, ip_address, user_agent, was_successful, error_message, metadata
Audit Log: log_id, action_type, entity_type, entity_id, description, ip_address, user_agent, was_successful, error_message, metadata, created_at
:

Reset Token: token_id, token, expires_at, used_at, ip_address
Expand Down
185 changes: 93 additions & 92 deletions docs/database/merise/learn-dev.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
167 changes: 84 additions & 83 deletions docs/database/merise/learn-dev_mld.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions docs/database/merise/mpd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# learn-dev

## Description

Learn-dev MPD (Physical Data Model)

## Tables

| Name | Columns | Comment | Type |
| ---- | ------- | ------- | ---- |
| [public.users](public.users.md) | 12 | | BASE TABLE |
| [public.roles](public.roles.md) | 4 | | BASE TABLE |
| [public.user_roles](public.user_roles.md) | 4 | | BASE TABLE |
| [public.email_tokens](public.email_tokens.md) | 5 | | BASE TABLE |
| [public.reset_tokens](public.reset_tokens.md) | 6 | | BASE TABLE |
| [public.audit_logs](public.audit_logs.md) | 12 | | BASE TABLE |

## Relations

![er](schema.svg)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
40 changes: 40 additions & 0 deletions docs/database/merise/mpd/public.audit_logs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# public.audit_logs

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
| log_id | bigint | | false | | | |
| action_type | varchar(100) | | false | | | |
| entity_type | varchar(100) | | true | | | |
| entity_id | varchar(64) | | true | | | |
| description | text | | true | | | |
| ip_address | inet | | true | | | |
| user_agent | text | | true | | | |
| was_successful | boolean | true | false | | | |
| error_message | text | | true | | | |
| metadata | jsonb | | true | | | |
| created_at | timestamp with time zone | now() | false | | | |
| user_id | uuid | | true | | [public.users](public.users.md) | |

## Constraints

| Name | Type | Definition |
| ---- | ---- | ---------- |
| audit_logs_user_id_fkey | FOREIGN KEY | FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE SET NULL |
| audit_logs_pkey | PRIMARY KEY | PRIMARY KEY (log_id) |

## Indexes

| Name | Definition |
| ---- | ---------- |
| audit_logs_pkey | CREATE UNIQUE INDEX audit_logs_pkey ON public.audit_logs USING btree (log_id) |
| idx_audit_logs_user_id | CREATE INDEX idx_audit_logs_user_id ON public.audit_logs USING btree (user_id) |

## Relations

![er](public.audit_logs.svg)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
110 changes: 110 additions & 0 deletions docs/database/merise/mpd/public.audit_logs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions docs/database/merise/mpd/public.email_tokens.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# public.email_tokens

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
| token_id | bigint | | false | | | |
| token | varchar(255) | | false | | | |
| expires_at | timestamp with time zone | | false | | | |
| used_at | timestamp with time zone | | true | | | |
| user_id | uuid | | false | | [public.users](public.users.md) | |

## Constraints

| Name | Type | Definition |
| ---- | ---- | ---------- |
| email_tokens_user_id_fkey | FOREIGN KEY | FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE |
| email_tokens_pkey | PRIMARY KEY | PRIMARY KEY (token_id) |
| email_tokens_token_key | UNIQUE | UNIQUE (token) |

## Indexes

| Name | Definition |
| ---- | ---------- |
| email_tokens_pkey | CREATE UNIQUE INDEX email_tokens_pkey ON public.email_tokens USING btree (token_id) |
| email_tokens_token_key | CREATE UNIQUE INDEX email_tokens_token_key ON public.email_tokens USING btree (token) |
| idx_email_tokens_user_id | CREATE INDEX idx_email_tokens_user_id ON public.email_tokens USING btree (user_id) |

## Relations

![er](public.email_tokens.svg)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
Loading
Loading