postgres: binary data type is not currently working
mysql: binary data type or string with binary collation is working
Had wanted to go with binary for all, but test would not pass
Currently, we are using the default database collation for the ancestry column.
In most rails apps, this is some form of unicode locale.
This is skipping indexes for like.
On ubuntu systems, it is ignoring slashes for sorting, which causes all sorts of problems
This changes tests to just use a simple binary comparison - ascii byte for byte.
This gets better results, uses indexes for LIKE, and is faster for all comparisons.
ENV["ANCESTRY_COLLATION"] should never be needed unless you are testing performance characteristics
### What is this PR?
* Add detail re: customizing column names.
### Why is it required?
Because it may not be convenient to name the column: 'ancestry' - I imagine (perhaps incorrectly) that many would prefer to customize the column name to something better suited to their use-cases (e.g. https://github.com/stefankroes/ancestry/issues/273).
I hope this change is helpful - if it is not, feel free to close without compunction etc.
Most database ship with locales built in so they are consistent across installations.
Postgres does not ship with locales so it uses the ones in the operating system.
In the locales there is collation, which basically defines how to sort. We will mostly
notice this in the following 2 ways:
- case sensitive sorting
- include symbols in the sorting
case sensitive: "B", "E", "c", "d"
non-case Insensitive: "B", "c", "d", "E"
include symbols: "Sams Golf Shop", "Sam's Cantina"
ignore symbols: "Sam's Cantina", "Sams Golf Shop"
In our domain, the ignoring symbols causes some issues:
include symbols: "1/2/3", "1/2/5", "1/4", "12/4"
ignore symbols: "1/2/3", "12/4", "1/2/5", "1/4" (think alphabetic sort: "123", "125", "14", 124")
If you are ordering them to put into a tree, then this gets confusing and
can result in children coming back out of order. This is tricky for arrange.
An option was introduced for the case when symbols are not considered. It essentially
'join' the strings together to simulate ignoring the symbols.
Also do remember, that this is sorting alphabetically rather than numerically. So 14 > 123.
Our team is going though the process of upgrading Rails and ran into the issue that type_for_attribute was undefined. After some investigation, we found that type_for_attribute was added in Rails 4.2 and was not defined previously.
Admittedly the documentation for `<Model>.arrange` took a couple thought cycles before I figured out the resulting data structure. I've added another node to the example to illustrate multiple siblings on one level, and fussed with the code style to be a bit easier to grok.