Skip to content

Purpose-Based Data Model: OSS models, schemas, and migration#7635

Draft
galvana wants to merge 17 commits intomainfrom
purpose-based-data-model
Draft

Purpose-Based Data Model: OSS models, schemas, and migration#7635
galvana wants to merge 17 commits intomainfrom
purpose-based-data-model

Conversation

@galvana
Copy link
Contributor

@galvana galvana commented Mar 12, 2026

Ticket ENG-2756

Description Of Changes

Add the foundational data model for purpose-based access control (PBAC) to Fides OSS. This introduces new SQLAlchemy models, Pydantic schemas, and an Alembic migration for tracking data purposes, data consumers, data producers, and their relationships to systems and datasets.

The purpose-based data model enables organizations to define why data is collected/processed (purposes), who consumes it (consumers), and who produces it (producers), with many-to-many relationships linking purposes to systems, consumers, and datasets.

Code Changes

  • src/fides/api/models/data_purpose.py - New DataPurpose model with taxonomy fields (data_use, data_subject, legal_basis, retention, etc.)
  • src/fides/api/models/system_purpose.py - SystemPurpose join table linking systems to purposes with assigned_by tracking
  • src/fides/api/models/data_consumer.py - DataConsumer model with contact info, egress/ingress, and DataConsumerPurpose join table
  • src/fides/api/models/data_producer.py - DataProducer model with DataProducerMember join table for user assignments
  • src/fides/api/models/sql_models.py - Added system_purposes relationship to System model
  • src/fides/api/db/base.py - Registered new models for Alembic discovery
  • src/fides/api/schemas/data_purpose.py - Create/Update/Response Pydantic schemas for DataPurpose
  • src/fides/api/schemas/data_consumer.py - Create/Update/Response schemas for DataConsumer with purpose assignment
  • src/fides/api/schemas/data_producer.py - Create/Update/Response schemas for DataProducer with member management
  • src/fides/api/alembic/migrations/versions/xx_2026_03_12_... - Migration creating all PBAC tables with indexes and foreign keys

Steps to Confirm

  1. Run model unit tests: nox -s "pytest(ops-unit)" -- tests/ops/models/test_data_purpose.py tests/ops/models/test_system_purpose.py tests/ops/models/test_data_consumer.py tests/ops/models/test_data_producer.py tests/ops/models/test_dataset_purposes.py -v
  2. Verify migration applies cleanly: nox -s check_migrations
  3. Confirm static checks pass: nox -s static_checks

Pre-Merge Checklist

  • Issue requirements met
  • All CI pipelines succeeded
  • CHANGELOG.md updated
    • Add a db-migration This indicates that a change includes a database migration label to the entry if your change includes a DB migration
    • Add a high-risk This issue suggests changes that have a high-probability of breaking existing code label to the entry if your change includes a high-risk change (i.e. potential for performance impact or unexpected regression) that should be flagged
    • Updates unreleased work already in Changelog, no new entry necessary
  • UX feedback:
    • All UX related changes have been reviewed by a designer
    • No UX review needed
  • Followup issues:
    • Followup issues created
    • No followup issues
  • Database migrations:
    • Ensure that your downrev is up to date with the latest revision on main
    • Ensure that your downgrade() migration is correct and works
      • If a downgrade migration is not possible for this change, please call this out in the PR description!
  • Documentation:
    • Documentation complete, PR opened in fidesdocs
    • Documentation issue created in fidesdocs
    • If there are any new client scopes created as part of the pull request, remember to update public-facing documentation that references our scope registry
    • No documentation updates required

Adrian Galvan and others added 15 commits March 11, 2026 17:44
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Clarify FidesBase inheritance pattern, add cascade/delete behavior,
fix response schema conventions, document facade coercion, add
comprehensive index specifications, and resolve GET-by-ID ambiguity.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Dataset-level purposes stored as ARRAY(String) column on ctl_datasets.
Collection/field/sub-field purposes remain as soft refs in JSON.
All dataset purpose references are fides_key strings validated on write.
No join table needed for dataset-to-purpose relationships.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
18-task plan across 4 chunks covering models/migration (fides OSS),
services, API routes (fidesplus), and dataset integration. Reviewed
and validated against the design spec.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
DataPurpose goes in src/fides/api/models/data_purpose.py instead of
sql_models.py. Imports FidesBase from sql_models without circular
dependency since sql_models doesn't import back.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Model tests use the standard db session fixture and don't need
the postgres marker.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Introduces the DataPurpose SQLAlchemy model as a centrally-governed,
reusable declaration of why data is processed. Follows the same pattern
as DataCategory/DataUse (Base + FidesBase, fides_key uniqueness enforced
in create override). Registers the model in base.py for Alembic discovery.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Resolves mypy errors for string-based relationship references.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add bidirectional relationships between DataPurpose, DataConsumer,
DataProducer, System, and their join tables. Include migration for
all purpose-model tables (data_purpose, data_consumer, data_producer,
system_purpose, data_consumer_purpose, data_producer_member).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Contributor

vercel bot commented Mar 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
fides-plus-nightly Ignored Ignored Preview Mar 17, 2026 6:21am
fides-privacy-center Ignored Ignored Mar 17, 2026 6:21am

Request Review

Adrian Galvan and others added 2 commits March 12, 2026 16:48
…onsumer_purpose table

The migration had a truncated line (sa on its own) and was missing:
- data_purpose columns (data_use, data_subject, data_categories, etc.)
- data_consumer_purpose join table creation
- data_purpose indexes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant