Skip to content
Snippets Groups Projects
Commit ec720f77 authored by Allen Gilliland's avatar Allen Gilliland
Browse files

Merge pull request #129 from metabase/ag-fix-uberjar-migrations

Fix uberjar so that migrations run
parents a35989c2 dc734874
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,6 @@
[org.clojure/tools.macro "0.1.5"] ; tools for writing macros
[org.clojure/tools.trace "0.7.8"] ; "tracing macros/fns to help you see what your code is doing"
[cheshire "5.4.0"] ; fast JSON encoding (used by Ring JSON middleware)
[clj-http "1.0.1"] ; HTTP Client
[clj-time "0.9.0"] ; library for dealing with date/time
[com.cemerick/friend "0.2.1"] ; auth library
[com.h2database/h2 "1.4.186"] ; embedded SQL database
......@@ -32,6 +31,7 @@
com.sun.jmx/jmxri]]
[marginalia "0.8.0"] ; for documentation
[medley "0.5.5"] ; lightweight lib of useful functions
[org.apache.httpcomponents/httpclient "4.3.5"]
[org.liquibase/liquibase-core "3.3.2"] ; migration management (Java lib)
[org.slf4j/slf4j-log4j12 "1.7.10"]
[org.yaml/snakeyaml "1.15"] ; YAML parser (required by liquibase)
......@@ -48,13 +48,16 @@
[lein-ring "0.8.10"]] ; start the HTTP server with 'lein ring server'
:java-source-paths ["src/java"]
:main ^:skip-aot metabase.core
:manifest {"Liquibase-Package" "liquibase.change,liquibase.changelog,liquibase.database,liquibase.parser,liquibase.precondition,liquibase.datatype,liquibase.serializer,liquibase.sqlgenerator,liquibase.executor,liquibase.snapshot,liquibase.logging,liquibase.diff,liquibase.structure,liquibase.structurecompare,liquibase.lockservice,liquibase.sdk,liquibase.ext"}
:target-path "target/%s"
;; :jar-exclusions [#"\.java"] Circle CI doesn't like regexes because it's using the EDN reader and is retarded
:ring {:handler metabase.core/app}
:ring {:handler metabase.core/app
:init metabase.core/init}
:eastwood {:exclude-namespaces [:test-paths]
:add-linters [:unused-private-vars]
:exclude-linters [:constant-test]} ; korma macros generate some formats with if statements that are always logically true or false
:profiles {:dev {:dependencies [[expectations "2.0.16"] ; unit tests
:profiles {:dev {:dependencies [[clj-http "1.0.1"] ; HTTP Client
[expectations "2.0.16"] ; unit tests
[ring/ring-mock "0.2.0"]]
:jvm-opts ["-Dlogfile.path=target/log -XX:PermSize=64m -XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC"]}
:uberjar {:aot :all
......
......@@ -15,4 +15,5 @@ log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d [%t] %-5p%c - %m%n
# customizations to logging by package
log4j.logger.metabase=DEBUG
\ No newline at end of file
log4j.logger.metabase=DEBUG
log4j.logger.liquibase=WARN
\ No newline at end of file
package com.metabase.corvus.migrations;
import java.io.FileWriter;
import java.io.StringWriter;
import java.sql.SQLException;
import liquibase.Liquibase;
import liquibase.database.DatabaseFactory;
......@@ -53,11 +54,13 @@ public class LiquibaseMigrations {
}
}
public static final void genSqlDatabase(java.sql.Connection dbConnection) throws Exception {
public static final String genSqlDatabase(java.sql.Connection dbConnection) throws Exception {
try {
StringWriter strw = new StringWriter();
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(dbConnection));
Liquibase liquibase = new Liquibase(LIQUIBASE_CHANGELOG, new ClassLoaderResourceAccessor(), database);
liquibase.update("", new FileWriter("/tmp/script.sql"));
liquibase.update("", strw);
return strw.toString();
} catch (Exception e) {
throw new DatabaseException(e);
} finally {
......
......@@ -34,12 +34,25 @@
))
(defn init
"General application initialization function which should be run once at application startup."
[]
(log/info "Metabase Initializing ... ")
;; startup database. validates connection & runs any necessary migrations
;; TODO - allow for env configuration regarding migrations process
(db/setup true)
(log/info "Metabase Initialization COMPLETE"))
(defn -main
"Launch Metabase in standalone mode."
[& args]
(log/info "Launching Metabase in STANDALONE mode")
;; TODO - startup database. validates connection & runs any necessary migrations
;; run our main initialization function
(init)
;; startup webserver
;; TODO - allow for env configuration
......
......@@ -10,6 +10,7 @@
[metabase.db.internal :refer :all]
[metabase.util :as u]))
(declare post-select)
(def db-file
......@@ -17,10 +18,11 @@
(delay
(str "file:" (or (:database-file env)
(str (System/getProperty "user.dir") "/" (:database-file app-defaults)))
";AUTO_SERVER=TRUE")))
";AUTO_SERVER=TRUE;MV_STORE=FALSE")))
;; Tell the DB to open an "AUTO_SERVER" connection so multiple processes can connect to it (e.g. web server + REPL)
;; Do this by appending `;AUTO_SERVER=TRUE` to the JDBC URL (see http://h2database.com/html/features.html#auto_mixed_mode)
(defn- setup-db
"Setup Korma default DB."
[]
......@@ -30,15 +32,34 @@
:fields str/upper-case}}))]
(default-connection db)))
(defn migrate
"Migrate the database `:up` or `:down.`"
"Migrate the database `:up`, `:down`, or `:print`."
[direction]
(setup-db)
(let [conn (jdbc/get-connection {:subprotocol "h2"
:subname @db-file})]
(case direction
:up (com.metabase.corvus.migrations.LiquibaseMigrations/setupDatabase conn)
:down (com.metabase.corvus.migrations.LiquibaseMigrations/teardownDatabase conn))))
:up (com.metabase.corvus.migrations.LiquibaseMigrations/setupDatabase conn)
:down (com.metabase.corvus.migrations.LiquibaseMigrations/teardownDatabase conn)
:print (let [sql (com.metabase.corvus.migrations.LiquibaseMigrations/genSqlDatabase conn)]
(log/info (str "Database migrations 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"
sql
"\n\n"
"Once you're database is updated try running the application again.\n"))))))
(defn setup
"Do general perparation of database by validating that we can connect.
Caller can specify if we should run any pending database migrations."
[auto-migrate]
;; TODO - test db connection and throw exception if we have trouble connecting
(if auto-migrate
(migrate :up)
;; if we are not doing auto migrations then return migration sql for user to run manually
(migrate :print)))
;;; # UTILITY FUNCTIONS
......
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment