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
e8dec169
Commit
e8dec169
authored
9 years ago
by
Tom Robinson
Browse files
Options
Downloads
Patches
Plain Diff
Refactor connection string parsing, move NonValidatingFactory import to postgres driver
parent
27e6807d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/db.clj
+21
-13
21 additions, 13 deletions
src/metabase/db.clj
src/metabase/driver/postgres.clj
+4
-1
4 additions, 1 deletion
src/metabase/driver/postgres.clj
with
25 additions
and
14 deletions
src/metabase/db.clj
+
21
−
13
View file @
e8dec169
...
...
@@ -3,25 +3,24 @@
(
:require
[
clojure.java.jdbc
:as
jdbc
]
[
clojure.tools.logging
:as
log
]
(
clojure
[
set
:as
set
]
[
string
:as
s
])
[
string
:as
s
]
[
walk
:as
walk
])
[
environ.core
:refer
[
env
]]
(
korma
[
core
:as
k
]
[
db
:as
kdb
])
[
medley.core
:as
m
]
[
ring.util.codec
:as
codec
]
[
metabase.config
:as
config
]
[
metabase.db.internal
:as
i
]
[
metabase.models.interface
:as
models
]
[
metabase.util
:as
u
]
[
ring.util.codec
:as
codec
]
[
clojure.walk
:as
walk
])
[
metabase.util
:as
u
])
(
:import
java.io.StringWriter
java.sql.Connection
liquibase.Liquibase
(
liquibase.database
DatabaseFactory
Database
)
liquibase.database.jvm.JdbcConnection
liquibase.exception.DatabaseException
liquibase.resource.ClassLoaderResourceAccessor
org.postgresql.ssl.NonValidatingFactory
))
liquibase.resource.ClassLoaderResourceAccessor
))
;; ## DB FILE, JDBC/KORMA DEFINITONS
...
...
@@ -41,16 +40,25 @@
;; if we don't have an absolute path then make sure we start from "user.dir"
[(
System/getProperty
"user.dir"
)
"/"
db-file-name
options
]))))))
(
defn
parse-connection-string
"Parse a DB connection URI like `postgres://cam@localhost.com:5432/cams_cool_db?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory` and return a broken-out map."
[
uri
]
(
when-let
[[
_
protocol
user
pass
host
port
db
query
]
(
re-matches
#
"^([^:/@]+)://([^:/@]+)(?::([^:@]+))?@([^:@]+)(?::(\d+))?/([^/?]+)(?:\?(.*))?$"
uri
)]
(
merge
{
:type
(
keyword
protocol
)
:user
user
:password
pass
:host
host
:port
port
:dbname
db
}
(
some->
query
codec/form-decode
walk/keywordize-keys
))))
(
def
^
:private
db-connection-details
"Connection details that can be used when pretending the Metabase DB is itself a `Database`
(e.g., to use the Generic SQL driver functions on the Metabase DB itself)."
(
delay
(
or
(
some->>
(
config/config-str
:mb-db-connection-uri
)
(
re-matches
#
"^([^:/@]+)://([^:/@]+)(?::([^:@]+))?@([^:@]+)(?::(\d+))?/([^/?]+)(?:\?(.*))?$"
)
rest
(
#
(
merge
(
zipmap
[
:type
:user
:password
:host
:port
:dbname
]
%
)
(
some->>
(
last
%
)
codec/form-decode
walk/keywordize-keys
)))
(
#
(
update-in
%
[
:type
]
keyword
)))
(
delay
(
or
(
when-let
[
uri
(
config/config-str
:mb-db-connection-uri
)]
(
parse-connection-string
uri
))
(
case
(
config/config-kw
:mb-db-type
)
:h2
{
:type
:h2
:db
@
db-file
}
...
...
This diff is collapsed.
Click to expand it.
src/metabase/driver/postgres.clj
+
4
−
1
View file @
e8dec169
...
...
@@ -16,7 +16,10 @@
ISyncDriverSpecificSyncField
]])
[
metabase.driver.generic-sql
:as
generic-sql
]
(
metabase.driver.generic-sql
[
interface
:refer
[
ISqlDriverDatabaseSpecific
]]
[
util
:refer
[
with-jdbc-metadata
]])))
[
util
:refer
[
with-jdbc-metadata
]]))
; This is necessary for when NonValidatingFactory is passed in the sslfactory connection string argument,
; e.x. when connecting to a Heroku Postgres database from outside of Heroku.
(
:import
org.postgresql.ssl.NonValidatingFactory
))
(
def
^
:private
^
:const
column->base-type
"Map of Postgres column types -> Field base types.
...
...
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