Strange behavior when transacting historical data

I am trying to transact historical data from a Postgres database, and stumbled upon this strange case. Here’s the minimal example:

  (def uri (str "datomic:mem://" (str (gensym "mem-db-"))))

  (def schema
    [{:db/id "datomic.tx"
       :db/txInstant #inst "2017-01-01"}
      {:db/ident :user/id
       :db/valueType :db.type/long
       :db/cardinality :db.cardinality/one
       :db/unique :db.unique/identity}])

  (def data
    [
     [{:db/id "datomic.tx"
       :db/txInstant #inst "2018-09-21T20:40:33.985606000-00:00"}
      {:user/id 1}]
     [{:db/id "datomic.tx"
       :db/txInstant #inst "2018-10-21T20:40:33.985606000-00:00"}
      {:user/id 2}]])

  (d/create-database uri)

  (def conn (d/connect uri))

  @(d/transact conn schema)

  (doseq [d data]
    @(d/transact conn d))

Results in

Execution error (Exceptions$IllegalArgumentExceptionInfo) at datomic.error/arg (error.clj:79).
  :db.error/past-tx-instant Time conflict: Fri Sep 21 21:40:33 WEST 2018 is older than database basis

This behavior has to do with the type of instant used. In my data I had java.sql.Timestamp, and changing that to java.util.Date fixed things.

But the funny part is that even though I managed to transact my data by converting to Date, the minimal example above still breaks — and I don’t see why.

Datomic will allow you to transact historical data by overriding the :db/txInstant on the transaction. However, it will allow this only as long as each new datom is later than :db/txInstant on the last datom transacted. If you don’t do that, you’ll get this error. So take a look at the very last tx you’ve transacted, and you’ll be locked out of transacting anything before that time.

Thanks, I’m quite aware of that. If you take a look at the code example you can see, that all txInstants are sorted chronologically, and the error still persists.

I had success using your example, I used the newest datomic

Try:

   [
    [{:db/id "datomic.tx"
      :db/txInstant #inst "2018-09-21T20:40:33.985606000-00:00"}
     {:user/id 1}
     {:user/id 2}]
   ])

You are right, it does work in the latest version. I had 1.0.7075. Thanks!