Skip to content
Snippets Groups Projects
Commit 62de6a11 authored by Cam Saül's avatar Cam Saül
Browse files

db/ins -> db/insert! :honey_pot:

parent 1fd6937d
Branches
Tags
No related merge requests found
Showing
with 68 additions and 80 deletions
......@@ -30,7 +30,7 @@
[:as {{:keys [name description public_perms]} :body}]
{name [Required NonEmptyString]
public_perms [Required PublicPerms]}
(->> (db/ins Dashboard
(->> (db/insert! Dashboard
:name name
:description description
:public_perms public_perms
......
......@@ -84,7 +84,7 @@
(boolean is_full_sync))]
(if-not (false? (:valid details-or-error))
;; no error, proceed with creation
(let-500 [new-db (db/ins Database, :name name, :engine engine, :details details-or-error, :is_full_sync is_full_sync)]
(let-500 [new-db (db/insert! Database, :name name, :engine engine, :details details-or-error, :is_full_sync is_full_sync)]
(events/publish-event :database-create new-db))
;; failed to connect, return error
{:status 400
......
......@@ -16,7 +16,7 @@
[:as {{:keys [name icon]} :body}]
{name [Required NonEmptyString]
icon NonEmptyString}
(db/ins Label, :name name, :icon icon))
(db/insert! Label, :name name, :icon icon))
(defendpoint PUT "/:id"
"Update a `Label`. :label:"
......
......@@ -20,7 +20,7 @@
"Generate a new `Session` for a given `User`. Returns the newly generated session id value."
[user-id]
(u/prog1 (str (java.util.UUID/randomUUID))
(db/ins Session
(db/insert! Session
:id <>
:user_id user-id)))
......
......@@ -32,7 +32,7 @@
(@(ns-resolve 'metabase.core 'site-url) request)
;; Now create the user
(let [session-id (str (java.util.UUID/randomUUID))
new-user (db/ins User
new-user (db/insert! User
:email email
:first_name first_name
:last_name last_name
......@@ -46,14 +46,18 @@
(setting/set :anon-tracking-enabled (or allow_tracking "true"))
;; setup database (if needed)
(when (driver/is-engine? engine)
(->> (db/ins Database, :name name, :engine engine, :details details, :is_full_sync (if-not (nil? is_full_sync)
is_full_sync
true))
(->> (db/insert! Database
:name name
:engine engine
:details details
:is_full_sync (if-not (nil? is_full_sync)
is_full_sync
true))
(events/publish-event :database-create)))
;; clear the setup token now, it's no longer needed
(setup/token-clear)
;; then we create a session right away because we want our new user logged in to continue the setup process
(db/ins Session
(db/insert! Session
:id session-id
:user_id (:id new-user))
;; notify that we've got a new user in the system AND that this user logged in
......
......@@ -284,22 +284,6 @@
~@args)))
;; ## INS
(defn ^:deprecated ins
"Wrapper around `korma.core/insert` that renames the `:scope_identity()` keyword in output to `:id`
and automatically passes &rest KWARGS to `korma.core/values`.
Returns a newly created object by calling `sel`."
[entity & {:as kwargs}]
(let [vals (models/do-pre-insert entity kwargs)
;; take database-specific keys returned from a jdbc insert and map them to :id
{:keys [id]} (set/rename-keys (k/insert entity (k/values vals))
{(keyword "scope_identity()") :id
:generated_key :id})]
(some-> id entity models/post-insert)))
;;; +------------------------------------------------------------------------------------------------------------------------+
;;; | NEW HONEY-SQL BASED DB UTIL FUNCTIONS |
......
......@@ -205,12 +205,12 @@
;; add this table to the set of tables we've processed
(swap! processed-tables conj {:schema table-schema, :name table-name})
;; create the RawTable
(let [{raw-table-id :id} (db/ins RawTable
:database_id database-id
:schema table-schema
:name table-name
:details {}
:active true)]
(let [{raw-table-id :id} (db/insert! RawTable
:database_id database-id
:schema table-schema
:name table-name
:details {}
:active true)]
;; update the Table and link it with the RawTable
(k/update Table
(k/set-fields {:raw_table_id raw-table-id})
......@@ -226,12 +226,12 @@
(k/set-fields {:visibility_type "retired"})
(k/where {:id field-id}))
;; normal unmigrated field, so lets use it
(let [{raw-column-id :id} (db/ins RawColumn
:raw_table_id raw-table-id
:name column-name
:is_pk (= :id (:special_type field))
:details {:base-type (:base_type field)}
:active true)]
(let [{raw-column-id :id} (db/insert! RawColumn
:raw_table_id raw-table-id
:name column-name
:is_pk (= :id (:special_type field))
:details {:base-type (:base_type field)}
:active true)]
;; update the Field and link it with the RawColumn
(k/update Field
(k/set-fields {:raw_column_id raw-column-id
......
......@@ -117,7 +117,7 @@
"card" (process-card-activity topic object)
"dashboard" (process-dashboard-activity topic object)
"install" (when-not (db/exists? Activity)
(db/ins Activity, :topic "install", :model "install"))
(db/insert! Activity, :topic "install", :model "install"))
"metric" (process-metric-activity topic object)
"pulse" (process-pulse-activity topic object)
"segment" (process-segment-activity topic object)
......
......@@ -24,7 +24,7 @@
"Simple base function for recording a view of a given `model` and `model-id` by a certain `user`."
[model model-id user-id]
;; TODO - we probably want a little code that prunes old entries so that this doesn't get too big
(db/ins ViewLog
(db/insert! ViewLog
:user_id user-id
:model model
:model_id model-id))
......
......@@ -62,7 +62,7 @@
[& {:keys [topic object details-fn database-id table-id user-id model model-id]}]
{:pre [(keyword? topic)]}
(let [object (or object {})]
(db/ins Activity
(db/insert! Activity
:topic topic
:user_id (or user-id (events/object->user-id object))
:model (or model (events/topic->model topic))
......
......@@ -112,13 +112,13 @@
(let [{:keys [sizeX sizeY row col series]} (merge {:sizeX 2, :sizeY 2, :series []}
dashboard-card)]
(kdb/transaction
(let [{:keys [id] :as dashboard-card} (db/ins DashboardCard
:dashboard_id dashboard_id
:card_id card_id
:sizeX sizeX
:sizeY sizeY
:row row
:col col)]
(let [{:keys [id] :as dashboard-card} (db/insert! DashboardCard
:dashboard_id dashboard_id
:card_id card_id
:sizeX sizeX
:sizeY sizeY
:row row
:col col)]
;; add series to the DashboardCard
(update-dashboard-card-series dashboard-card series)
;; return the full DashboardCard (and record our create event)
......
......@@ -234,7 +234,7 @@
{:pre [(integer? table-id)
(string? field-name)
(contains? base-types base-type)]}
(db/ins Field
(db/insert! Field
:table_id table-id
:raw_column_id raw-column-id
:name field-name
......
......@@ -43,7 +43,7 @@
[{field-id :id, field-name :name, :as field} & [human-readable-values]]
{:pre [(integer? field-id)]}
(log/debug (format "Creating FieldValues for Field %s..." (or field-name field-id))) ; use field name if available
(db/ins FieldValues
(db/insert! FieldValues
:field_id field-id
:values ((resolve 'metabase.db.metadata-queries/field-distinct-values) field)
:human_readable_values human-readable-values))
......@@ -76,7 +76,7 @@
(coll? values)]}
(if-let [field-values (db/sel :one FieldValues :field_id field-id)]
(db/update! FieldValues (:id field-values), :values values)
(db/ins FieldValues :field_id field-id, :values values)))
(db/insert! FieldValues :field_id field-id, :values values)))
(defn clear-field-values
"Remove the `FieldValues` for FIELD-ID."
......
......@@ -75,13 +75,13 @@
(string? metric-name)
(integer? creator-id)
(map? definition)]}
(let [metric (db/ins Metric
:table_id table-id
:creator_id creator-id
:name metric-name
:description description
:is_active true
:definition definition)]
(let [metric (db/insert! Metric
:table_id table-id
:creator_id creator-id
:name metric-name
:description description
:is_active true
:definition definition)]
(-> (events/publish-event :metric-create metric)
(hydrate :creator))))
......
......@@ -162,7 +162,7 @@
(coll? channels)
(every? map? channels)]}
(kdb/transaction
(let [{:keys [id] :as pulse} (db/ins Pulse
(let [{:keys [id] :as pulse} (db/insert! Pulse
:creator_id creator-id
:name pulse-name)]
;; add card-ids to the Pulse
......
......@@ -232,18 +232,18 @@
(coll? recipients)
(every? map? recipients)]}
(let [recipients-by-type (group-by integer? (filter identity (map #(or (:id %) (:email %)) recipients)))
{:keys [id]} (db/ins PulseChannel
:pulse_id pulse_id
:channel_type channel_type
:details (cond-> details
(supports-recipients? channel_type) (assoc :emails (get recipients-by-type false)))
:schedule_type schedule_type
:schedule_hour (when (not= schedule_type :hourly)
schedule_hour)
:schedule_day (when (contains? #{:weekly :monthly} schedule_type)
schedule_day)
:schedule_frame (when (= schedule_type :monthly)
schedule_frame))]
{:keys [id]} (db/insert! PulseChannel
:pulse_id pulse_id
:channel_type channel_type
:details (cond-> details
(supports-recipients? channel_type) (assoc :emails (get recipients-by-type false)))
:schedule_type schedule_type
:schedule_hour (when (not= schedule_type :hourly)
schedule_hour)
:schedule_day (when (contains? #{:weekly :monthly} schedule_type)
schedule_day)
:schedule_frame (when (= schedule_type :monthly)
schedule_frame))]
(when (and (supports-recipients? channel_type) (seq (get recipients-by-type true)))
(update-recipients! id (get recipients-by-type true)))
;; return the id of our newly created channel
......
......@@ -129,7 +129,7 @@
object (serialize-instance entity id object)]
;; make sure we still have a map after calling out serialization function
(assert (map? object))
(db/ins Revision
(db/insert! Revision
:model (:name entity)
:model_id id
:user_id user-id
......@@ -155,7 +155,7 @@
(revert-to-revision entity id user-id serialized-instance)
;; Push a new revision to record this change
(let [last-revision (db/sel :one Revision, :model (:name entity), :model_id id, (k/order :id :DESC))
new-revision (db/ins Revision
new-revision (db/insert! Revision
:model (:name entity)
:model_id id
:user_id user-id
......
......@@ -61,7 +61,7 @@
(string? segment-name)
(integer? creator-id)
(map? definition)]}
(let [segment (db/ins Segment
(let [segment (db/insert! Segment
:table_id table-id
:creator_id creator-id
:name segment-name
......
......@@ -114,7 +114,7 @@
(defn create-table
"Create `Table` with the data from TABLE-DEF."
[database-id {schema-name :schema, table-name :name, raw-table-id :raw-table-id, visibility-type :visibility-type}]
(db/ins Table
(db/insert! Table
:db_id database-id
:raw_table_id raw-table-id
:schema schema-name
......
......@@ -75,13 +75,13 @@
{:pre [(string? first-name)
(string? last-name)
(string? email-address)]}
(when-let [new-user (db/ins User
:email email-address
(when-let [new-user (db/insert! User
:email email-address
:first_name first-name
:last_name last-name
:password (if (not (nil? password))
password
(str (java.util.UUID/randomUUID))))]
:last_name last-name
:password (if (not (nil? password))
password
(str (java.util.UUID/randomUUID))))]
(when send-welcome
(let [reset-token (set-user-password-reset-token (:id new-user))
;; NOTE: the new user join url is just a password reset with an indicator that this is a first time user
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment