         tenant-migrations (:tenants migrations)
         tenant-manager-migrations (:tenant-manager migrations)
 
-        tenant-manager-db {:connection-uri (get-in system [:config :db :uri])}]
+        tenant-manager-db {:connection-uri (get-in system [:config :db :uri])}
+        tenant-connection-uri-fn #(aes/decrypt (get-in system [:config :config :encryption-key])
+                                       (:db_uri %))]
     (cond
       (= arg :tenant-manager)
       (do-rollback (ragtime-jdbc/sql-database tenant-manager-db)

                   (count tenant-manager-migrations))

      (number? arg)
      (rollback-tenants tenant-manager-db
                        (:tenants migrations)
                        arg)

      :else
      (rollback-tenants tenant-manager-db
                        (:tenants migrations)
                        (count (:tenants migrations))))))

                         amount-or-id))


(defn rollback-tenants [db connection-uri-fn migrations amount-or-id]
  (doseq [tenant (all-tenants db)]
    (do-rollback (ragtime-jdbc/sql-database {:connection-uri (connection-uri-fn tenant)})
                 migrations
                 amount-or-id)))

