Skip to content

Commit

Permalink
Fix Schema/Table synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonrafael committed Jun 26, 2023
1 parent 3ae37e4 commit 8d368f4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
\#*\#
.\#*
/target
/.nrepl-port
/.nrepl-port
.cpcache
4 changes: 2 additions & 2 deletions resources/metabase-plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
info:
name: Metabase DB2 Driver
name: Metabase IBM DB2 for LUW Driver
version: 1.0.2
description: Allows Metabase to connect to DB2 for LUW databases.
driver:
name: db2
display-name: DB2
display-name: DB2 for LUW
lazy-load: true
parent: sql-jdbc
connection-properties:
Expand Down
19 changes: 17 additions & 2 deletions src/metabase/driver/db2.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns metabase.driver.db2
"Driver for DB2 for LUW databases."
(:require [clojure.java.jdbc :as jdbc]
[clojure.set :as set]
[clojure.string :as str]
[clj-time
[coerce :as tcoerce]
Expand All @@ -26,14 +27,15 @@
[date-2 :as du]
[honey-sql-2 :as h2x]
[ssh :as ssh]
[log :as log]]
[log :as log]
[i18n :refer [trs]]]
[metabase.driver.sql :as sql]
[schema.core :as s])
(:import [java.sql ResultSet Types]
java.util.Date)
(:import java.sql.Time
[java.util Date UUID])
(:import (java.sql ResultSet Time Timestamp Types)
(:import (java.sql ResultSet ResultSetMetaData Time Timestamp Types)
(java.util Calendar Date TimeZone)
(java.time Instant LocalDateTime OffsetDateTime OffsetTime ZonedDateTime LocalDate LocalTime)
(java.time.temporal Temporal)
Expand Down Expand Up @@ -345,3 +347,16 @@

(defmethod sql-jdbc.execute/set-timezone-sql :db2 [_]
"SET SESSION TIME ZONE = %s")

(defn- materialized-views
"Fetch the Materialized Views DB2 for LUW"
[database]
(try (set (jdbc/query (sql-jdbc.conn/db->pooled-connection-spec database)
["SELECT TABSCHEMA AS \"schema\", TABNAME AS \"name\", REMARKS AS \"description\" FROM SYSCAT.TABLES ORDER BY 1, 2"]))
(catch Throwable e
(log/error e (trs "Failed to fetch materialized views for DB2 for LUW")))))

(defmethod driver/describe-database :db2
[driver database]
(-> ((get-method driver/describe-database :sql-jdbc) driver database)
(update :tables set/union (materialized-views database))))

0 comments on commit 8d368f4

Please sign in to comment.