Skip to content

early table name serialization prevents sharding with switchman #214

Open
@anthuswilliams

Description

@anthuswilliams

We have a Rails app that does sharding using https://github.com/instructure/switchman, an ActiveRecord extension which manages database sharding by using several PostgreSQL schemas and switching between them appropriately when executing ActiveRecord queries.

closure_tree does not work at all with switchman because it serializes the hierarchies table name at load time, when it is included in an ActiveRecord model. This happens in the default shard (the "public" schema). Then, when we switch shards in order to execute a closure_tree query in a different schema, it incorrectly tries to pull records from "public.#{ table }_hierarchies", rather than "#{ schema }.#{ table }_hierarchies".

In order to help see what I'm talking about, here is a monkey-patch that works around this problem in our app:

https://gist.github.com/anthuswilliams/bce19169ae1fa531d798765031bc320d

I thought I'd introduce this issue in case anyone is trying something similar, and on the off chance we can work up a solution within closure_tree. In the meantime, I guess no Rails codebase is complete without a monkey-patch or two.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions