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
7f8427fb
Unverified
Commit
7f8427fb
authored
5 years ago
by
Walter Leibbrandt
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Don't use `system` command as alias [ci mysql] (#12098)
parent
dde9b939
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/driver/mysql.clj
+18
-16
18 additions, 16 deletions
src/metabase/driver/mysql.clj
test/metabase/driver/mysql_test.clj
+22
-15
22 additions, 15 deletions
test/metabase/driver/mysql_test.clj
with
40 additions
and
31 deletions
src/metabase/driver/mysql.clj
+
18
−
16
View file @
7f8427fb
...
...
@@ -116,25 +116,27 @@
(
defmethod
driver/db-default-timezone
:mysql
[
_
db
]
(
let
[
spec
(
sql-jdbc.conn/db->pooled-connection-spec
db
)
sql
(
str
"SELECT @@GLOBAL.time_zone AS global,"
" @@system_time_zone AS system,"
" time_format("
" timediff(now(), convert_tz(now(), @@GLOBAL.time_zone, '+00:00')),"
" '%H:%i'"
" ) AS offset;"
)
[{
:keys
[
global
system
offset
]}]
(
jdbc/query
spec
sql
)
the-valid-id
(
fn
[
zone-id
]
(
when
zone-id
(
try
(
.getId
(
t/zone-id
zone-id
))
(
catch
Throwable
_
))))]
(
let
[
spec
(
sql-jdbc.conn/db->pooled-connection-spec
db
)
sql
(
str
"SELECT @@GLOBAL.time_zone AS global_tz,"
" @@system_time_zone AS system_tz,"
" time_format("
" timediff("
" now(), convert_tz(now(), @@GLOBAL.time_zone, '+00:00')"
" ),"
" '%H:%i'"
" ) AS offset;"
)
[{
:keys
[
global_tz
system_tz
offset
]}]
(
jdbc/query
spec
sql
)
the-valid-id
(
fn
[
zone-id
]
(
when
zone-id
(
try
(
.getId
(
t/zone-id
zone-id
))
(
catch
Throwable
_
))))]
(
or
;; if global timezone ID is 'SYSTEM', then try to use the system timezone ID
(
when
(
=
global
"SYSTEM"
)
(
the-valid-id
system
))
(
when
(
=
global
_tz
"SYSTEM"
)
(
the-valid-id
system
_tz
))
;; otherwise try to use the global ID
(
the-valid-id
global
)
(
the-valid-id
global
_tz
)
;; failing that, calculate the offset between now in the global timezone and now in UTC. Non-negative offsets
;; don't come back with `+` so add that if needed
(
if
(
str/starts-with?
offset
"-"
)
...
...
This diff is collapsed.
Click to expand it.
test/metabase/driver/mysql_test.clj
+
22
−
15
View file @
7f8427fb
...
...
@@ -98,21 +98,28 @@
[
result-row
]
(
apply
orig
spec
sql-args
options
))))]
(
driver/db-default-timezone
driver/*driver*
db
))))]
(
is
(
=
"US/Pacific"
(
timezone
{
:global
"US/Pacific"
,
:system
"UTC"
}))
"Should use global timezone by default"
)
(
is
(
=
"UTC"
(
timezone
{
:global
"SYSTEM"
,
:system
"UTC"
}))
"If global timezone is 'SYSTEM', should use system timezone"
)
(
is
(
=
"+00:00"
(
timezone
{
:offset
"00:00"
}))
"Should fall back to returning `offset` if global/system aren't present"
)
(
is
(
=
"-08:00"
(
timezone
{
:global
"PDT"
,
:system
"PDT"
,
:offset
"-08:00"
}))
"If global timezone is invalid, should fall back to offset"
)
(
is
(
=
"+00:00"
(
timezone
{
:global
"PDT"
,
:system
"UTC"
,
:offset
"00:00"
}))
"Should add a `+` if needed to offset"
))))
(
testing
"Should use global timezone by default"
(
is
(
=
"US/Pacific"
(
timezone
{
:global_tz
"US/Pacific"
,
:system_tz
"UTC"
}))))
(
testing
"If global timezone is 'SYSTEM', should use system timezone"
(
is
(
=
"UTC"
(
timezone
{
:global_tz
"SYSTEM"
,
:system_tz
"UTC"
}))))
(
testing
"Should fall back to returning `offset` if global/system aren't present"
(
is
(
=
"+00:00"
(
timezone
{
:offset
"00:00"
}))))
(
testing
"If global timezone is invalid, should fall back to offset"
(
is
(
=
"-08:00"
(
timezone
{
:global_tz
"PDT"
,
:system_tz
"PDT"
,
:offset
"-08:00"
}))))
(
testing
"Should add a `+` if needed to offset"
(
is
(
=
"+00:00"
(
timezone
{
:global_tz
"PDT"
,
:system_tz
"UTC"
,
:offset
"00:00"
})))))
(
testing
"real timezone query doesn't fail"
(
is
(
nil?
(
try
(
driver/db-default-timezone
driver/*driver*
(
data/db
))
nil
(
catch
Throwable
e
e
)))))))
(
def
^
:private
before-daylight-savings
#
t
"2018-03-10T10:00:00Z"
)
...
...
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