Skip to content

Determine type column values for Namespace subclasses

Currently we have two different aspects that we use to identify what kind of Namespace we're dealing with.

  • kind which is a method on the model
  • type which is a DB field.

Currently we have the following:

  • Namespace
    • kind: user
    • type: nil
  • Group
    • kind: group
    • type: Group

Let's use type and phase out kind, and also make an effort to reduce database storage of unnecessary characters.

@digitalmoksha specifies in !68825 (comment 664632991):

One small concern I have - if we just use the default mappings, then the types in the type column will become Namespaces::ProjectNamespace, Namespaces::UserNamespace, and eventually Namespaces::GroupNamespace. Rather than Project, User, and today's Group. It feels a little wasteful on characters.

I think we can override that behavior by adjusting store_full_sti_class, store_full_class_name, and I think sti_name and sti_class_for. But I haven't gotten that working yet cleanly in the UserNamespace case.

Also, he writes in !68825 (comment 666478387):

The code above also needs to handle the null value for user namespace.

Believe it or not (and unfortunately), it doesn't need to. STI is not invoked unless the type column exists and there is value in it. At least based on my testing.

I think it is worth being consistent. I mean I don't think we'd want the Group, Namespaces::ProjectNamespace and null(current value for user namespace) values in the namespaces#type field 😬 🤷

I agree, I'm working on the User angle right now in !68894 (merged)

I agree values should be consistent. Whether to store shorter or "full" names depends if there is a noticeable DB benefit. If it doesn't matter from DB POV, I wonder if it's worth it (as it would be just extra logic to maintain)?

I agree, if there is no benefit, it's not really necessary (though we will be able to use that trick during the time we/if transition the Group to Namespaces::GroupNamespace).

@ahegyi up to you - for the namespaces table, should we care about whether each record's type column has one of Namespaces::GroupNamespace, Namespaces::ProjectNamespace, and Namespaces::UserNamespace, or they would be Group, Project, User?

Edited by charlie ablett