Skip to content

Commit

Permalink
Merge pull request #643 from k1LoW/viewpoint-support-schema
Browse files Browse the repository at this point in the history
Support wildcard in `viewpoints[].tables:`
  • Loading branch information
k1LoW authored Jan 17, 2025
2 parents a0a4f93 + a6b2295 commit 77e97f5
Show file tree
Hide file tree
Showing 39 changed files with 682 additions and 17 deletions.
15 changes: 8 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,16 +512,17 @@ func (c *Config) ModifySchema(s *schema.Schema) error {
// Add viewpoints to table

for _, t := range v.Tables {
println(v.Name, t)
table, err := s.FindTableByName(t)
ts, err := s.MatchTablesByName(t)
if err != nil {
return err
}
table.Viewpoints = append(table.Viewpoints, &schema.TableViewpoint{
Index: vi,
Name: v.Name,
Desc: v.Desc,
})
for _, tt := range ts {
tt.Viewpoints = append(tt.Viewpoints, &schema.TableViewpoint{
Index: vi,
Name: v.Name,
Desc: v.Desc,
})
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions drivers/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ const queryFunctions95 = `SELECT
FROM pg_proc AS p
LEFT JOIN pg_namespace AS n ON p.pronamespace = n.oid
LEFT JOIN pg_type AS t ON t.oid = p.prorettype
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')`
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
ORDER BY p.oid;`

const queryFunctions = `SELECT
n.nspname AS schema_name,
Expand All @@ -415,7 +416,8 @@ const queryFunctions = `SELECT
FROM pg_proc AS p
LEFT JOIN pg_namespace AS n ON p.pronamespace = n.oid
LEFT JOIN pg_type AS t ON t.oid = p.prorettype
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')`
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
ORDER BY p.oid;`

const queryStoredProcedureSupported = `SELECT column_name
FROM information_schema.columns
Expand Down
7 changes: 7 additions & 0 deletions sample/adjust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

Sample PostgreSQL database document.

## Viewpoints

| Name | Description |
| ------------------------------- | ------------------------- |
| [post](viewpoint-0.md) | for post |
| [administrator](viewpoint-1.md) | administrator schema only |

## Tables

| Name | Columns | Comment | Type |
Expand Down
6 changes: 6 additions & 0 deletions sample/adjust/administrator.blogs.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ admin blogs
| created | timestamp without time zone | | false | | | |
| updated | timestamp without time zone | | true | | | |

## Viewpoints

| Name | Definition |
| ------------------------------- | ------------------------- |
| [administrator](viewpoint-1.md) | administrator schema only |

## Constraints

| Name | Type | Definition |
Expand Down
6 changes: 6 additions & 0 deletions sample/adjust/public.post_comment_stars.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ CREATE MATERIALIZED VIEW post_comment_stars AS (
| [public.comment_stars](public.comment_stars.md) | 6 | | BASE TABLE |
| [public.users](public.users.md) | 6 | Users table | BASE TABLE |

## Viewpoints

| Name | Definition |
| ---------------------- | ---------- |
| [post](viewpoint-0.md) | for post |

## Relations

![er](public.post_comment_stars.svg)
Expand Down
6 changes: 6 additions & 0 deletions sample/adjust/public.post_comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ CREATE VIEW post_comments AS (
| [public.comments](public.comments.md) | 7 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE |
| [public.users](public.users.md) | 6 | Users table | BASE TABLE |

## Viewpoints

| Name | Definition |
| ---------------------- | ---------- |
| [post](viewpoint-0.md) | for post |

## Relations

![er](public.post_comments.svg)
Expand Down
6 changes: 6 additions & 0 deletions sample/adjust/public.posts.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ Posts table
| created | timestamp without time zone | | false | | | |
| updated | timestamp without time zone | | true | | | |

## Viewpoints

| Name | Definition |
| ---------------------- | ---------- |
| [post](viewpoint-0.md) | for post |

## Constraints

| Name | Type | Definition | Comment |
Expand Down
2 changes: 1 addition & 1 deletion sample/adjust/schema.json

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions sample/adjust/viewpoint-0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# post

## Description

for post

## Tables

| Name | Columns | Comment | Type |
| --------------------------------------------------------- | ------- | ---------------------------- | ----------------- |
| [public.posts](public.posts.md) | 8 | Posts table | BASE TABLE |
| [public.post_comments](public.post_comments.md) | 7 | post and comments View table | VIEW |
| [public.post_comment_stars](public.post_comment_stars.md) | 5 | | MATERIALIZED VIEW |

## Relations

![er](viewpoint-0.svg)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
100 changes: 100 additions & 0 deletions sample/adjust/viewpoint-0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions sample/adjust/viewpoint-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# administrator

## Description

administrator schema only

## Tables

| Name | Columns | Comment | Type |
| --------------------------------------------- | ------- | ----------- | ---------- |
| [administrator.blogs](administrator.blogs.md) | 6 | admin blogs | BASE TABLE |

## Relations

![er](viewpoint-1.svg)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
40 changes: 40 additions & 0 deletions sample/adjust/viewpoint-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion sample/detect_relations/schema.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sample/detect_relations_singular/schema.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sample/mariadb/schema.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sample/mssql/schema.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sample/mysql/schema.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions sample/postgres/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

Sample PostgreSQL database document.

## Viewpoints

| Name | Description |
| ---- | ----------- |
| [post](viewpoint-0.md) | for post |
| [administrator](viewpoint-1.md) | administrator schema only |

## Tables

| Name | Columns | Comment | Type |
Expand Down
6 changes: 6 additions & 0 deletions sample/postgres/administrator.blogs.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ admin blogs
| created | timestamp without time zone | | false | | | |
| updated | timestamp without time zone | | true | | | |

## Viewpoints

| Name | Definition |
| ---- | ---------- |
| [administrator](viewpoint-1.md) | administrator schema only |

## Constraints

| Name | Type | Definition |
Expand Down
6 changes: 6 additions & 0 deletions sample/postgres/public.post_comment_stars.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ CREATE MATERIALIZED VIEW post_comment_stars AS (
| [public.comment_stars](public.comment_stars.md) | 6 | | BASE TABLE |
| [public.users](public.users.md) | 6 | Users table | BASE TABLE |

## Viewpoints

| Name | Definition |
| ---- | ---------- |
| [post](viewpoint-0.md) | for post |

## Relations

![er](public.post_comment_stars.svg)
Expand Down
6 changes: 6 additions & 0 deletions sample/postgres/public.post_comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ CREATE VIEW post_comments AS (
| [public.comments](public.comments.md) | 7 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE |
| [public.users](public.users.md) | 6 | Users table | BASE TABLE |

## Viewpoints

| Name | Definition |
| ---- | ---------- |
| [post](viewpoint-0.md) | for post |

## Relations

![er](public.post_comments.svg)
Expand Down
6 changes: 6 additions & 0 deletions sample/postgres/public.posts.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ Posts table
| created | timestamp without time zone | | false | | | |
| updated | timestamp without time zone | | true | | | |

## Viewpoints

| Name | Definition |
| ---- | ---------- |
| [post](viewpoint-0.md) | for post |

## Constraints

| Name | Type | Definition | Comment |
Expand Down
2 changes: 1 addition & 1 deletion sample/postgres/schema.json

Large diffs are not rendered by default.

Loading

0 comments on commit 77e97f5

Please sign in to comment.