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
0b0ea8fe
Unverified
Commit
0b0ea8fe
authored
1 year ago
by
Ngoc Khuat
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix unable to start on windows with h2 (#39739)
parent
796256c5
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/db/data_source.clj
+10
-5
10 additions, 5 deletions
src/metabase/db/data_source.clj
src/metabase/db/update_h2.clj
+16
-10
16 additions, 10 deletions
src/metabase/db/update_h2.clj
test/metabase/cmd/dump_to_h2_test.clj
+12
-18
12 additions, 18 deletions
test/metabase/cmd/dump_to_h2_test.clj
with
38 additions
and
33 deletions
src/metabase/db/data_source.clj
+
10
−
5
View file @
0b0ea8fe
...
...
@@ -17,7 +17,10 @@
(
set!
*warn-on-reflection*
true
)
(
p/deftype+
DataSource
[
^
String
url
^
Properties
properties
]
;; NOTE: Never instantiate a DataSource directly
;; Use one of our helper functions below to ensure [[update-h2/update-if-needed!]] is called
;; You can use [[raw-connection-string->DataSource]] or [[broken-out-details->DataSource]]
(
p/deftype+
^
:private
DataSource
[
^
String
url
^
Properties
properties
]
pretty/PrettyPrintable
(
pretty
[
_
]
;; in dev we can actually print out the details, it's useful in debugging. Everywhere else we should obscure them
...
...
@@ -28,10 +31,9 @@
javax.sql.DataSource
(
getConnection
[
_
]
(
update-h2/update-if-needed!
url
)
(
if
properties
(
DriverManager/getConnection
url
properties
)
(
DriverManager/getConnection
url
)))
(
if
properties
(
DriverManager/getConnection
url
properties
)
(
DriverManager/getConnection
url
)))
;; we don't use (.getConnection this url user password) so we don't need to implement it.
(
getConnection
[
_
_user
_password
]
...
...
@@ -85,6 +87,7 @@
m
(
cond->
m
(
seq
username
)
(
assoc
:user
username
)
(
seq
password
)
(
assoc
:password
password
))]
(
update-h2/update-if-needed!
s
)
(
->DataSource
s
(
some->
(
not-empty
m
)
connection-pool/map->properties
)))))
(
defn
broken-out-details->DataSource
...
...
@@ -97,4 +100,6 @@
url
(
format
"jdbc:%s:%s"
subprotocol
subname
)
properties
(
some->
(
not-empty
(
dissoc
spec
:classname
:subprotocol
:subname
))
connection-pool/map->properties
)]
(
update-h2/update-if-needed!
url
)
(
->DataSource
url
properties
)))
This diff is collapsed.
Click to expand it.
src/metabase/db/update_h2.clj
+
16
−
10
View file @
0b0ea8fe
...
...
@@ -35,7 +35,7 @@
[
jdbc-url
]
(
second
(
re-matches
#
"jdbc:h2:file:(.*)$"
jdbc-url
)))
(
defn
db-version
(
defn
-
db-version
!
"Returns the H2 major version number of H2 MV database file at path, or nil if no file exists"
[
jdbc-url
]
;; The H2 database version is indicated in the "format:" key of the MV file header, which is 4096 bytes
...
...
@@ -87,15 +87,21 @@
(
def
^
:private
h2-lock
(
Object.
))
(
defn-
update-needed?
[
jdbc-url
]
(
=
1
(
db-version!
jdbc-url
)))
(
defn
update-if-needed!
"Updates H2 database at db-path from version 1.x to 2.x if jdbc-url points
to version 1 H2 database."
to version 1 H2 database."
[
jdbc-url
]
(
locking
h2-lock
(
when
(
=
1
(
db-version
jdbc-url
))
(
log/info
"H2 v1 database detected, updating..."
)
(
try
(
update!
jdbc-url
)
(
catch
Exception
e
(
log/error
"Failed to update H2 database:"
e
)
(
throw
e
))))))
(
when
(
and
(
h2-base-path
jdbc-url
)
(
update-needed?
jdbc-url
))
(
locking
h2-lock
;; the database may have been upgraded while we waited for the lock
(
when
(
update-needed?
jdbc-url
)
(
log/info
"H2 v1 database detected, updating..."
)
(
try
(
update!
jdbc-url
)
(
catch
Exception
e
(
log/error
"Failed to update H2 database:"
e
)
(
throw
e
)))))))
This diff is collapsed.
Click to expand it.
test/metabase/cmd/dump_to_h2_test.clj
+
12
−
18
View file @
0b0ea8fe
...
...
@@ -26,26 +26,20 @@
(
deftest
dump-deletes-target-db-files-tests
;; test fails when the application db is anything but H2 presently
;; TODO: make this test work with postgres / mysql / mariadb
(
mt/with-temp-file
[
tmp-h2-db
"mbtest_dump.h2"
]
(
let
[
tmp-h2-db-mv
(
str
tmp-h2-db
".mv.db"
)
file-contents
{
tmp-h2-db
"Not really an H2 DB"
tmp-h2-db-mv
"Not really another H2 DB"
}]
(
mt/with-temp-file
[
tmp-h2-db
"mbtest_dump.h2"
tmp-h2-db-mv
"mbtest_dump.h2.mv.db"
]
(
let
[
h2-file-dump-content
"H:2,block:61,blockSize:1000,chunk:7,clean:1,created:18e17379d42,format:2,version:7"
file-contents
{
tmp-h2-db
h2-file-dump-content
tmp-h2-db-mv
h2-file-dump-content
}]
;; 1. Don't actually run the copy steps themselves
(
with-redefs
[
copy/copy!
(
constantly
nil
)]
(
try
(
doseq
[[
filename
contents
]
file-contents
]
(
spit
filename
contents
))
(
dump-to-h2/dump-to-h2!
tmp-h2-db
)
(
mt/with-dynamic-redefs
[
copy/copy!
(
constantly
nil
)]
(
doseq
[[
filename
contents
]
file-contents
]
(
spit
filename
contents
))
(
dump-to-h2/dump-to-h2!
tmp-h2-db
)
(
doseq
[
filename
(
keys
file-contents
)]
(
testing
(
str
filename
" was deleted"
)
(
is
(
false?
(
.exists
(
io/file
filename
))))))
(
finally
(
doseq
[
filename
(
keys
file-contents
)
:let
[
file
(
io/file
filename
)]]
(
when
(
.exists
file
)
(
io/delete-file
file
)))))))))
(
doseq
[
filename
(
keys
file-contents
)]
(
testing
(
str
filename
" was deleted"
)
(
is
(
false?
(
.exists
(
io/file
filename
))))))))))
(
deftest
cmd-dump-to-h2-returns-code-from-dump-test
(
with-redefs
[
dump-to-h2/dump-to-h2!
#
(
throw
(
Exception.
"err"
))
...
...
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