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
da2d0f39
Commit
da2d0f39
authored
9 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Sample Dataset sync improvements. Options for `defsetting`
parent
70d518a1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/core.clj
+18
-9
18 additions, 9 deletions
src/metabase/core.clj
src/metabase/models/setting.clj
+17
-9
17 additions, 9 deletions
src/metabase/models/setting.clj
src/metabase/task/sync_databases.clj
+7
-7
7 additions, 7 deletions
src/metabase/task/sync_databases.clj
with
42 additions
and
25 deletions
src/metabase/core.clj
+
18
−
9
View file @
da2d0f39
...
...
@@ -97,7 +97,7 @@
[]
(
log/info
"Metabase Initializing ... "
)
;; First of all, lets register a shutdown hook that will tidy things up for us on app exit
(
.addShutdownHook
(
Runtime/getRuntime
)
(
Thread.
destroy
))
(
.addShutdownHook
(
Runtime/getRuntime
)
(
Thread.
^
Runnable
destroy
))
(
log/debug
"Using Config:\n"
(
with-out-str
(
clojure.pprint/pprint
config/config-all
)))
;; Bootstrap the event system
...
...
@@ -152,8 +152,15 @@
(
def
^
:private
^
:const
sample-dataset-name
"Sample Dataset"
)
(
def
^
:private
^
:const
sample-dataset-filename
"sample-dataset.db.mv.db"
)
(
defsetting
sample-dataset-id
"The string-serialized integer ID of the `Database` entry for the Sample Dataset. If this is `nil`, the Sample Dataset
hasn't been loaded yet, and we should do so; otherwise we've already loaded it, and should not do so again. Keep in
mind the user may delete the Sample Dataset's DB, so this ID is not guaranteed to correspond to an existent object."
nil
:internal
true
)
; don't expose in the UI
(
defn-
add-sample-dataset!
[]
(
when-not
(
db/exists?
Database
:name
sample-dataset-
name
)
(
when-not
(
sample-dataset-
id
)
(
try
(
log/info
"Loading sample dataset..."
)
(
let
[
resource
(
->
(
Thread/currentThread
)
; hunt down the sample dataset DB file inside the current JAR
...
...
@@ -162,13 +169,15 @@
(
if-not
resource
(
log/error
(
format
"Can't load sample dataset: the DB file '%s' can't be found by the ClassLoader."
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
(
driver/sync-database!
(
db/ins
Database
:name
sample-dataset-name
:details
{
:db
h2-file
}
:engine
:h2
)))))
(
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/ins
Database
:name
sample-dataset-name
:details
{
:db
h2-file
}
:engine
:h2
)]
(
driver/sync-database!
db
)
(
sample-dataset-id
(
str
(
:id
db
))))))
(
catch
Throwable
e
(
log/error
(
format
"Failed to load sample dataset: %s"
(
.getMessage
e
)))))))
...
...
This diff is collapsed.
Click to expand it.
src/metabase/models/setting.clj
+
17
−
9
View file @
da2d0f39
...
...
@@ -5,7 +5,8 @@
[
environ.core
:as
env
]
[
korma.core
:as
k
]
[
metabase.db
:refer
[
sel
del
]]
[
metabase.models.interface
:refer
:all
]))
[
metabase.models.interface
:refer
:all
]
[
metabase.util
:as
u
]))
;; Settings are a fast + simple way to create a setting that can be set
;; from the SuperAdmin page. They are saved to the Database, but intelligently
...
...
@@ -71,7 +72,7 @@
(
k/set-fields
{
:value
v
})
(
k/where
{
:key
(
name
k
)}))
(
k/insert
Setting
(
k/values
{
:key
(
name
k
)
(
k/values
{
:key
(
name
k
)
:value
v
})))
(
restore-cache-if-needed
)
(
swap!
cached-setting->value
assoc
k
v
)
...
...
@@ -103,16 +104,21 @@
(mandrill-api-key nil) ; delete the value
A setting can be set from the SuperAdmin page or via the corresponding env var,
eg. `MB_MANDRILL_API_KEY` for the example above."
{
:arglists
'
([
setting-name
description
]
[
setting-name
description
default-value
])}
[
nm
description
&
[
default-value
]]
eg. `MB_MANDRILL_API_KEY` for the example above.
You may optionally pass any of the kvarg OPTIONS below, which are kept as part of the
metadata of the `Setting` under the key `::options`:
* `:internal` - This `Setting` is for internal use and shouldn't be exposed in the UI (i.e., not
returned by the corresponding endpoints). Default: `false`"
[
nm
description
&
[
default-value
&
{
:as
options
}]]
{
:pre
[(
symbol?
nm
)
(
string?
description
)]}
(
let
[
setting-key
(
keyword
nm
)]
`
(
defn
~
nm
~
description
{
::is-setting?
true
::default-value
~
default-value
}
{
::is-setting?
true
::default-value
~
default-value
::options
~
options
}
([]
(
or
(
get
~
setting-key
)
(
get-from-env-var
~
setting-key
)
...
...
@@ -161,13 +167,15 @@
[(
k/table
:setting
)])
(
defn-
settings-list
"Return a list of all Settings (as created with `defsetting`)."
"Return a list of all Settings (as created with `defsetting`).
This excludes Settings created with the option `:internal`."
[]
(
->>
(
all-ns
)
(
mapcat
ns-interns
)
vals
(
map
meta
)
(
filter
::is-setting?
)
(
filter
(
complement
(
u/rpartial
get-in
[
::options
:internal
])))
; filter out :internal Settings
(
map
(
fn
[{
k
:name
desc
:doc
default
::default-value
}]
{
:key
(
keyword
k
)
:description
desc
...
...
This diff is collapsed.
Click to expand it.
src/metabase/task/sync_databases.clj
+
7
−
7
View file @
da2d0f39
...
...
@@ -3,11 +3,12 @@
[
clojurewerkz.quartzite.jobs
:as
jobs
]
[
clojurewerkz.quartzite.triggers
:as
triggers
]
[
clojurewerkz.quartzite.schedule.cron
:as
cron
]
[
metabase.config
:as
config
]
[
metabase.db
:as
db
]
[
metabase.driver
:as
driver
]
[
metabase.models.database
:refer
[
Database
]]
[
metabase.task
:as
task
]))
(
metabase
[
config
:as
config
]
[
core
:refer
[
sample-dataset-id
]]
[
db
:as
db
]
[
driver
:as
driver
]
[
task
:as
task
])
[
metabase.models.database
:refer
[
Database
]]))
(
def
sync-databases-job-key
"metabase.task.sync-databases.job"
)
(
def
sync-databases-trigger-key
"metabase.task.sync-databases.trigger"
)
...
...
@@ -16,11 +17,10 @@
(
defonce
^
:private
sync-databases-trigger
(
atom
nil
))
;; simple job which looks up all databases and runs a sync on them
;; TODO - skip the sample dataset?
(
jobs/defjob
SyncDatabases
[
ctx
]
(
dorun
(
for
[
database
(
db/sel
:many
Database
)]
(
for
[
database
(
db/sel
:many
Database
,
:id
[
not=
(
some->
(
sample-dataset-id
)
Integer/parseInt
)])]
; skip Sample Dataset DB
(
try
;; NOTE: this happens synchronously for now to avoid excessive load if there are lots of databases
(
driver/sync-database!
database
)
...
...
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