citusdata / citusdata/citus_docs

Multi-tenant migration steps for Sequel ORM

Open
#535 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
CSS
Stars
58
Forks
60
PR merge metrics
No merged PRs in 30d

Description

## Why are we implementing it? (sales eng)
There are a couple of customers/prospects who use SEQUEL.

### What are the typical use cases?
Multi-tenant use cases.

## Communication goals (e.g. detailed howto vs orientation)
* Model (schema) changes to add tenant_id to tables and constraints.
* How to make queries have tenant_id appended? ORMs can already have constructs (for ex. composite primary keys, scopes in sequelize etc) which would filters to tenant_id to DMLS and selects. We need to investigate by spinning up a demo app and do a test.

### Good locations for content in docs structure
https://docs.citusdata.com/en/v7.0/migration/transitioning.html#app-migration

### Example code snippet:
Just copied and pasted from general slack channel.
```
class Widget < Sequel::Model
many_to_many :tags,
adder: (->(tag) do
TagsWidgets.create(tenant: tag.tenant, tag: tag, widget: self)
end) do |ds|
ds.where(Sequel.qualify(:tags_widgets, :tenant_id) => tenant_id)
end
end
```

Basically just the `ds.where` block was what I needed to include `tenant_id`, while the `adder` block makes sure it adds new join models w/ the tenant in place
Querying on `widget.tags` for example works and includes the org ID, as does `widget.add_tag(new_tag)`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.