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
d60c6492
Unverified
Commit
d60c6492
authored
8 years ago
by
Cam Saül
Browse files
Options
Downloads
Patches
Plain Diff
Update path to sample dataset on launch in case JAR moves
parent
37db081c
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/sample_data.clj
+18
-21
18 additions, 21 deletions
src/metabase/sample_data.clj
with
18 additions
and
21 deletions
src/metabase/sample_data.clj
+
18
−
21
View file @
d60c6492
...
...
@@ -8,8 +8,16 @@
[
metabase.util
:as
u
]))
(
def
^
:private
^
:const
sample-dataset-name
"Sample Dataset"
)
(
def
^
:private
^
:const
sample-dataset-filename
"sample-dataset.db.mv.db"
)
(
def
^
:private
^
:const
^
String
sample-dataset-name
"Sample Dataset"
)
(
def
^
:private
^
:const
^
String
sample-dataset-filename
"sample-dataset.db.mv.db"
)
(
defn-
db-details
[]
(
let
[
resource
(
or
(
io/resource
sample-dataset-filename
)
(
throw
(
Exception.
(
format
"Can't load sample dataset: the DB file '%s' can't be found."
sample-dataset-filename
))))]
{
:db
(
->
(
.getPath
resource
)
(
s/replace
#
"^file:"
"zip:"
)
; to connect to an H2 DB inside a JAR just replace file: with zip:
(
s/replace
#
"\.mv\.db$"
""
)
; strip the .mv.db suffix from the path
(
str
";USER=GUEST;PASSWORD=guest"
))}))
; specify the GUEST user account created for the DB
(
defn
add-sample-dataset!
"Add the sample dataset as a Metabase DB if it doesn't already exist."
...
...
@@ -17,28 +25,17 @@
(
when-not
(
db/exists?
Database
:is_sample
true
)
(
try
(
log/info
"Loading sample dataset..."
)
(
let
[
resource
(
io/resource
sample-dataset-filename
)]
(
if-not
resource
(
log/error
(
u/format-color
'red
"Can't load sample dataset: the DB file '%s' can't be found."
sample-dataset-filename
))
(
let
[
h2-file
(
->
(
.getPath
resource
)
(
s/replace
#
"^file:"
"zip:"
)
; to connect to an H2 DB inside a JAR just replace file: with zip:
(
s/replace
#
"\.mv\.db$"
""
)
; strip the .mv.db suffix from the path
(
str
";USER=GUEST;PASSWORD=guest"
))
; specify the GUEST user account created for the DB
db
(
db/insert!
Database
:name
sample-dataset-name
:details
{
:db
h2-file
}
:engine
:h2
:is_sample
true
)]
(
sync-database/sync-database!
db
))))
(
sync-database/sync-database!
(
db/insert!
Database
:name
sample-dataset-name
:details
(
db-details
)
:engine
:h2
:is_sample
true
))
(
catch
Throwable
e
(
log/error
(
u/format-color
'red
"Failed to load sample dataset: %s\n%s"
(
.getMessage
e
)
(
u/pprint-to-str
(
u/filtered-stacktrace
e
))))))))
(
defn
update-sample-dataset-if-needed!
"
Re-sync
the sample dataset DB if it exists."
"
Update the path to
the sample dataset DB if it exists
in case the JAR has moved
."
[]
;; TODO - it would be a bit nicer if we skipped this when the data hasn't changed
(
when-let
[
db
(
Database
:is_sample
true
)]
(
try
(
sync-database/sync-database!
db
)
(
catch
Throwable
e
(
log/error
(
u/format-color
'red
"Failed to update sample dataset: %s\n%s"
(
.getMessage
e
)
(
u/pprint-to-str
(
u/filtered-stacktrace
e
))))))))
(
db/update!
Database
(
:id
db
)
:details
(
db-details
))))
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