Skip to content

Commit

Permalink
Merge pull request #4 from liam-hq/mysql-with-tbls
Browse files Browse the repository at this point in the history
Add sample dir: mysql-with-tbls
  • Loading branch information
MH4GF authored Jan 28, 2025
2 parents 40774e4 + 0ab8a95 commit 1b1870b
Show file tree
Hide file tree
Showing 29 changed files with 2,331 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/mysql-with-tbls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: MySQL with tbls

on:
pull_request:
paths:
- "samples/mysql-with-tbls/**"
- ".github/workflows/mysql-with-tbls.yml"
schedule:
# Schedule: Runs at 9:00 AM and 1:00 PM Asia/Tokyo time (UTC+9) on weekdays (Monday to Friday).
- cron: "0 0,4 * * mon-fri"

jobs:
document:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_DATABASE: blog_app
MYSQL_ALLOW_EMPTY_PASSWORD: yes
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -h localhost"
--health-interval=10s
--health-timeout=5s
--health-retries=3
steps:
- uses: actions/checkout@v4

- name: Setup tbls
uses: k1low/setup-tbls@v1

- name: Migrate schema
run: |
mysql -h127.0.0.1 -uroot blog_app < samples/mysql-with-tbls/schema.sql
- name: Generate tbls document
run: |
tbls doc --force --config samples/mysql-with-tbls/.tbls.yml
- name: Generate ER Diagrams
run: npx @liam-hq/cli erd build --format tbls --input samples/mysql-with-tbls/docs/schema.json

# NOTE: For deploy, comment-in.
# see also other .github/workflows/ files.
# - name: Deploy ERD to Cloudflare Pages
# uses: cloudflare/wrangler-action@v3
# with:
# apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN_SAMPLE_PRISMA }}
# accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID_SAMPLE_PRISMA }}
# workingDirectory: samples/prisma-with-cloudflare-pages
# command: pages deploy ./dist --project-name=prisma-with-cloudflare-pages
# gitHubToken: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions samples/mysql-with-tbls/.tbls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dsn: mysql://[email protected]:3306/blog_app
docPath: samples/mysql-with-tbls/docs
16 changes: 16 additions & 0 deletions samples/mysql-with-tbls/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# MySQL with tbls

This project is a development example using MySQL and tbls, demonstrating how to automatically generate database documentation.

In this demo, a GitHub Actions workflow generates database documentation using tbls, which is then used as input for the Liam CLI to create ER diagrams.

## Workflow

The documentation process is automated using a GitHub Actions workflow defined in [.github/workflows/mysql-with-tbls.yml](/.github/workflows/mysql-with-tbls.yml).

## Documentation

For more detailed information, please refer to:

- [tbls documentation](https://github.com/k1LoW/tbls)
- [Liam documentation's tbls support page](https://liambx.com/docs/parser/supported-formats/tbls)
25 changes: 25 additions & 0 deletions samples/mysql-with-tbls/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# blog_app

## Tables

| Name | Columns | Comment | Type |
| ---- | ------- | ------- | ---- |
| [categories](categories.md) | 2 | | BASE TABLE |
| [comments](comments.md) | 6 | | BASE TABLE |
| [notifications](notifications.md) | 6 | | BASE TABLE |
| [order_items](order_items.md) | 5 | | BASE TABLE |
| [orders](orders.md) | 6 | | BASE TABLE |
| [posts](posts.md) | 7 | | BASE TABLE |
| [posts_tags](posts_tags.md) | 2 | | BASE TABLE |
| [products](products.md) | 8 | | BASE TABLE |
| [profiles](profiles.md) | 8 | | BASE TABLE |
| [tags](tags.md) | 2 | | BASE TABLE |
| [users](users.md) | 6 | | BASE TABLE |

## Relations

![er](schema.svg)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
46 changes: 46 additions & 0 deletions samples/mysql-with-tbls/docs/categories.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# categories

## Description

<details>
<summary><strong>Table Definition</strong></summary>

```sql
CREATE TABLE `categories` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
```

</details>

## Columns

| Name | Type | Default | Nullable | Extra Definition | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | ---------------- | -------- | ------- | ------- |
| id | int | | false | auto_increment | [products](products.md) | | |
| name | varchar(255) | | false | | | | |

## Constraints

| Name | Type | Definition |
| ---- | ---- | ---------- |
| name | UNIQUE | UNIQUE KEY name (name) |
| PRIMARY | PRIMARY KEY | PRIMARY KEY (id) |

## Indexes

| Name | Definition |
| ---- | ---------- |
| PRIMARY | PRIMARY KEY (id) USING BTREE |
| name | UNIQUE KEY name (name) USING BTREE |

## Relations

![er](categories.svg)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
69 changes: 69 additions & 0 deletions samples/mysql-with-tbls/docs/categories.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions samples/mysql-with-tbls/docs/comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# comments

## Description

<details>
<summary><strong>Table Definition</strong></summary>

```sql
CREATE TABLE `comments` (
`id` int NOT NULL AUTO_INCREMENT,
`content` text NOT NULL,
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`post_id` int NOT NULL,
`author_id` int NOT NULL,
PRIMARY KEY (`id`),
KEY `post_id` (`post_id`),
KEY `author_id` (`author_id`),
CONSTRAINT `comments_ibfk_1` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),
CONSTRAINT `comments_ibfk_2` FOREIGN KEY (`author_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
```

</details>

## Columns

| Name | Type | Default | Nullable | Extra Definition | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | ---------------- | -------- | ------- | ------- |
| id | int | | false | auto_increment | | | |
| content | text | | false | | | | |
| created_at | timestamp | CURRENT_TIMESTAMP | true | DEFAULT_GENERATED | | | |
| updated_at | timestamp | CURRENT_TIMESTAMP | true | DEFAULT_GENERATED on update CURRENT_TIMESTAMP | | | |
| post_id | int | | false | | | [posts](posts.md) | |
| author_id | int | | false | | | [users](users.md) | |

## Constraints

| Name | Type | Definition |
| ---- | ---- | ---------- |
| comments_ibfk_1 | FOREIGN KEY | FOREIGN KEY (post_id) REFERENCES posts (id) |
| comments_ibfk_2 | FOREIGN KEY | FOREIGN KEY (author_id) REFERENCES users (id) |
| PRIMARY | PRIMARY KEY | PRIMARY KEY (id) |

## Indexes

| Name | Definition |
| ---- | ---------- |
| author_id | KEY author_id (author_id) USING BTREE |
| post_id | KEY post_id (post_id) USING BTREE |
| PRIMARY | PRIMARY KEY (id) USING BTREE |

## Relations

![er](comments.svg)

---

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

0 comments on commit 1b1870b

Please sign in to comment.