Skip to content

Implement max_models_by_field and unique field constraints#122

Draft
Copilot wants to merge 3 commits intoimprove-sosh-net-uifrom
copilot/implement-max-models-by-field
Draft

Implement max_models_by_field and unique field constraints#122
Copilot wants to merge 3 commits intoimprove-sosh-net-uifrom
copilot/implement-max-models-by-field

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

Adds two new data-integrity features: per-field creation limits per user (max_models_by_field) and database-level unique column constraints (unique: true).

max_models_by_field

reaction:
  auth:
    require_login: true
    max_models_by_field:
      post_id: 1  # one reaction per user per post
  • src/mspec/core.py: Defaults max_models_by_field to {} in all auth blocks; validates that it cannot be set without require_login: true
  • src/mapp/module/model/db.pydb_model_create: After the max_models_per_user check, iterates max_models_by_field and raises MappUserError('MAX_MODELS_BY_FIELD_EXCEEDED', ...) (→ HTTP 400) when exceeded

unique field constraint

username:
  type: str
  unique: true
  • db_model_create_table: Appends UNIQUE to the SQLite column definition for non-list, non-foreign-key fields with unique: true
  • db_model_create: Catches sqlite3.IntegrityError and raises MappUserError('UNIQUE_CONSTRAINT_VIOLATED', 'A record with that value already exists.') (→ HTTP 400)

Tests & docs

  • Added limit_d (exercises max_models_by_field) and unique_test (exercises unique: true) models to model-type-testing.yaml
  • run_server_crud_for_model in test.py now asserts HTTP 400 + correct error codes for both constraint types
  • docs/LINGO_MAPP_SPEC.md documents the new auth.max_models_by_field dict and unique field attribute

Copilot AI and others added 2 commits April 13, 2026 06:13
…_by_field requires login, add comment for FK UNIQUE exclusion

Agent-Logs-Url: https://github.com/medium-tech/mspec/sessions/b14cb5cf-a10a-4577-a667-9dcc9cb85103

Co-authored-by: b-rad-c <25362581+b-rad-c@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement max_models_by_field and unique constraints Implement max_models_by_field and unique field constraints Apr 13, 2026
Copilot AI requested a review from b-rad-c April 13, 2026 06:20
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.

DEPLOY SPRINT - Ticket 01 - Implement max_models_by_field and unique constraints

2 participants