Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
38faad60
Unverified
Commit
38faad60
authored
3 years ago
by
Cam Saul
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
GET /api/database/:id/schemas should not return 'empty' schemas (#18123)
parent
6725c0cf
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/api/database.clj
+6
-1
6 additions, 1 deletion
src/metabase/api/database.clj
src/metabase/models/table.clj
+2
-2
2 additions, 2 deletions
src/metabase/models/table.clj
test/metabase/api/database_test.clj
+12
-0
12 additions, 0 deletions
test/metabase/api/database_test.clj
with
20 additions
and
3 deletions
src/metabase/api/database.clj
+
6
−
1
View file @
38faad60
...
...
@@ -696,7 +696,11 @@
"Returns a list of all the schemas found for the database `id`"
[
id
]
(
api/read-check
Database
id
)
(
->>
(
db/select-field
:schema
Table
:db_id
id,
:active
true,
{
:order-by
[[
:%lower.schema
:asc
]]})
(
->>
(
db/select-field
:schema
Table
:db_id
id
:active
true
;; a non-nil value means Table is hidden -- see [[metabase.models.table/visibility-types]]
:visibility_type
nil
{
:order-by
[[
:%lower.schema
:asc
]]})
(
filter
(
partial
can-read-schema?
id
))
;; for `nil` schemas return the empty string
(
map
#
(
if
(
nil?
%
)
""
%
))
...
...
@@ -723,6 +727,7 @@
:db_id
db-id
:schema
schema
:active
true
;; a non-nil value means Table is hidden -- see [[metabase.models.table/visibility-types]]
:visibility_type
nil
{
:order-by
[[
:display_name
:asc
]]})))
...
...
This diff is collapsed.
Click to expand it.
src/metabase/models/table.clj
+
2
−
2
View file @
38faad60
...
...
@@ -16,12 +16,12 @@
;;; ----------------------------------------------- Constants + Entity -----------------------------------------------
(
def
^
:const
visibility-types
(
def
visibility-types
"Valid values for `Table.visibility_type` (field may also be `nil`).
(Basically any non-nil value is a reason for hiding the table.)"
#
{
:hidden
:technical
:cruft
})
(
def
^
:const
field-orderings
(
def
field-orderings
"Valid values for `Table.field_order`.
`:database` - use the same order as in the table definition in the DB;
`:alphabetical` - order alphabetically by name;
...
...
This diff is collapsed.
Click to expand it.
test/metabase/api/database_test.clj
+
12
−
0
View file @
38faad60
...
...
@@ -837,6 +837,18 @@
(
is
(
=
[
""
" "
]
(
mt/user-http-request
:lucky
:get
200
(
format
"database/%d/schemas"
db-id
))))))))
(
deftest
get-schemas-should-not-return-schemas-with-no-visible-tables
(
testing
"GET /api/database/:id/schemas should not return schemas with no VISIBLE TABLES"
(
mt/with-temp*
[
Database
[{
db-id
:id
}]
Table
[
_
{
:db_id
db-id,
:schema
"schema_1"
,
:name
"table_1"
}]
;; table is not visible. Any non-nil value of `visibility_type` means Table shouldn't be visible
Table
[
_
{
:db_id
db-id,
:schema
"schema_2"
,
:name
"table_2a"
,
:visibility_type
"hidden"
}]
Table
[
_
{
:db_id
db-id,
:schema
"schema_2"
,
:name
"table_2b"
,
:visibility_type
"cruft"
}]
;; table is not active
Table
[
_
{
:db_id
db-id,
:schema
"schema_3"
,
:name
"table_3"
,
:active
false
}]]
(
is
(
=
#
{
"schema_1"
}
(
set
(
mt/user-http-request
:crowberto
:get
200
(
format
"database/%d/schemas"
db-id
))))))))
(
deftest
get-schema-tables-test
(
testing
"GET /api/database/:id/schema/:schema\n"
(
testing
"Permissions: Can we fetch the Tables in a schema?"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment