Implement sponsor tier model (Gold/Silver/Bronze) with database constraints - #71
Open
federicopfund wants to merge 1 commit into
Open
Implement sponsor tier model (Gold/Silver/Bronze) with database constraints#71federicopfund wants to merge 1 commit into
federicopfund wants to merge 1 commit into
Conversation
Evolution 32: agrega unit_type 'publication' y 'platform' a sponsor_agreements, restringe qué contenido puede auspiciar cada tier (chk_agreement_tier_scope) y garantiza con índices únicos parciales que Oro sea exclusivo a nivel de toda la plataforma (no por unidad) y que Plata tenga como máximo un acuerdo activo por unidad. publications gana sponsor_id/sponsor_label/sponsor_show_public igual que seasons/ collections/events. El límite de 2 sponsors Bronce activos por unidad no se puede expresar como índice único, así que se aplica con un trigger fuera de las evolutions de Play (sql/trigger_sponsor_bronze_limit.sql), siguiendo el mismo patrón que trigger_close_previous_stage.sql. docs/SPONSOR_TIER_MODEL.md documenta la evaluación de la evolution 31, las reglas de negocio resultantes y los próximos pasos de capa de aplicación (modelos, repos, admin UI, partial de badge). Validado aplicando las 32 evolutions contra Postgres real y probando las 10 reglas de negocio (exclusividad de Oro, alcance por tier, exclusividad de Plata, límite de Bronce). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011GvPuvd3UBUf1hPFRHNEza
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements the definitive sponsor business model with three tiers (Gold/Silver/Bronze), each with distinct content scope, exclusivity rules, and concurrency limits. The changes enforce these rules at the database level through constraints and indexes, eliminating reliance on application-layer validation alone.
Key Changes
Evolution 32 (
conf/evolutions/default/32.sql): Core schema updatespublication_idFK tosponsor_agreementsto support publication-level sponsorshipsunit_type = 'platform'for Gold tier agreements (single agreement covering entire site)sponsor_id,sponsor_label,sponsor_show_publiccolumns topublicationstable (matching existing pattern in seasons/collections/events)chk_agreement_tier_scopeconstraint to enforce tier-specific content scope:platform(all content)event,newsletter,publicationevent,publicationidx_sponsor_gold_exclusive: ensures max 1 active Gold agreement platform-wideidx_sponsor_silver_event_exclusive,idx_sponsor_silver_publication_exclusive,idx_sponsor_silver_newsletter_exclusive: ensures max 1 active Silver per unitsponsor_deliverablestypes with Gold-exclusive surfaces:homepage_banner,site_header_badgeTrigger (
sql/trigger_sponsor_bronze_limit.sql): Bronce concurrency enforcementenforce_bronze_sponsor_limit()function to enforce max 2 active Bronze agreements per unitDocumentation (
docs/SPONSOR_TIER_MODEL.md): Comprehensive business model specificationNotable Implementation Details
tiercolumn wheretier='gold' AND status='active', preventing database-level violations even if application logic failsunit_type, preventing data inconsistencyunit_type='platform'with no FK to specific content, allowing single agreement to cover all content surfaces!Downssection to safely rollback all changeshttps://claude.ai/code/session_011GvPuvd3UBUf1hPFRHNEza