Skip to content

tenants

Platform instances belonging to the customer. Each customer typically owns 1+ tenants in a hierarchy (root + sub-platforms).

  • ETL strategy: merge (upsert by id)
  • PK: id

Columns

ColumnTypeDescription
idBIGINTPK.
id_parentBIGINTLogical FK → tenants.id. Parent tenant in the hierarchy.
subdomainTEXTTenant subdomain (e.g. customer.cademi.com.br).
domainTEXTCustom domain when configured.
keyTEXTInternal slug for the tenant.
user_limitBIGINTContractual user cap.
metaJSONBTenant-level configuration. Domain-grouped (certificate, gamification). See structure below.
created_atTIMESTAMPTZTenant creation.
deleted_atTIMESTAMPTZSoft delete (NULL = active).

meta structure

Domain-grouped JSONB. Any key may be absent — empty branches are stripped.

json
{
  "branding": {
    "title",
    "main_color",
    "theme",
    "login":  { "logo" },
    "email":  { "logo", "sender": { "email", "name" } }
  },
  "certificate": {
    "is_active",
    "logo": { "light", "dark" }
  },
  "gamification": {
    "is_active",
    "show_users",
    "show_full_name",
    "comment_scoring_type",
    "events": { "<event_name>": { "is_active", "points" },  }
  }
}

meta.branding

Visual identity and email-sender configuration.

PathTypeMeaning
titlestringTenant display title.
main_colorstringPrimary brand color (hex).
themestringEnum — see below. Defaults to light.
login.logostringURL of the logo shown on the login page.
email.logostringURL of the logo embedded in transactional emails.
email.sender.emailstring"From" address used for transactional emails.
email.sender.namestring"From" display name used for transactional emails.

Enum · meta.branding.theme

ValueMeaning
darkDark layout.
lightLight layout. Default.

meta.certificate

PathTypeMeaning
is_activebooleanWhether the tenant has certificates enabled.
logo.lightstringURL of the light-theme certificate logo.
logo.darkstringURL of the dark-theme certificate logo.

meta.gamification

PathTypeMeaning
is_activebooleanGamification turned on for the tenant.
show_usersbooleanShow learners in the gamification ranking.
show_full_namebooleanDisplay learners' full name in the ranking.
comment_scoring_typestringEnum — see below.
eventsobjectMap of event name → { is_active, points }. See event names below.

Enum · meta.gamification.comment_scoring_type

ValueMeaning
singleA user is awarded points only on their first comment.
unlimitedEvery comment scores.

Event names in meta.gamification.events

Each value is { is_active: boolean, points: integer }. points defaults to 0 when not configured.

EventAwards points when…
lesson_completeda lesson is completed.
course_startedthe learner starts a course.
course_progress_50the learner reaches 50%.
course_progress_75the learner reaches 75%.
course_progress_90the learner reaches 90%.
course_completeda course is fully completed.
exam_passedthe learner passes an exam.
certificate_issueda certificate is issued.
comment_posteda comment is posted (subject to comment_scoring_type).
question_askeda question/inquiry is posted.

The same event names show up in scores.type, so you can match scores.type against meta.gamification.events.

Relationships

  • Self: id_parent → another tenants.id. Use it to reconstruct the instance tree.
  • Children: almost every table references tenants.id via id_tenant.

Examples

sql
-- Full tenant tree for the customer
WITH RECURSIVE tree AS (
    SELECT id, id_parent, subdomain, 0 AS level
    FROM lms.tenants
    WHERE id_parent IS NULL AND deleted_at IS NULL
  UNION ALL
    SELECT t.id, t.id_parent, t.subdomain, tree.level + 1
    FROM lms.tenants t
    JOIN tree ON tree.id = t.id_parent
    WHERE t.deleted_at IS NULL
)
SELECT * FROM tree ORDER BY level, subdomain;

-- Tenants with gamification enabled and the points awarded for completing a lesson
SELECT id,
       subdomain,
       (meta->'gamification'->'events'->'lesson_completed'->>'points')::int AS lesson_points
FROM lms.tenants
WHERE (meta->'gamification'->>'is_active')::boolean = TRUE
  AND deleted_at IS NULL;

OpenDB · Cademi LMS Data Warehouse