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
6abcb4a9
Commit
6abcb4a9
authored
9 years ago
by
Allen Gilliland
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into sample_dataset_loading
parents
2cd84a5d
0af435c1
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/core.clj
+30
-5
30 additions, 5 deletions
src/metabase/core.clj
src/metabase/db.clj
+27
-17
27 additions, 17 deletions
src/metabase/db.clj
with
57 additions
and
22 deletions
src/metabase/core.clj
+
30
−
5
View file @
6abcb4a9
...
...
@@ -20,7 +20,8 @@
[
routes
:as
routes
]
[
sample-data
:as
sample-data
]
[
setup
:as
setup
]
[
task
:as
task
])
[
task
:as
task
]
[
util
:as
u
])
(
metabase.models
[
setting
:refer
[
defsetting
]]
[
database
:refer
[
Database
]]
[
user
:refer
[
User
]])))
...
...
@@ -67,6 +68,10 @@
wrap-session
; reads in current HTTP session and sets :session/key
wrap-gzip
))
; GZIP response if client can handle it
;;; ## ---------------------------------------- LIFECYCLE ----------------------------------------
(
defn-
-init-create-setup-token
"Create and set a new setup token, and open the setup URL on the user's system."
[]
...
...
@@ -127,7 +132,8 @@
true
)
;; ## Jetty (Web) Server
;;; ## ---------------------------------------- Jetty (Web) Server ----------------------------------------
(
def
^
:private
jetty-instance
(
atom
nil
))
...
...
@@ -157,9 +163,10 @@
(
reset!
jetty-instance
nil
)))
(
defn
-main
"Launch Metabase in standalone mode."
[
&
args
]
;;; ## ---------------------------------------- App Main ----------------------------------------
(
defn-
start-normally
[]
(
log/info
"Starting Metabase in STANDALONE mode"
)
(
try
;; run our initialization process
...
...
@@ -169,3 +176,21 @@
(
catch
Exception
e
(
.printStackTrace
e
)
(
log/error
"Metabase Initialization FAILED: "
(
.getMessage
e
)))))
(
defn-
run-cmd
[
cmd
&
args
]
(
let
[
cmd->fn
{
:migrate
(
fn
[
direction
]
(
db/migrate
(
keyword
direction
)))}]
(
if-let
[
f
(
cmd->fn
cmd
)]
(
do
(
apply
f
args
)
(
println
"Success."
)
(
System/exit
0
))
(
do
(
println
"Unrecognized command:"
(
name
cmd
))
(
println
"Valid commands are:\n"
(
u/pprint-to-str
(
map
name
(
keys
cmd->fn
))))
(
System/exit
1
)))))
(
defn
-main
"Launch Metabase in standalone mode."
[
&
[
cmd
&
args
]]
(
if
cmd
(
apply
run-cmd
(
keyword
cmd
)
args
)
; run a command like `java -jar metabase.jar migrate release-locks` or `lein run migrate release-locks`
(
start-normally
)))
; with no command line args just start Metabase normally
This diff is collapsed.
Click to expand it.
src/metabase/db.clj
+
27
−
17
View file @
6abcb4a9
...
...
@@ -64,21 +64,31 @@
"migrations/liquibase.json"
)
(
defn
migrate
"Migrate the database `:up`, `:down`, or `:print`."
[
jdbc-connection-details
direction
]
(
try
(
jdbc/with-db-transaction
[
conn
jdbc-connection-details
]
(
let
[
^
Database
database
(
->
(
DatabaseFactory/getInstance
)
(
.findCorrectDatabaseImplementation
(
JdbcConnection.
(
jdbc/get-connection
conn
))))
^
Liquibase
liquibase
(
Liquibase.
changelog-file
(
ClassLoaderResourceAccessor.
)
database
)]
(
case
direction
:up
(
.update
liquibase
""
)
:down
(
.rollback
liquibase
10000
""
)
:print
(
let
[
writer
(
StringWriter.
)]
(
.update
liquibase
""
writer
)
(
.toString
writer
)))))
(
catch
Throwable
e
(
throw
(
DatabaseException.
e
)))))
"Migrate the database:
* `:up` - Migrate up
* `:down` - Rollback *all* migrations
* `:print` - Just print the SQL for running the migrations, don't actually run them.
* `:release-locks` - Manually release migration locks left by an earlier failed migration.
(This shouldn't be necessary now that we run migrations inside a transaction,
but is available just in case)."
([
direction
]
(
migrate
@
jdbc-connection-details
direction
))
([
jdbc-connection-details
direction
]
(
try
(
jdbc/with-db-transaction
[
conn
jdbc-connection-details
]
(
let
[
^
Database
database
(
->
(
DatabaseFactory/getInstance
)
(
.findCorrectDatabaseImplementation
(
JdbcConnection.
(
jdbc/get-connection
conn
))))
^
Liquibase
liquibase
(
Liquibase.
changelog-file
(
ClassLoaderResourceAccessor.
)
database
)]
(
case
direction
:up
(
.update
liquibase
""
)
:down
(
.rollback
liquibase
10000
""
)
:print
(
let
[
writer
(
StringWriter.
)]
(
.update
liquibase
""
writer
)
(
.toString
writer
))
:release-locks
(
.forceReleaseLocks
liquibase
))))
(
catch
Throwable
e
(
throw
(
DatabaseException.
e
))))))
;; ## SETUP-DB
...
...
@@ -122,10 +132,10 @@
;; Run through our DB migration process and make sure DB is fully prepared
(
if
auto-migrate
(
migrate
@
jdbc-connection-details
:up
)
(
migrate
:up
)
;; if we are not doing auto migrations then print out migration sql for user to run manually
;; then throw an exception to short circuit the setup process and make it clear we can't proceed
(
let
[
sql
(
migrate
@
jdbc-connection-details
:print
)]
(
let
[
sql
(
migrate
:print
)]
(
log/info
(
str
"Database Upgrade Required\n\n"
"NOTICE: Your database requires updates to work with this version of Metabase. "
"Please execute the following sql commands on your database before proceeding.\n\n"
...
...
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