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
eaa25b49
Unverified
Commit
eaa25b49
authored
6 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Fail gracefully when migrating invalid BigQuery legacy SQL questions
parent
9adfbb45
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/db/migrations.clj
+20
-11
20 additions, 11 deletions
src/metabase/db/migrations.clj
test/metabase/db/migrations_test.clj
+13
-0
13 additions, 0 deletions
test/metabase/db/migrations_test.clj
with
33 additions
and
11 deletions
src/metabase/db/migrations.clj
+
20
−
11
View file @
eaa25b49
...
...
@@ -279,17 +279,26 @@
(
doseq
[
database-id
(
db/select-ids
Database
:engine
"bigquery"
)]
;; For each Card belonging to that BigQuery database...
(
doseq
[{
query
:dataset_query,
card-id
:id
}
(
db/select
[
Card
:id
:dataset_query
]
:database_id
database-id
)]
;; If the Card isn't native, ignore it
(
when
(
=
(
keyword
(
:type
query
))
:native
)
(
let
[
sql
(
get-in
query
[
:native
:query
])]
;; if the Card already contains a #standardSQL or #legacySQL (both are case-insenstive) directive, ignore it
(
when-not
(
re-find
#
"(?i)#(standard|legacy)sql"
sql
)
;; if it doesn't have a directive it would have (under old behavior) defaulted to legacy SQL, so give it a
;; #legacySQL directive...
(
let
[
updated-sql
(
str
"#legacySQL\n"
sql
)]
;; and save the updated dataset_query map
(
db/update!
Card
(
u/get-id
card-id
)
:dataset_query
(
assoc-in
query
[
:native
:query
]
updated-sql
)))))))))
(
try
;; If the Card isn't native, ignore it
(
when
(
=
(
keyword
(
:type
query
))
:native
)
;; there apparently are cases where we have a `:native` query with no `:query`. See #8924
(
when-let
[
sql
(
get-in
query
[
:native
:query
])]
;; if the Card already contains a #standardSQL or #legacySQL (both are case-insenstive) directive, ignore it
(
when-not
(
re-find
#
"(?i)#(standard|legacy)sql"
sql
)
;; if it doesn't have a directive it would have (under old behavior) defaulted to legacy SQL, so give it a
;; #legacySQL directive...
(
let
[
updated-sql
(
str
"#legacySQL\n"
sql
)]
;; and save the updated dataset_query map
(
db/update!
Card
(
u/get-id
card-id
)
:dataset_query
(
assoc-in
query
[
:native
:query
]
updated-sql
))))))
;; if for some reason something above fails (as in #8924) let's log the error and proceed. It's not mission
;; critical that we migrate existing queries anyway, and for ones that are impossible to migrate (e.g. ones
;; that are invalid in the first place) it's best to fail gracefully and proceed rather than nuke someone's MB
;; instance
(
catch
Throwable
e
(
log/error
e
(
trs
"Error adding legacy SQL directive to BigQuery saved Question"
)))))))
;; Before 0.30.0, we were storing the LDAP user's password in the `core_user` table (though it wasn't used). This
;; migration clears those passwords and replaces them with a UUID. This is similar to a new account setup, or how we
...
...
This diff is collapsed.
Click to expand it.
test/metabase/db/migrations_test.clj
+
13
−
0
View file @
eaa25b49
...
...
@@ -47,6 +47,19 @@
(
->>
(
db/select-field->field
:name
:dataset_query
Card
:id
[
:in
(
map
u/get-id
[
card-1
card-2
])])
(
m/map-vals
#
(
update
%
:database
integer?
)))))
;; if for some reason we have a BigQuery native query that does not actually have any SQL, ignore it rather than
;; barfing (#8924) (No idea how this was possible, but clearly it was)
(
expect
{
:database
true,
:type
:native,
:native
{
:query
1000
}}
(
tt/with-temp*
[
Database
[
database
{
:engine
"bigquery"
}]
Card
[
card
{
:database_id
(
u/get-id
database
)
:dataset_query
{
:database
(
u/get-id
database
)
:type
:native
:native
{
:query
1000
}}}]]
(
#
'migrations/add-legacy-sql-directive-to-bigquery-sql-cards
)
(
->
(
db/select-one-field
:dataset_query
Card
:id
(
u/get-id
card
))
(
update
:database
integer?
))))
;; Test clearing of LDAP user local passwords
(
expect
[
false
true
]
...
...
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