Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support wildcard in viewpoints[].tables: #643

Merged
merged 5 commits into from
Jan 17, 2025
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
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
Loading