Skip to content

Use SQL composite data types for mutli-parent resource #3152

@luqmana

Description

@luqmana

We have some tables with columns being foreign keys to potentially multiple tables depending on some kind or type, e.g.:

CREATE TYPE omicron.public.network_interface_kind AS ENUM (
    /* An interface attached to a guest instance. */
    'instance',
    /* An interface attached to a service. */
    'service'
);

CREATE TABLE omicron.public.network_interface (
    /* ...snip... */

    /* The kind of network interface, e.g., instance */
    kind omicron.public.network_interface_kind NOT NULL,

    /*
     * FK into the parent resource of this interface (e.g. Instance, Service)
     * as determined by the `kind`.
     */
    parent_id UUID NOT NULL,

Keeping track of 2 separate columns can be kind of fraught so it'd be nice to replace with a composite data type on the SQL side and an enum + appropriate impls on the Rust side.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cleanupCode cleanliness

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions