You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
use CockroachDB enums in more places in database schema #312
There are a few places in the schema where we'd like to use CockroachDB enums, but we were prevented by cockroachdb/cockroach#57411 / cockroachdb/cockroach#58084. This was supposed to be resolved in v21.1. So with #195 in, we should be able to switch to the enums. (This is worth confirming before doing too much work here.)
Examples where we want to use this:
"Instance" table, "state" field.
"Disk" table, "disk_state" field.
"Saga" table, "saga_state" field.
"SagaNodeEvent" table, "event_type" field.
I skimmed the schema to look for other candidates and I think that about covers it.
I expect this change will involve, for each of the above cases:
update the schema SQL to create the enum (many of these have a commented-out version already -- that needs to be compared to the actual Rust enum to make sure these are in sync)
presumably there's some change we need to make to the Diesel table! macro invocations, but I'm not sure what that looks like yet
I think that's it, but I'm not sure if there's something else we need to do on the Diesel side.
_ => Err("Unrecognized enum variant for VpcRouterKind".into()),
}
}
}
As part of the firewall work I'm doing in a branch, I needed some more enums so I followed the pattern there and made a declarative macro to reduce the pile of boilerplate (9f667f7). Does this seem like a fine workaround for now?
Activity
teisenbe commentedon Nov 10, 2021
It looks like we're already using enums, just with some manual conversion back and forth
omicron/nexus/src/db/schema.rs
Lines 185 to 196 in b9b0ea9
omicron/nexus/src/db/model.rs
Lines 982 to 1033 in b9b0ea9
As part of the firewall work I'm doing in a branch, I needed some more enums so I followed the pattern there and made a declarative macro to reduce the pile of boilerplate (9f667f7). Does this seem like a fine workaround for now?
smklein commentedon Nov 10, 2021
FYI @zephraph , regarding the macro for enum generation.
Personally I think having helpers to reduce the boilerplate here would be great, as long as the interface for those helpers is clear.
just-be-dev commentedon Nov 10, 2021
Heh, that pattern is hot off the presses (and may need to be cleaned up a little). I do love the macro to dry it up though! Thanks @teisenbe.
Implement macro to simplify enum types
Implement macro to simplify enum types (#379)
davepacheco commentedon Nov 15, 2021
FWIW in this issue I was talking about using CockroachDB enums, not Rust enums.
[-]use CockroachDB enums in database schema[/-][+]use CockroachDB enums in more places in database schema[/+]davepacheco commentedon Nov 8, 2022
Update: we've done this for most of the enums, but not the data-carrying ones (like DiskState).