Skip to content

Instantly share code, notes, and snippets.

@chrisarcand
Last active April 27, 2016 09:26
Show Gist options
  • Save chrisarcand/d84da35e832afc95dcda625810fe3c05 to your computer and use it in GitHub Desktop.
Save chrisarcand/d84da35e832afc95dcda625810fe3c05 to your computer and use it in GitHub Desktop.
Big Trouble In Little Arraytown

So I ran into a lovely issue while porting MiqGroup#filters (text blob, serialized hash) to Entitlement filter columns (Postgres Array columns, divided): Postgres multidimensional arrays must be of equal length.

The problem with this is that we currently store filters like this:

[["/managed/environment/dev"],
 ["/managed/location/chicago", "/managed/location/london"],
 ["/managed/prov_max_cpu/1"],
 ["/managed/service_level/gold"]]

I was originally going to leave the format as is because it affects too much to change it. But now I realize I can't do that (at least, not without just porting over a serialized text blob). The current format is pretty fragile, plus with multiple columns now the prefixes (i.e. /managed/) are pointless.

Maybe we should port this to a JSON column, an excellent tool for 'tagging'. Then...

{ "environment":   ["dev"],
  "location":      ["chicago", "london"],
  "service_level": ["gold"] }

Problems:

  • These are just filters, not the actual tags themselves...so I'm guessing tags elsewhere will have to be changed. That could be a very, very large undertaking.
  • My example is just for tag_filters ("managed" filters); I can't really deduce what the format is for 'belongsto' yet. I'm guessing it could work similarly.

Ultimately, we must do tagging in a better way now IMO, as the next step is for ✨ Multiple entitlements ✨ which need to be able to make sense of 'merging' filters. (Right?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment