Skip to content
Snippets Groups Projects
Unverified Commit 8a337d08 authored by Mark Bastian's avatar Mark Bastian Committed by GitHub
Browse files

Fixing case where no fields in a table cause a failure (#30036)

Fixed missing seed {} in a reduce and added tests.
parent 3812b7c2
No related branches found
No related tags found
No related merge requests found
......@@ -181,6 +181,7 @@
(if-some [enums (field->pseudo-enums table field)]
(assoc acc field-name enums)
acc))
{}
fields)
columns (vec
(for [{column-name :name :keys [database_required database_type]} fields]
......
(ns metabase.metabot.metabot-util-test
(:require
[clojure.test :refer :all]
[metabase.db.query :as mdb.query]
[metabase.lib.native :as lib-native]
[metabase.metabot-test :as metabot-test]
[metabase.metabot.settings :as metabot-settings]
[metabase.metabot.util :as metabot-util]
[metabase.models :refer [Card Database]]
[metabase.query-processor :as qp]
[metabase.test :as mt]
[metabase.util :as u]
[toucan2.core :as t2]))
[clojure.string :as str]
[clojure.test :refer :all]
[metabase.db.query :as mdb.query]
[metabase.lib.native :as lib-native]
[metabase.metabot-test :as metabot-test]
[metabase.metabot.settings :as metabot-settings]
[metabase.metabot.util :as metabot-util]
[metabase.models :refer [Card Database]]
[metabase.query-processor :as qp]
[metabase.test :as mt]
[metabase.util :as u]
[toucan2.core :as t2]))
(deftest normalize-name-test
(testing "Testing basic examples of how normalize-name should work"
......@@ -175,3 +176,16 @@
(lib-native/template-tags inner_query)
(fn [m] (update m :id str)))}})]
(is (some? (seq (get-in results [:data :rows]))))))))))
(deftest create-database-ddl-test
(testing "Ensure the generated pseudo-ddl contains the expected tables and enums."
(mt/dataset sample-dataset
(let [{:keys [create_database_ddl]} (metabot-util/denormalize-database {:id (mt/id)})]
(is (str/includes? create_database_ddl "create type PRODUCTS_CATEGORY_t as enum 'Doohickey', 'Gadget', 'Gizmo', 'Widget';"))
(is (str/includes? create_database_ddl "create type PEOPLE_STATE_t as enum 'AK', 'AL', 'AR', 'AZ', 'CA', 'CO', 'CT',"))
(is (str/includes? create_database_ddl "create type PEOPLE_SOURCE_t as enum 'Affiliate', 'Facebook', 'Google', 'Organic', 'Twitter';"))
(is (str/includes? create_database_ddl "create type REVIEWS_RATING_t as enum '1', '2', '3', '4', '5';"))
(is (str/includes? create_database_ddl "CREATE TABLE \"PRODUCTS\" ("))
(is (str/includes? create_database_ddl "CREATE TABLE \"ORDERS\" ("))
(is (str/includes? create_database_ddl "CREATE TABLE \"PEOPLE\" ("))
(is (str/includes? create_database_ddl "CREATE TABLE \"REVIEWS\" ("))))))
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