Private Issues: Examine feasibility of single type/class ⇔ multiple DB tables #244

Closed
opened 2025-10-23 11:59:02 +00:00 by nilsph · 2 comments
nilsph commented 2025-10-23 11:59:02 +00:00 (Migrated from codeberg.org)

In the design ticket (forgejo/design#2), there are comments mentioning using one class/type in the code as an option. I want to research if it is possible to have instances of an xorm-backed struct type be mapped to rows in one or the other table (that’s a requirement for the feature to be accepted upstream). I assume if it were, this would let me get by with a lot less of making existing code generic to cope with two separate issue types.

In the design ticket (forgejo/design#2), there are comments mentioning using one class/type in the code as an option. I want to research if it is possible to have instances of an xorm-backed struct type be mapped to rows in one or the other table (that’s a requirement for the feature to be accepted upstream). I assume if it were, this would let me get by with a lot less of making existing code generic to cope with two separate issue types.
nilsph commented 2025-10-27 14:06:20 +00:00 (Migrated from codeberg.org)
Here’s my current POC: https://codeberg.org/nilsph/poc-xorm_map_type_two_tables
nilsph commented 2025-10-30 16:06:05 +00:00 (Migrated from codeberg.org)

I’ve simplified the POC a bit and clarified about the role of PrivateThing.

I think the POC shows that:

  • We can have one struct type (Thing) which depending on an attribute (Thing.is_private) gets stored in one or the other table in the database (via Thing.Table()).
  • With this, “naively” querying Thing will give you only public items and you need to use PrivateThing for querying private items (which are cast afterwards), you shouldn’t inadvertently end up with a private item and divulge it to the wrong audience.
I’ve simplified the POC a bit and clarified about the role of `PrivateThing`. I think the POC shows that: - We can have one struct type (`Thing`) which depending on an attribute (`Thing.is_private`) gets stored in one or the other table in the database (via `Thing.Table()`). - With this, “naively” querying `Thing` will give you only public items and you need to use `PrivateThing` for querying private items (which are cast afterwards), you shouldn’t inadvertently end up with a private item and divulge it to the wrong audience.
ryanlerch added this to the Sprint 12 project 2025-11-03 04:04:45 +00:00
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
Reference
forge/forge#244
No description provided.