-
-
Save ivarref/f92d9efd45d1c0cbd2d239bf4904a323 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns no.nsd.ire-test.excision-on-prem | |
(:require [datomic.api :as d] | |
[clojure.string :as str] | |
[clojure.pprint :as pprint]) | |
(:import (java.util Date))) | |
(def uri (str/trim (slurp ".db.url"))) | |
(def conn | |
(do | |
(d/delete-database uri) | |
(d/create-database uri) | |
(d/connect uri))) | |
@(d/transact conn [#:db{:ident :m/info | |
:cardinality :db.cardinality/one | |
:valueType :db.type/string}]) | |
(def eid (-> @(d/transact conn [{:db/id "id" | |
:m/info "secret data that should be removed"}]) | |
(get-in [:tempids "id"]))) | |
@(d/transact conn [{:db/id eid | |
:m/info "OK data"}]) | |
(defn show-history [] | |
(->> (d/q '[:find ?e ?a ?v ?t ?o | |
:in $ ?e ?a | |
:where | |
[?e ?a ?v ?t ?o]] | |
(d/history (d/db conn)) | |
eid :m/info) | |
(into []) | |
(sort-by (fn [[e a v t o]] [t o e a v])) | |
(mapv (fn [[e a v t o]] | |
(println (str "[" e) a (pr-str v) t | |
(str o "]")))))) | |
(println "history before excision:") | |
(show-history) | |
(def before-t (d/q '[:find ?t . | |
:in $ ?e ?a ?v | |
:where | |
[?e ?a ?v ?t true]] | |
(d/history (d/db conn)) | |
eid :m/info "OK data")) | |
(println "before-t:" before-t) | |
(def excise-cmd {:db/excise eid | |
:db.excise/attrs [:m/info] | |
:db.excise/beforeT before-t}) | |
(pprint/pprint excise-cmd) | |
(let [{:keys [db-after]} @(d/transact conn [excise-cmd])] | |
(println "waiting for excise ...") | |
@(d/sync-excise conn (d/basis-t db-after)) | |
(println "waiting for excise ... OK")) | |
(println "history after excision:") | |
(show-history) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment