Fork me on GitHub
#datomic
<
2017-01-24
>
abhir00p09:01:15

I am new to datomic and I was trying to understand how altering schema works in datomic?

abhir00p09:01:37

I came across this in the documentation

Because Datomic maintains a single set of physical indexes, and supports query across time, a db value utilizes the single schema associated with its basis, i.e. before any call to asOf/since/history, for all views of that db (including asOf/since/history). Thus traveling back in time does not take the working schema back in time, as the infrastructure to support it may no longer exist. Many alterations are backwards compatible - any nuances are detailed separately below.

abhir00p09:01:08

Given this Thus traveling back in time does not take the working schema back in time, as the infrastructure to support it may no longer exist.

abhir00p09:01:24

How do people using it handle schema changes in production?

pesterhazy09:01:40

well what kind of schema changes are you thinking of?

pesterhazy09:01:07

usually what you'll do is to add an attribute or add an index to an existing attribute

pesterhazy09:01:55

remember the datomic schema is very lightweight

chrisblom09:01:36

@abhir00p generally by avoiding non backward compatible schema changes

chrisblom09:01:04

in my experience most schema changes are are just adding new attributes

chrisblom09:01:46

for breaking changes is often a good idea to use a new attribute, and convert the old data to the use the new attribute

chrisblom09:01:38

Does anyone know id its possible to specify the partition when using string temp ids?

abhir00p09:01:46

Need to read a bit more to understand this.

karol.adamiec11:01:22

hello, what is the idiomatic way in datomic go get a monotonically increasing number? i need it for constructing order ids and stuff like that. Transaction number?

pesterhazy11:01:58

@karol.adamiec you need a transactor fn

karol.adamiec11:01:46

hoped to avoid that 🙂

karol.adamiec11:01:03

i am looking for something that is in datomic already that i can piggyback off. the numbers do not need to be in order, just uniqe and legible ie on the phone… guids out 🙂

pesterhazy11:01:12

here's something that you can use

pesterhazy11:01:14

{:db/id (d/tempid :db.part/user),
 :db/fn (d/function '{:lang :clojure, :imports [], :requires [], :params [db eid],
                      :code "(let [new-number (d/q ' [:find (max ?number) . :in $ :where [_ :my.order/number ?number]] db)] [{:db/id eid, :my.order/number (inc (or new-number 0))}])"})
 :db/ident :my.order/new-order}

pesterhazy11:01:49

assuming your order number attr is :my.order/number, you can generate a new order using [:my.order/new-order]

karol.adamiec11:01:13

well looks exactly like a thing i need

karol.adamiec11:01:18

thank You 😄

pesterhazy11:01:45

it's not ideal btw

pesterhazy11:01:11

I wish there were default db.fn's like that, e.g. :db.fn/auto-increment

karol.adamiec11:01:05

btw: hos does one manage clojure db functions? is that an issue?

karol.adamiec11:01:30

i can put a function in my conformity schema, but are there any practices, workflow if that code needs to evolve?

pesterhazy11:01:51

if the code evolves, a new migration 🙂

karol.adamiec11:01:03

yeah so the flow is develop a new version in repl, when happy do the migration

karol.adamiec11:01:19

sounds good enough 🙂

pesterhazy11:01:27

it's just a function really

karol.adamiec11:01:31

well yes, but passed in as string ==> which means copy and paste 😄, triggers alarms 😄

karol.adamiec11:01:00

anyway good enough for today 🙂

pesterhazy11:01:42

you can just pass it as a quoted data structure

pesterhazy11:01:50

instead of a string

karol.adamiec11:01:58

ha, that is way nicer

pesterhazy11:01:11

it's a string here because I got it from my db 🙂

karol.adamiec11:01:57

perfect, will brush up on the api today 🙂

pesterhazy11:01:13

for exploration you can also call a fn installed in your db: http://docs.datomic.com/clojure/#datomic.api/invoke

karol.adamiec11:01:34

ha, looks like a great way for an ‘integration' test

pesterhazy11:01:13

(d/invoke (rdb) :my.order/new-order (rdb) (d/tempid :db.part/user))
[{:db/id #db/id[:db.part/user -1000004], :my.order/number 16256}]

jaret14:01:54

@Chrisbloom To your question on specifying the partition when using string temp ids. The string temp id will use the partition that is configured as the default. So you can specify what partition all string temp ids will use, but not on a per transaction basis. http://docs.datomic.com/transactions.html#default-partition

chrisblom14:01:56

@jaret thanks, looks like i'll be using good 'ol tempids then

alqvist16:01:42

The query works in datomic console

alqvist16:01:26

And I can use the same repl to transact successfully

marshall16:01:58

@alqvist are you passing a database that has had that schema transacted?

alqvist16:01:38

@marshall Yes, tried it just before

alqvist16:01:01

(d/transact conn (read-string (slurp "schema.edn")))

alqvist16:01:26

and console reflects the schema

marshall16:01:21

can you provide the full query you’re issuing?

alqvist16:01:22

It is in the previous link

alqvist16:01:41

But this also fails `(d/q '[:find ?e ?doc :where [?e :db/doc ?doc]])`

alqvist16:01:28

that is by design..

marshall16:01:37

what args are you passing?

alqvist16:01:44

my last query is working

alqvist16:01:50

but not the linked one

marshall16:01:07

the last one ends after the query string - it needs to be passed a database

alqvist16:01:29

Yea, caught that

alqvist16:01:37

this is from my link (d/q '[:find ?org-name :where [?e :alarm/org-name ?org-name]]

alqvist16:01:18

(d/q '[:find ?org-name :where [?e :alarm/org-name ?org-name]] db)

marshall16:01:22

(d/q '[:find ?org-name :where [?e :alarm/org-name ?org-name]] (d/db conn))

marshall16:01:51

I’m guessing you def’d db before transacting your schema

marshall16:01:09

so it is an immutable value of the database from before schema was added

marshall16:01:20

you need to get a new value of the db (with (d/db conn))

marshall16:01:26

to pass to your query

alqvist16:01:22

Ahhhh.... That makes perfect sense

alqvist16:01:32

Thanks for your help!

curtosis20:01:57

what are folks currently using for schema/migrations etc these days?

jaret20:01:34

@curtosis I think Conformity is what I see most often around schema/migration discussions.

jaret20:01:58

That's an older experience report from Yeller

jaret20:01:47

There are others out there. Generations to name one

apsey20:01:10

Hi, regarding s3 log rotation, what does cognitect mean with time-status-reached on:

* Better naming convention for logrotation:
  `{bucket}/{system-root}/{status}/{time-status-reached}`,
  where status is "active" or "standby".

curtosis20:01:19

thanks… yeah, I remembered Conformity but it was a while ago.

curtosis20:01:00

(cue typical clojure complaint: not sure if library abandoned or just very stable)

jaret21:01:16

@robert-stuttaford awesome! This looks great!

robert-stuttaford21:01:37

rad 🙂 hope others find it useful!

robert-stuttaford21:01:58

i must admit that spec is probably overkill for parsing options, but it was just so much fun to do https://github.com/Cognician/datomic-doc/blob/master/src/cognician/datomic_doc/options.clj