Appearance
user_tags
M:N junction between users and tags.
- ETL strategy:
merge - PK:
id
Columns
| Column | Type | Description |
|---|---|---|
id | BIGINT | PK. |
id_tenant | BIGINT | FK → tenants.id. |
id_user | BIGINT | FK → users.id. |
id_tag | BIGINT | Logical FK to tags. Resolves to tags.id_origin when present, otherwise tags.id. |
No
created_at/deleted_at— this is a materialization of the current relationship state.
Patterns
sql
-- Users carrying the "VIP" tag
SELECT u.*
FROM lms.users u
JOIN lms.user_tags ut
ON ut.id_tenant = u.id_tenant AND ut.id_user = u.id
JOIN lms.tags t
ON t.id_tenant = ut.id_tenant
AND (t.id = ut.id_tag OR t.id_origin = ut.id_tag)
WHERE t.title = 'VIP'
AND u.deleted_at IS NULL
AND t.deleted_at IS NULL;