   (-> (get-unrestricted-congregation state cong-id)
       (apply-user-permissions user-id)))
 
-(defn use-schema [conn state cong-id] ; TODO: create a better helper?
-  (let [cong (get-unrestricted-congregation state cong-id)
-        schema (:congregation/schema-name cong)]
-    (db/use-tenant-schema conn schema)))
-
-(defn create-congregation! [conn name]
-  (let [id (UUID/randomUUID)
-        master-schema (:database-schema config/env)
-        tenant-schema (str master-schema
-                           "_"
-                           (str/replace (str id) "-" ""))]
-    (assert (not (contains? (set (db/get-schemas conn))
-                            tenant-schema))
-            {:schema-name tenant-schema})
-    (event-store/save! conn id 0 [(assoc (events/defaults)
-                                         :event/type :congregation.event/congregation-created
-                                         :congregation/id id
-                                         :congregation/name name
-                                         :congregation/schema-name tenant-schema)])
-    (-> (db/tenant-schema tenant-schema master-schema)
-        (.migrate))
-    (log/info "Congregation created:" id)
-    id))
-
 
 ;;;; Write model
 
 (defn- write-model [congregation event]
   (-> congregation
       (update-congregation event)))
+
+
+;;;; Command handlers
 
 (defmulti ^:private command-handler (fn [command _congregation _injections]
                                       (:command/type command)))

    (event-store/save! conn stream-id (count old-events) new-events)))


;;;; User access

(defn get-users [state cong-id]

      (update-in [::congregations (:congregation/id event)] update-congregation event)
      (update-permissions event)))


;;;; Queries

(defn get-unrestricted-congregations [state]
  (vals (::congregations state)))

