     :db/valueType :db.type/boolean
     :db/cardinality :db.cardinality/one
     :db.install/_attribute :db.part/db}
-    ;; Instance attributes
-    {:db/id (d/tempid :db.part/db)
-     :db/ident :instance/task-id
-     :db/valueType :db.type/string
-     :db/unique :db.unique/identity
-     :db/cardinality :db.cardinality/one
-     :db.install/_attribute :db.part/db}
-    {:db/id (d/tempid :db.part/db)
-     :db/ident :instance/progress
-     :db/doc "represents the progress of the instance, from 0 to 100"
-     :db/valueType :db.type/long
-     :db/cardinality :db.cardinality/one
-     :db.install/_attribute :db.part/db}
-    {:db/id (d/tempid :db.part/db)
-     :db/ident :instance/backfilled?
-;;;   In a future version, datomic adds these schema values, leaving the info here when that occurs
-;;     :schema/deprecated true
-;;     :schema/deprecated-because "The concept of backfill was meant to allow Cook to schedule jobs out of order
-;;                                 temporarily but treat the jobs as opportunistic and upgrade the jobs out of
-;;                                 backfill later once the scheduling order had been corrected. Unfortunately,
-;;                                 this causes a lot of unexpected behavior (jobs being preempted out of priority
-;;                                 order) and lots of bugs (it is hard to correctly update jobs). The concept of
-;;                                 backfill is not worth the added problems and so it is being removed."
-     :db/doc "DEPRECATED: If this is true, then this instance should be preempted first regardless of priority. It's okay to upgrade an instance to be non-backfilled after a while."
-     :db/valueType :db.type/boolean
-     :db/cardinality :db.cardinality/one
-     :db.install/_attribute :db.part/db}
-    {:db/id (d/tempid :db.part/db)
-     :db/ident :instance/hostname
-     :db/valueType :db.type/string
-     :db/cardinality :db.cardinality/one
-     :db.install/_attribute :db.part/db}
-    {:db/id (d/tempid :db.part/db)
-     :db/ident :instance/ports
-     :db/valueType :db.type/long
-     :db/cardinality :db.cardinality/many
-     :db.install/_attribute :db.part/db}
-    {:db/id (d/tempid :db.part/db)
-     :db/ident :instance/executor-id
-     :db/valueType :db.type/string
-     :db/cardinality :db.cardinality/one
-     :db.install/_attribute :db.part/db}
-    {:db/id (d/tempid :db.part/db)
-     :db/ident :instance/slave-id
-     :db/valueType :db.type/string
-     :db/cardinality :db.cardinality/one
-     :db.install/_attribute :db.part/db}
-    {:db/id (d/tempid :db.part/db)
-     :db/ident :instance/status
-     :db/index true
-     :db/valueType :db.type/ref
-     :db/cardinality :db.cardinality/one
-     :db.install/_attribute :db.part/db}
+   ;; Instance attributes
+   {:db/id (d/tempid :db.part/db)
+    :db/ident :instance/task-id
+    :db/valueType :db.type/string
+    :db/unique :db.unique/identity
+    :db/cardinality :db.cardinality/one
+    :db.install/_attribute :db.part/db}
+   {:db/id (d/tempid :db.part/db)
+    :db/ident :instance/progress
+    :db/doc "represents the progress of the instance, from 0 to 100"
+    :db/valueType :db.type/long
+    :db/cardinality :db.cardinality/one
+    :db.install/_attribute :db.part/db}
+   {:db/id (d/tempid :db.part/db)
+    :db/ident :instance/backfilled?
+    ;;;   In a future version, datomic adds these schema values, leaving the info here when that occurs
+    ;;     :schema/deprecated true
+    ;;     :schema/deprecated-because "The concept of backfill was meant to allow Cook to schedule jobs out of order
+    ;;                                 temporarily but treat the jobs as opportunistic and upgrade the jobs out of
+    ;;                                 backfill later once the scheduling order had been corrected. Unfortunately,
+    ;;                                 this causes a lot of unexpected behavior (jobs being preempted out of priority
+    ;;                                 order) and lots of bugs (it is hard to correctly update jobs). The concept of
+    ;;                                 backfill is not worth the added problems and so it is being removed."
+    :db/doc "DEPRECATED: If this is true, then this instance should be preempted first regardless of priority. It's okay to upgrade an instance to be non-backfilled after a while."
+    :db/valueType :db.type/boolean
+    :db/cardinality :db.cardinality/one
+    :db.install/_attribute :db.part/db}
+   {:db/id (d/tempid :db.part/db)
+    :db/ident :instance/hostname
+    :db/valueType :db.type/string
+    :db/cardinality :db.cardinality/one
+    :db.install/_attribute :db.part/db}
+   {:db/id (d/tempid :db.part/db)
+    :db/ident :instance/ports
+    :db/valueType :db.type/long
+    :db/cardinality :db.cardinality/many
+    :db.install/_attribute :db.part/db}
+   {:db/id (d/tempid :db.part/db)
+    :db/ident :instance/executor-id
+    :db/valueType :db.type/string
+    :db/cardinality :db.cardinality/one
+    :db.install/_attribute :db.part/db}
+   {:db/id (d/tempid :db.part/db)
+    :db/ident :instance/slave-id
+    :db/valueType :db.type/string
+    :db/cardinality :db.cardinality/one
+    :db.install/_attribute :db.part/db}
+   {:db/id (d/tempid :db.part/db)
+    :db/ident :instance/status
+    :db/index true
+    :db/valueType :db.type/ref
+    :db/cardinality :db.cardinality/one
+    :db.install/_attribute :db.part/db}
    {:db/id (d/tempid :db.part/db)
     :db/ident :instance/start-time
     :db/valueType :db.type/instant

                     ;; Checking the validity of the target state transition
                     (when (get-in state-transitions [old-state new-state])
                       (into [[:db/add instance :instance/status new-state]]
                         (let [instance-ent (d/entity db instance)
                               job-ent (:job/_instance instance-ent)
                               job (:db/id job-ent)
                               other-instances (->> (:job/instance job-ent)
                                                    (remove #(= (:db/id %) (:db/id instance-ent))))
                               instance-states (->> other-instances
                                                    (map :instance/status)
                                                    (cons new-state))
                               any-success? (some #{:instance.status/success} instance-states)
                               any-running? (some #{:instance.status/running} instance-states)
                               any-unknown? (some #{:instance.status/unknown} instance-states)
                               all-failed? (every? #{:instance.status/failed} instance-states)
                               prior-state (:job/state job-ent)
                               reason (d/entity db reason)
                               all-attempts-consumed?
                               (d/invoke db :job/all-attempts-consumed? db
                                         (update-in (into {} job-ent) [:job/instance]
                                                    conj {:instance/status new-state
                                                          :instance/reason reason}))]
                           (cond
                             (= prior-state :job.state/completed)
                             []

                             (or (and all-failed?
                                      all-attempts-consumed?)
                                 any-success?)
                             [[:db/add job :job/state :job.state/completed]]

                             (or any-running?
                                 any-unknown?)
                             [[:db/add job :job/state :job.state/running]]

                             :else
                             [[:db/add job :job/state :job.state/waiting]])))))}}

   {:db/id (d/tempid :db.part/user)
    :db/ident :job/allowed-to-start?

    :db/cardinality :db.cardinality/one
    :db.install/_attribute :db.part/db}

   ;; Resource mapping attributes
   {:db/id (d/tempid :db.part/db)
    :db/ident :resource.type/mesos-name
    :db/valueType :db.type/keyword
