Files
PiCloud/crates/shared/src/group.rs
MechaCat02 ba97c35aaf feat(projects): projects table + owner_project FK; ProjectId/Project types
First commit of §7 multi-repo ownership. A 'project' is a repo-root that
declaratively manages a slice of the shared group tree; each group node is
owned by exactly one project (single-owner-per-node). This lands the registry
+ shared types and wires the inert 0047 `owner_project` seam — no behavior
change yet (claim logic is the next commit).

- migration 0066: `projects` table (UUID pk, unique slug, name, created_by →
  admin_users ON DELETE SET NULL); `groups.owner_project` gains its FK →
  projects(id) ON DELETE SET NULL (un-claim, never cascade-destroy a tree) +
  an index.
- shared: `ProjectId` (id_type! macro) + `Project` struct; `Group` gains
  `owner_project: Option<ProjectId>`.
- group_repo: GROUP_COLS + the ancestors recursive-CTE term now carry
  `owner_project`, so `ancestors()` surfaces ownership for the nearest-claimed
  fold; GroupRow + From updated.
- schema snapshot re-blessed; /version schema assertion 65 → 66.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-06 20:01:57 +02:00

36 lines
1.4 KiB
Rust

//! Groups: a GitLab-like, single-parent org tree ABOVE apps (Phase 2).
//!
//! Groups are a pure org / RBAC / UI container — they own no resources
//! (scripts/secrets stay app-owned). A `group_admin` on any ancestor is
//! implicitly app_admin on every app/subgroup beneath it; resolution
//! takes the highest effective role across the app's own membership and
//! all ancestor group memberships.
//!
//! See docs/design/groups-and-project-tool.md §5.
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::{GroupId, ProjectId};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Group {
pub id: GroupId,
/// `None` for a root node. Single-parent keeps the tree acyclic.
pub parent_id: Option<GroupId>,
/// Instance-global identifier, frozen at creation (a rename/reparent
/// never rewrites it — the deployment key stays stable).
pub slug: String,
pub name: String,
pub description: Option<String>,
/// Per-subtree structure version, bumped on every structural mutation
/// (reparent/rename/delete). Not an authz input.
pub structure_version: i64,
/// §7 multi-repo ownership: the project that declaratively manages this
/// node, or `None` when the node is UI/API-owned (no manifest claims it).
/// Apps inherit ownership from their nearest claimed ancestor group.
pub owner_project: Option<ProjectId>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}