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
cb7ad5bc
Unverified
Commit
cb7ad5bc
authored
4 years ago
by
Simon Belak
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Field ordering: ignore non-active fields when validating (#13182)
parent
c2d7f9cf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/models/table.clj
+4
-1
4 additions, 1 deletion
src/metabase/models/table.clj
test/metabase/models/table_test.clj
+56
-0
56 additions, 0 deletions
test/metabase/models/table_test.clj
with
60 additions
and
1 deletion
src/metabase/models/table.clj
+
4
−
1
View file @
cb7ad5bc
...
...
@@ -102,7 +102,10 @@
(
defn-
valid-field-order?
"Field ordering is valid if all the fields from a given table are present and only from that table."
[
table
field-ordering
]
(
=
(
db/select-ids
Field
:table_id
(
u/get-id
table
))
(
set
field-ordering
)))
(
=
(
db/select-ids
Field
:table_id
(
u/get-id
table
)
:active
true
)
(
set
field-ordering
)))
(
defn
custom-order-fields!
"Set field order to `field-order`."
...
...
This diff is collapsed.
Click to expand it.
test/metabase/models/table_test.clj
0 → 100644
+
56
−
0
View file @
cb7ad5bc
(
ns
metabase.models.table-test
(
:require
[
clojure.java.jdbc
:as
jdbc
]
[
clojure.test
:refer
:all
]
[
metabase
[
sync
:as
sync
]
[
test
:as
mt
]]
[
metabase.models.table
:as
table
]
[
metabase.test.data.one-off-dbs
:as
one-off-dbs
]))
(
deftest
valud-field-order?-test
(
testing
"A valid field ordering is a set IDs of all active fields in a given table"
(
is
(
#
'table/valid-field-order?
(
mt/id
:venues
)
[(
mt/id
:venues
:name
)
(
mt/id
:venues
:category_id
)
(
mt/id
:venues
:latitude
)
(
mt/id
:venues
:longitude
)
(
mt/id
:venues
:price
)
(
mt/id
:venues
:id
)])))
(
testing
"Field ordering is invalid if some fields are missing"
(
is
(
false?
(
#
'table/valid-field-order?
(
mt/id
:venues
)
[(
mt/id
:venues
:category_id
)
(
mt/id
:venues
:latitude
)
(
mt/id
:venues
:longitude
)
(
mt/id
:venues
:price
)
(
mt/id
:venues
:id
)]))))
(
testing
"Field ordering is invalid if some fields are from a differnt table"
(
is
(
false?
(
#
'table/valid-field-order?
(
mt/id
:venues
)
[(
mt/id
:venues
:name
)
(
mt/id
:venues
:category_id
)
(
mt/id
:venues
:latitude
)
(
mt/id
:venues
:longitude
)
(
mt/id
:venues
:price
)
(
mt/id
:checkins
:id
)]))))
(
testing
"Only active fields should be considerd when checking field order"
(
one-off-dbs/with-blank-db
(
doseq
[
statement
[
;; H2 needs that 'guest' user for QP purposes. Set that up
"CREATE USER IF NOT EXISTS GUEST PASSWORD 'guest';"
;; Keep DB open until we say otherwise :)
"SET DB_CLOSE_DELAY -1;"
;; create table & load data
"DROP TABLE IF EXISTS \"BIRDS\";"
"CREATE TABLE \"BIRDS\" (\"SPECIES\" VARCHAR PRIMARY KEY, \"EXAMPLE_NAME\" VARCHAR);"
"GRANT ALL ON \"BIRDS\" TO GUEST;"
(
str
"INSERT INTO \"BIRDS\" (\"SPECIES\", \"EXAMPLE_NAME\") VALUES "
"('House Finch', 'Marshawn Finch'), "
"('California Gull', 'Steven Seagull'), "
"('Chicken', 'Colin Fowl');"
)]]
(
jdbc/execute!
one-off-dbs/*conn*
[
statement
]))
(
sync/sync-database!
(
mt/db
))
(
is
(
#
'table/valid-field-order?
(
mt/id
:birds
)
[(
mt/id
:birds
:species
)
(
mt/id
:birds
:example_name
)]))
(
jdbc/execute!
one-off-dbs/*conn*
[
"ALTER TABLE \"BIRDS\" DROP COLUMN \"EXAMPLE_NAME\";"
])
(
sync/sync-database!
(
mt/db
))
(
is
(
#
'table/valid-field-order?
(
mt/id
:birds
)
[(
mt/id
:birds
:species
)])))))
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