Thursday, January 31, 2019

重拾 Datomic

這些日子接了一個專案,打算用 Luminus 來做 web application 。前端考慮了幾個選項之後,覺得還是 ClojureScript + re-frame 是最先進的選項。資料庫自然還是要用 Datomic 才是最合用的選項。

Datomic 參考資料
1. Leran Datalog Today  --- 互動式的教學網站,可以練習 Datomic 搭配的 DSL: Datalog
2. Missing Link Datomic Tutorial --- 比官網的 Datomic tutorial 易懂,因為省略了太細的細節
3. How to setup Datomic Free with Clojure  ---- 看完了 tutorial 總是要自己實作一下,參考這個來實作最快
4. Using Datomic in your app: a practical guide --- 使用 Datomic 的實務經驗談
5. The ten rules of schema growth --- 使用 OLTP 資料庫常遇到的問題: schema migration ,該怎麼處理呢?

適合什麼情況?
哪些情況適合用 Datomic ? Datomic 適用於 OLTP 的應用、適合於 iterative development ,也就是說,如果一開始對於問題的細節有很多不了解,會有許多難以預測的新 schema 變動, Datomic 是很不錯的選項。

關於 Datomic Schema 的兩個特別的心得
(1) Datomic Schema 不需要有獨立平行的版本控管 migration file 來管理。
Datomic is uniquely suited for iterative development. Change is easy, due to the granular data model and small but powerful schema. And change is always tracked within the database itself, so you do not need a parallel infrastructure of version-controlled migration files as your application evolves.

(2) Schema 安裝是 idempotent ,所以可以放到 server startup code
In Datomic, installing your schema consists of submitting a regular transaction. Attribute installation transactions are idempotent, so you can just write your schema installation transaction in your application code and transact in your server startup code.