flip_api.db.seed.roles

Attributes

CURRENT_ROLES

Classes

RoleSeed

A predefined role to seed; id is the stable RoleRef identity.

Functions

seed_roles(→ list[str])

Seed roles into the database, idempotently.

Module Contents

class flip_api.db.seed.roles.RoleSeed

Bases: TypedDict

A predefined role to seed; id is the stable RoleRef identity.

id: uuid.UUID
name: str
description: str
flip_api.db.seed.roles.CURRENT_ROLES: list[RoleSeed]
flip_api.db.seed.roles.seed_roles(session: sqlmodel.Session) list[str]

Seed roles into the database, idempotently.

Idempotency is keyed on the role id (the stable RoleRef), not the name. A role may be renamed across releases while keeping its id — e.g. the observerviewer rename — so matching on the (mutable) name would miss the existing row and collide on the primary key when re-seeding a live database. An existing role has its name/description refreshed in place (bumping updated_at) so renames apply; an unchanged re-seed is left untouched.

Parameters:

session (Session) – The SQLModel session used for reads and writes.

Returns:

All role names present after seeding.

Return type:

list[str]