Find the tables by the organizations table¶
You do not have to write the spec by hand. If your schema has an organizations table (accounts, companies, tenants) that the other tables reach through foreign keys, check can propose the whole spec from it, whatever the columns are called.
lokadb check -db "$CLOUD_DSN" -org-table organizations -write-spec spec.json
-write-spec saves the proposed spec; review it, then use it as -spec spec.json for check, enable and move-org.
What it decides¶
For every table, the report says what it decided and why:
| Role | Meaning |
|---|---|
root |
has a one-column foreign key to the organizations table; that column becomes its tenant_column (tenant_id in one table, owner_company_id in another) |
child |
has a one-column foreign key to the key of a table already chosen; that column becomes its parent_column, so chains of any depth are followed |
cloud |
stays in the cloud, with a reason: the organizations table itself, tables that do not reach it (users, reference data), polymorphic references (never followed), membership tables |
ambiguous |
two or more foreign keys to the organizations table (from_company_id, to_company_id), or two parents that disagree on the data; the check does not guess, you name one in the spec |
If your schema has no foreign keys (Laravel without foreign(), Rails), the organization column is found by name (<singular of the table>_id) and confirmed against the data before it is trusted; a table with no rows yet cannot be confirmed, and the report says it was taken by name and not verified.
Read the result¶
The text report prints a line per table. The JSON report (-json) carries the same in a discovery object: the role, the column, the path up to the organizations table, the basis (fk or name) and, for tables left out, a reason code and text (report format).
If you do not give -spec, -org-table or -tenant-column, check names the tables that look like the organizations table. When every table shares one column name, -tenant-column organization_id is the shorter way.
The full rules are in check an application.