Fork me on GitHub
#xtdb
<
2023-06-14
>
Nikolas Pafitis09:06:17

How do you handle schema changes when working with XTDB? Right now if my data's shape change, I connect to the prod Xtdb Node with a local repl and update the resources as necessary.

👀 2
wotbrew15:06:27

Hi @U0105D1EL4B, In XTDB there is no explicit notion of schema change - are you referring to using :xt/put to change attribute names or types? Have you got an example of what you are trying to achieve so I can better help?

Nikolas Pafitis17:06:45

I use schemas for my REST API, with reitit coercion and malli validation. If i want to change my schema, for example the name of an attribute or add a new attribute that's not optional etc, I need the data in the db to reflect the new schema

wotbrew15:06:28

There is no ALTER TABLE type statement that will rewrite your data automatically. You would need to use :xt/put to overwrite your data with the desired structure. For example, you could use a transaction function to query for affected data and emit the desired :xt/put ops. Be aware that transaction sizes are limited to main memory, so you might not want to rewrite millions of documents in a single transaction.

jussi14:06:13

Any ideas when you could update dependencies in XTDB libraries? Our automated cve-check failed due to an old com.google.guava version (31.1, https://ossindex.sonatype.org/vulnerability/CVE-2023-2976?component-type=maven&amp;component-name=com.google.guava%2Fguava&amp;utm_source=dependency-check&amp;utm_medium=integration&amp;utm_content=8.2.1). Latest library versions 1.23.2 do not solve this. It's a transient dependency:

xtdb-google-cloud-storage
  google-cloud-nio
    guava

wotbrew15:06:30

Thanks for the report @U0267SNCPEY, I will take a look at bumping the dependency. Have you been able to override the dependency version (by including the desired version explicitly in your lein project.clj or clj deps.edn )? I have created an issue here: https://github.com/xtdb/xtdb/issues/2564

jussi16:06:52

Not yet, it was caught by deployment and I temporarily suppressed the cve issue in order to deploy.

jussi06:06:58

And we could override that particular version yes, but we have another shadowed guava dependency which is a real problem

ianjones16:06:50

hey yall, let me know if this is the right place for this question but Im writing this pull query: (pull m [* {:workout-movement/_movement [{:workout-movement/workout [*]}]}]) and I want to filter the :workout-movement/workout by an attribute on the :workout entity. Im struggling to do so… I either get no records back (where I want just the root record m ) or I get workouts that I am trying to filter. yall have any recommendations for how to do this or where to explore?

Vincent23:06:19

can you paste a sample of your data or like the general data shape

jarohen09:06:48

Hey @U0CKDV6DB 👋 Pull is more of a projection tool - once you've found the documents you're interested in, pull will get you the data in the shape you need it. I'd use triples in the :where clause to filter the data down first - e.g. (guessing at your data model):

{:find [(pull m [* {:workout-movement/_movement [{:workout-movement/workout [*]}]}])]
 :in [filter-val]
 :where [[wm :workout-movement/movement m]
         [wm :workout-movement/workout w]
         [w :workout/attr-to-filter filter-val]]}

ianjones14:06:33

yeah, for a query like this, the [w :workout/attr-to-filter filter-val] isnt filtering out the workouts I’d expect

ianjones14:06:04

(q db
       '{:find [(pull m [* {:workout-movement/_movement [{:workout-movement/workout [*]}]}])]
         :in [user]
         :where [[m :movement/name "muscle up"]
                 [wm :workout-movement/movement m]
                 [wm :workout-movement/workout w]
                 [w :workout/user user]
                 ]}
       user-a)

ianjones14:06:28

being an actual query im making… im getting workouts w for more than 1 user

ianjones14:06:18

I’ve conceded to just doing this

(let [m        (xt/entity db (parse-uuid (:id path-params)))
        workouts (biff/q db '{:find  (pull w [*])
                              :in    [[movement user]]
                              :where [[w :workout/name]
                                      (or [w :workout/user  user]
                                          (and [w :workout/name]
                                               (not [w :workout/user])))
                                      [wm :workout-movement/workout w]
                                      [wm :workout-movement/movement movement]]}
                         [(parse-uuid (:id path-params)) (:uid session)])])

ianjones14:06:51

its 2 queries but does exactly what i need ¯\(ツ)

ianjones14:06:00

just wanted to get the reverse look up working haha

jarohen14:06:59

oh, of course, sorry, yes - because the pull ignores the filter and starts again, traversing the graph from the movement object. once the pull has joined to the next document it pulls out everything again

jarohen14:06:06

glad to hear you resolved it though 🙂

Vincent23:06:49

Huzzah an #CG3AM2F7V chat room 😄

👋 2
Vincent23:06:14

Okay let's say I want to check if someone has hit their quota of 3 special posts this month. So I was thinking, do 30-day long window, count how many posts have been made, check against quota question: how can I achieve this with xtdb 😅

jarohen09:06:52

Hey @U055PQH9R4M, welcome 👋 In this case, I don't think the (1.x-style point-in-time) bitemporal queries would be the right tool for the job here - I'd probably store the 'quota date' on the document and then do a standard atemporal 'find me the special posts with a quota date in the last 30 days' query

jarohen09:06:49

(we generally recommend an explicit attribute in the document whenever 'creation date' or similar is important in the business domain)

Vincent16:06:05

I'm writing a created-at for each entry, I'm not sure I understand your proposal my friend. Something like: "Today is June 16 and you have 3 special writes left this month" as a tuple? I guess I am confused by the term "quota date" -- would that be the date the quota resets?

Vincent16:06:59

quota date think_beret seems like the right approach gotta kinda sort it out in my head tho x)

jarohen16:06:15

it's probably created-at, tbh 🙂

jarohen17:06:05

but I didn't want to assume that the date that you were using to calculate the quota was published-at or something 🙂

Vincent17:06:40

"gimme all the docs with a quota date, sort by time, count?

jarohen17:06:01

sounds good to me 🙂

jarohen17:06:56

filter to 'since 30 days ago' rather than sort, I'd guess - but yeah, otherwise all good 🙂

Vincent05:06:53

as an xtdb newb i'm wondering what it looks like. i'm gonna take a stab at it soon

👍 2