Skip to content

Commit 0329dde

Browse files
feat: init
1 parent 38ca28a commit 0329dde

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+19426
-1
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 2
7+
indent_style = space
8+
insert_final_newline = true
9+
max_line_length = 120
10+
tab_width = 2
11+
trim_trailing_whitespace = true
12+
13+
[*.md]
14+
trim_trailing_whitespace = false
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Build and Deploy VitePress site to Pages
2+
3+
on:
4+
workflow_dispatch:
5+
6+
push:
7+
branches:
8+
- main
9+
10+
concurrency:
11+
# 同じブランチに複数の push があれば、古いワークフローをキャンセルする
12+
group: ${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
build:
17+
name: Build
18+
timeout-minutes: 30
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
steps:
23+
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
29+
- uses: moonrepo/setup-toolchain@v0
30+
with:
31+
auto-install: true
32+
33+
- name: Install pnpm Dependencies
34+
run: pnpm install --frozen-lockfile
35+
36+
- name: Set up Docker Buildx
37+
uses: docker/setup-buildx-action@v3
38+
39+
- name: Start Docker services
40+
run: pnpm run db:serve
41+
42+
- name: Wait for services to be ready
43+
run: |
44+
echo "データベースとマイグレーションの完了を待機中..."
45+
max_attempts=30
46+
attempt=1
47+
while [ $attempt -le $max_attempts ]; do
48+
if [ "$(docker inspect -f '{{.State.Status}}' tbls_container 2>/dev/null)" = "exited" ] && \
49+
[ "$(docker inspect -f '{{.State.ExitCode}}' tbls_container 2>/dev/null)" = "0" ]; then
50+
echo "tbls document generation completed successfully"
51+
break
52+
fi
53+
echo "Waiting for tbls to complete... (Attempt $attempt/$max_attempts)"
54+
sleep 10
55+
attempt=$((attempt + 1))
56+
done
57+
58+
if [ $attempt -gt $max_attempts ]; then
59+
echo "tbls did not complete in time"
60+
docker logs tbls_container
61+
exit 1
62+
fi
63+
64+
- name: Build ER
65+
run: pnpm run er:build
66+
67+
- name: Build Documents
68+
run: pnpm run docs:build
69+
70+
- name: Copy ER diagrams to VitePress dist
71+
run: |
72+
mkdir -p docs/.vitepress/dist/er
73+
cp -r docs/out/* docs/.vitepress/dist/er/
74+
# Fix relative paths in ER diagram HTML
75+
sed -i 's|"./assets/|"/sample-db-docs-as-code/er/assets/|g' docs/.vitepress/dist/er/index.html
76+
77+
- name: Create .nojekyll file for GitHub Pages
78+
run: touch docs/.vitepress/dist/.nojekyll
79+
80+
- name: Upload built site
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: vitepress-site
84+
path: docs/.vitepress/dist/
85+
- name: Upload Excel artifact
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: table-excel
89+
path: excel/schema.xlsx
90+
retention-days: 5
91+
92+
deploy:
93+
runs-on: ubuntu-latest
94+
permissions:
95+
contents: write
96+
pages: write
97+
id-token: write
98+
environment:
99+
name: github-pages
100+
url: ${{ steps.deployment.outputs.page_url }}
101+
needs: build
102+
name: Deploy
103+
steps:
104+
- name: Setup Pages
105+
uses: actions/configure-pages@v4
106+
- name: Download built site
107+
uses: actions/download-artifact@v4
108+
with:
109+
name: vitepress-site
110+
path: .
111+
- name: Upload to GitHub Pages
112+
uses: actions/upload-pages-artifact@v3
113+
with:
114+
path: .
115+
- name: Deploy to GitHub Pages
116+
id: deployment
117+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,9 @@ dist
137137
# Vite logs files
138138
vite.config.js.timestamp-*
139139
vite.config.ts.timestamp-*
140+
141+
# macOS-specific files
142+
.DS_Store
143+
144+
# excel
145+
excel/

.prototools

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pnpm = "10.14.0"
2+
node = "~23"
3+
4+
[settings]
5+
auto-install = true

.sql-formatter.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"language": "mysql",
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"keywordCase": "upper",
6+
"dataTypeCase": "upper",
7+
"functionCase": "upper",
8+
"identifierCase": "lower",
9+
"logicalOperatorNewline": "before",
10+
"expressionWidth": 120,
11+
"linesBetweenQueries": 1,
12+
"denseOperators": false,
13+
"newlineBeforeSemicolon": false
14+
}

.tbls.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
docPath: schema
2+
# docPath: docs/schema # local 用
3+
4+
dsn: mysql://user:Password@db:3306/sample_rdb
5+
# dsn: mysql://user:Password@localhost:3306/sample_rdb # local 用
6+
7+
format:
8+
# Markdown形式のテーブルの列幅を調整する
9+
adjust: true
10+
# テーブルリストと列の順序を並べ替える
11+
sort: false
12+
# テーブルの各行に連番を表示する
13+
number: true
14+
# インデックスページの「Tables」セクションにある各テーブルのコメントは、最初の二重改行(最初の段落)までのテキストが表示されます。
15+
showOnlyFirstParagraph: false
16+
# 値が存在しないテーブルの列を非表示にする
17+
# Default is false
18+
hideColumnsWithoutValues: false
19+
# It can be boolean or array
20+
# hideColumnsWithoutValues: ["Parents", "Children"]
21+
22+
er:
23+
# Skip generation of ER diagram
24+
# Default is false
25+
skip: false
26+
# ER diagram image format (`png`, `jpg`, `svg`, `mermaid`)
27+
# Default is `svg`
28+
format: svg
29+
# Add table/column comment to ER diagram
30+
# Default is false
31+
comment: true
32+
# Hide relation definition from ER diagram
33+
# Default is false
34+
hideDef: false
35+
# Show column settings in ER diagram. If this section is not set, all columns will be displayed (default).
36+
showColumnTypes:
37+
# Show related columns
38+
related: true
39+
# Show primary key columns
40+
primary: true
41+
# Distance between tables that display relations in the ER
42+
# Default is 1
43+
distance: 2
44+
font: HackGen
45+
exclude:
46+
- flyway_schema_history
47+
48+
dict:
49+
Tables: テーブル一覧
50+
Description: 概要
51+
Columns: カラム一覧
52+
Indexes: INDEX一覧
53+
Constraints: 制約一覧
54+
Triggers: トリガー
55+
Relations: ER図
56+
Name: 名前
57+
Comment: コメント
58+
Type: タイプ
59+
Default: デフォルト値
60+
Children: 子テーブル
61+
Parents: 親テーブル
62+
Definition: 定義
63+
Table Definition: テーブル定義
64+
65+
relations:
66+
- table: m_role
67+
columns:
68+
- role_id
69+
parentTable: m_role_permission
70+
parentColumns:
71+
- role_id
72+
- table: m_permission
73+
columns:
74+
- perm_id
75+
parentTable: m_role_permission
76+
parentColumns:
77+
- perm_id
78+
79+
viewpoints:
80+
- name: 認可関連 ViewPoint
81+
desc: 認可関連のテーブルをまとめた ViewPoint
82+
tables:
83+
- m_permission
84+
- m_role
85+
- m_role_permission

CLAUDE.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is a database documentation project that implements "docs as code" approach using Docker, tbls, Liam ERD, and VitePress. The system automatically generates database documentation from a MySQL database schema and provides both tabular documentation and ER diagrams through a web interface.
8+
9+
## Key Components
10+
11+
- **Database**: MySQL database with Flyway migrations in `sql/migration/`
12+
- **Documentation Generation**: tbls for schema documentation, Liam ERD for ER diagrams
13+
- **Static Site**: VitePress for serving documentation website
14+
- **Docker**: Containerized database and tbls execution
15+
- **Git Hooks**: Lefthook for pre-commit formatting and schema generation
16+
17+
## Essential Commands
18+
19+
### Database Operations
20+
```bash
21+
# Start database container
22+
pnpm db:serve
23+
24+
# Stop and remove database with volumes
25+
pnpm db:down
26+
27+
# Rebuild database from scratch
28+
pnpm db:rebuild
29+
30+
# Generate schema documentation using tbls
31+
pnpm db:schema
32+
```
33+
34+
### Documentation
35+
```bash
36+
# Start VitePress development server
37+
pnpm docs:dev
38+
39+
# Build documentation site
40+
pnpm docs:build
41+
42+
# Preview built documentation
43+
pnpm docs:preview
44+
45+
# Generate ER diagram from schema
46+
pnpm er:build
47+
48+
# Serve ER diagram locally
49+
pnpm er:serve
50+
```
51+
52+
### Code Formatting
53+
```bash
54+
# Format all SQL files using sql-formatter
55+
pnpm sql:fix
56+
```
57+
58+
## Architecture
59+
60+
### Database Schema Management
61+
- Migration files in `sql/migration/` follow Flyway naming conventions
62+
- DDL files: `V{version}__{description}.sql` for versioned migrations
63+
- DML files: Data seeding organized by environment (`local/`, `stg/`, `prd/`)
64+
- Views: `R__views.sql` as repeatable migrations
65+
66+
### Documentation Pipeline
67+
1. Database schema → tbls → generates markdown docs in `docs/schema/`
68+
2. Schema JSON → Liam ERD → generates ER diagrams in `docs/out/`
69+
3. VitePress builds static site from docs/ directory
70+
71+
### Configuration Files
72+
- `.tbls.yml`: tbls configuration for schema documentation generation
73+
- `.sql-formatter.json`: SQL formatting rules (MySQL dialect, uppercase keywords)
74+
- `lefthook.yml`: Git hooks for SQL formatting and schema regeneration
75+
- `.vitepress/config.ts`: VitePress site configuration
76+
77+
## Development Workflow
78+
79+
1. Make database schema changes in `sql/migration/`
80+
2. Run `pnpm sql:fix` to format SQL (or let git hooks handle it)
81+
3. Run `pnpm db:rebuild` to apply migrations
82+
4. Run `pnpm db:schema` to regenerate documentation
83+
5. Run `pnpm er:build` to update ER diagrams
84+
6. Use `pnpm docs:dev` to preview changes
85+
86+
## Important Notes
87+
88+
- The database runs on port 3306 with credentials: `user:Password@db:3306/sample_rdb`
89+
- Schema documentation is generated in Japanese (see dict section in .tbls.yml)
90+
- Pre-commit hooks automatically format SQL and rebuild documentation
91+
- ER diagrams show relationships up to distance 2 between tables
92+
- Excel schema export available in `excel/schema.xlsx`

0 commit comments

Comments
 (0)