   GlobalSecondaryIndexDescription
   (as-map [d] {:name       (keyword (.getIndexName d))
                :size       (.getIndexSizeBytes d)
-               :throughput (as-map (.getProvisionedThroughput d))
                :item-count (.getItemCount d)
                :key-schema (as-map (.getKeySchema d))
-               :projection (as-map (.getProjection d))})
+               :projection (as-map (.getProjection d))
+               :throughput (as-map (.getProvisionedThroughput d))})
 
   ProvisionedThroughputDescription
   (as-map [d] {:read                (.getReadCapacityUnits d)

            (let [pr (Projection.)
                  ptype (if (coll?* projection) :include projection)]
              (.setProjectionType pr (utils/enum ptype))
              (when (= ptype :include) (.setNonKeyAttributes pr (mapv name projection)))
              pr))))
      indexes)))

(defn- global-indexes
  "[{:name _ :hash-keydef _ :range-keydef _ :throughput _ :projection _} ...] gindexes -> [GlobalSecondaryIndex ...]"
  [gindexes]
  (if gindexes
    (mapv
      (fn [{index-name :name
            :keys      [hash-keydef range-keydef throughput projection]
            :or        {projection :all}
            :as        index}]
        (assert (and index-name hash-keydef projection throughput)
                (str "Malformed index: " index))
        (doto (GlobalSecondaryIndex.)
          (.setIndexName (name index-name))
          (.setKeySchema (key-schema hash-keydef range-keydef))
          (.setProvisionedThroughput (provisioned-throughput throughput))
          (.setProjection
            (let [pr (Projection.)
                  ptype (if (coll?* projection) :include projection)]
              (.setProjectionType pr (utils/enum ptype))
              (when (= ptype :include) (.setNonKeyAttributes pr (mapv name projection)))
              pr))))
      gindexes)))

(defn create-table
  "Creates a table with options:
    hash-keydef   - [<name> <#{:s :n :ss :ns :b :bs}>].
    :range-keydef - [<name> <#{:s :n :ss :ns :b :bs}>].
    :throughput   - {:read <units> :write <units>}.
    :indexes      - [{:name _ :range-keydef _
                      :projection #{:all :keys-only [<attr> ...]}}].
    :block?       - Block for table to actually be active?"
  [creds table-name hash-keydef
   & [{:keys [range-keydef throughput indexes gindexes block?]
       :or   {throughput {:read 1 :write 1}}}]]
  (let [result
        (as-map
         (.createTable (db-client creds)
           (doto-cond [_ (CreateTableRequest.)]
             :always (.setTableName (name table-name))
             :always (.setKeySchema (key-schema hash-keydef range-keydef))
             :always (.setProvisionedThroughput (provisioned-throughput throughput))
             :always (.setAttributeDefinitions  (keydefs hash-keydef range-keydef indexes gindexes))
             :always (.setLocalSecondaryIndexes (local-indexes hash-keydef indexes))
             gindexes (.setGlobalSecondaryIndexes (global-indexes gindexes)))))]
    (if-not block? result @(table-status-watch creds table-name :creating))))

(comment (time (create-table mc "delete-me7" [:id :s] {:block? true})))

    (.setWriteCapacityUnits (long write-units))))

(defn- keydefs "[<name> <type>] defs -> [AttributeDefinition ...]"
  [hash-keydef range-keydef lsindexes gsindexes]
  (let [defs (->> (conj [] hash-keydef range-keydef)
                  (concat (mapv :range-keydef lsindexes))
                  (concat (mapv :hash-keydef  gsindexes))
                  (concat (mapv :range-keydef gsindexes))
                  (filterv identity))]
    (mapv
     (fn [[key-name key-type :as def]]
