feat: Initialize Fediversion multi-band platform

- Fork elmeg-demo codebase for multi-band support
- Add data importer infrastructure with base class
- Create band-specific importers:
  - phish.py: Phish.net API v5
  - grateful_dead.py: Grateful Stats API
  - setlistfm.py: Dead & Company, Billy Strings (Setlist.fm)
- Add spec-kit configuration for Gemini
- Update README with supported bands and architecture
This commit is contained in:
fullsizemalt 2025-12-28 12:39:28 -08:00
commit b4cddf41ea
306 changed files with 62807 additions and 0 deletions

View file

@ -0,0 +1,73 @@
---
description: how to deploy elmeg changes safely
---
# Elmeg Safe Deployment
## CRITICAL: Never wipe the database
When deploying changes to elmeg, **ONLY rebuild the backend and frontend containers**. The database must NEVER be rebuilt or recreated.
## Safe deployment command
### Production (`elmeg.xyz`) - tangible-aacorn
```bash
# turbo
ssh tangible-aacorn "cd /srv/containers/elmeg-demo && git pull && docker compose up -d --build --no-deps backend frontend"
```
### Staging (`elmeg.runfoo.run`) - nexus-vector
```bash
# turbo
ssh nexus-vector "cd /srv/containers/elmeg-demo && git pull && docker compose up -d --build --no-deps backend frontend"
```
## DANGEROUS - Do NOT use these commands
```bash
# These will WIPE THE DATABASE:
docker compose up -d --build # Rebuilds ALL containers including db
docker compose down && docker compose up -d # Recreates all containers
docker compose up -d --force-recreate # Force recreates all
```
## Backup before any deployment (optional but recommended)
```bash
# turbo
ssh nexus-vector "docker exec elmeg-demo-db-1 pg_dump -U elmeg elmeg > /srv/containers/elmeg-demo/backup-\$(date +%Y%m%d-%H%M%S).sql"
```
## Restore from backup if needed
```bash
ssh nexus-vector "cat /srv/containers/elmeg-demo/backup-YYYYMMDD-HHMMSS.sql | docker exec -i elmeg-demo-db-1 psql -U elmeg elmeg"
```
## Data Import (Recovery)
If the database is wiped or fresh, use the Smart Import script to populate shows and setlists. This script is memory-optimized and checks for infinite loops.
### Production (tangible-aacorn)
```bash
ssh tangible-aacorn "docker exec elmeg-backend-1 python import_setlists_smart.py"
```
### Staging (nexus-vector)
```bash
ssh nexus-vector "docker exec elmeg-demo-backend-1 python import_setlists_smart.py"
```
## Git Configuration (Production)
To ensure `git pull` works correctly on production:
```bash
# On nexus-vector
cd /srv/containers/elmeg-demo
git branch --set-upstream-to=origin/main main
```

View file

@ -0,0 +1,41 @@
name: Deploy Elmeg
on:
push:
branches:
- testing
- production
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set deployment target
id: target
run: |
if [ "${{ github.ref_name }}" = "testing" ]; then
echo "server=nexus-vector" >> $GITHUB_OUTPUT
echo "domain=elmeg.runfoo.run" >> $GITHUB_OUTPUT
elif [ "${{ github.ref_name }}" = "production" ]; then
echo "server=tangible-aacorn" >> $GITHUB_OUTPUT
echo "domain=elmeg.xyz" >> $GITHUB_OUTPUT
fi
- name: Deploy to ${{ steps.target.outputs.server }}
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ steps.target.outputs.server == 'nexus-vector' && '216.158.230.94' || '159.69.219.254' }}
username: root
key: ${{ secrets.DEPLOY_SSH_KEY }}
script: |
cd /srv/containers/elmeg-demo
git fetch origin ${{ github.ref_name }}
git checkout ${{ github.ref_name }}
git reset --hard origin/${{ github.ref_name }}
docker compose build --no-cache
docker compose up -d
docker compose exec -T backend alembic upgrade head
echo "Deployed ${{ github.ref_name }} to ${{ steps.target.outputs.domain }}"

View file

@ -0,0 +1,188 @@
description = "Perform a non-destructive cross-artifact consistency and quality analysis across spec.md, plan.md, and tasks.md after task generation."
prompt = """
---
description: Perform a non-destructive cross-artifact consistency and quality analysis across spec.md, plan.md, and tasks.md after task generation.
---
## User Input
```text
$ARGUMENTS
```
You **MUST** consider the user input before proceeding (if not empty).
## Goal
Identify inconsistencies, duplications, ambiguities, and underspecified items across the three core artifacts (`spec.md`, `plan.md`, `tasks.md`) before implementation. This command MUST run only after `/speckit.tasks` has successfully produced a complete `tasks.md`.
## Operating Constraints
**STRICTLY READ-ONLY**: Do **not** modify any files. Output a structured analysis report. Offer an optional remediation plan (user must explicitly approve before any follow-up editing commands would be invoked manually).
**Constitution Authority**: The project constitution (`.specify/memory/constitution.md`) is **non-negotiable** within this analysis scope. Constitution conflicts are automatically CRITICAL and require adjustment of the spec, plan, or tasksnot dilution, reinterpretation, or silent ignoring of the principle. If a principle itself needs to change, that must occur in a separate, explicit constitution update outside `/speckit.analyze`.
## Execution Steps
### 1. Initialize Analysis Context
Run `.specify/scripts/bash/check-prerequisites.sh --json --require-tasks --include-tasks` once from repo root and parse JSON for FEATURE_DIR and AVAILABLE_DOCS. Derive absolute paths:
- SPEC = FEATURE_DIR/spec.md
- PLAN = FEATURE_DIR/plan.md
- TASKS = FEATURE_DIR/tasks.md
Abort with an error message if any required file is missing (instruct the user to run missing prerequisite command).
For single quotes in args like "I'm Groot", use escape syntax: e.g 'I'\\''m Groot' (or double-quote if possible: "I'm Groot").
### 2. Load Artifacts (Progressive Disclosure)
Load only the minimal necessary context from each artifact:
**From spec.md:**
- Overview/Context
- Functional Requirements
- Non-Functional Requirements
- User Stories
- Edge Cases (if present)
**From plan.md:**
- Architecture/stack choices
- Data Model references
- Phases
- Technical constraints
**From tasks.md:**
- Task IDs
- Descriptions
- Phase grouping
- Parallel markers [P]
- Referenced file paths
**From constitution:**
- Load `.specify/memory/constitution.md` for principle validation
### 3. Build Semantic Models
Create internal representations (do not include raw artifacts in output):
- **Requirements inventory**: Each functional + non-functional requirement with a stable key (derive slug based on imperative phrase; e.g., "User can upload file" `user-can-upload-file`)
- **User story/action inventory**: Discrete user actions with acceptance criteria
- **Task coverage mapping**: Map each task to one or more requirements or stories (inference by keyword / explicit reference patterns like IDs or key phrases)
- **Constitution rule set**: Extract principle names and MUST/SHOULD normative statements
### 4. Detection Passes (Token-Efficient Analysis)
Focus on high-signal findings. Limit to 50 findings total; aggregate remainder in overflow summary.
#### A. Duplication Detection
- Identify near-duplicate requirements
- Mark lower-quality phrasing for consolidation
#### B. Ambiguity Detection
- Flag vague adjectives (fast, scalable, secure, intuitive, robust) lacking measurable criteria
- Flag unresolved placeholders (TODO, TKTK, ???, `<placeholder>`, etc.)
#### C. Underspecification
- Requirements with verbs but missing object or measurable outcome
- User stories missing acceptance criteria alignment
- Tasks referencing files or components not defined in spec/plan
#### D. Constitution Alignment
- Any requirement or plan element conflicting with a MUST principle
- Missing mandated sections or quality gates from constitution
#### E. Coverage Gaps
- Requirements with zero associated tasks
- Tasks with no mapped requirement/story
- Non-functional requirements not reflected in tasks (e.g., performance, security)
#### F. Inconsistency
- Terminology drift (same concept named differently across files)
- Data entities referenced in plan but absent in spec (or vice versa)
- Task ordering contradictions (e.g., integration tasks before foundational setup tasks without dependency note)
- Conflicting requirements (e.g., one requires Next.js while other specifies Vue)
### 5. Severity Assignment
Use this heuristic to prioritize findings:
- **CRITICAL**: Violates constitution MUST, missing core spec artifact, or requirement with zero coverage that blocks baseline functionality
- **HIGH**: Duplicate or conflicting requirement, ambiguous security/performance attribute, untestable acceptance criterion
- **MEDIUM**: Terminology drift, missing non-functional task coverage, underspecified edge case
- **LOW**: Style/wording improvements, minor redundancy not affecting execution order
### 6. Produce Compact Analysis Report
Output a Markdown report (no file writes) with the following structure:
## Specification Analysis Report
| ID | Category | Severity | Location(s) | Summary | Recommendation |
|----|----------|----------|-------------|---------|----------------|
| A1 | Duplication | HIGH | spec.md:L120-134 | Two similar requirements ... | Merge phrasing; keep clearer version |
(Add one row per finding; generate stable IDs prefixed by category initial.)
**Coverage Summary Table:**
| Requirement Key | Has Task? | Task IDs | Notes |
|-----------------|-----------|----------|-------|
**Constitution Alignment Issues:** (if any)
**Unmapped Tasks:** (if any)
**Metrics:**
- Total Requirements
- Total Tasks
- Coverage % (requirements with >=1 task)
- Ambiguity Count
- Duplication Count
- Critical Issues Count
### 7. Provide Next Actions
At end of report, output a concise Next Actions block:
- If CRITICAL issues exist: Recommend resolving before `/speckit.implement`
- If only LOW/MEDIUM: User may proceed, but provide improvement suggestions
- Provide explicit command suggestions: e.g., "Run /speckit.specify with refinement", "Run /speckit.plan to adjust architecture", "Manually edit tasks.md to add coverage for 'performance-metrics'"
### 8. Offer Remediation
Ask the user: "Would you like me to suggest concrete remediation edits for the top N issues?" (Do NOT apply them automatically.)
## Operating Principles
### Context Efficiency
- **Minimal high-signal tokens**: Focus on actionable findings, not exhaustive documentation
- **Progressive disclosure**: Load artifacts incrementally; don't dump all content into analysis
- **Token-efficient output**: Limit findings table to 50 rows; summarize overflow
- **Deterministic results**: Rerunning without changes should produce consistent IDs and counts
### Analysis Guidelines
- **NEVER modify files** (this is read-only analysis)
- **NEVER hallucinate missing sections** (if absent, report them accurately)
- **Prioritize constitution violations** (these are always CRITICAL)
- **Use examples over exhaustive rules** (cite specific instances, not generic patterns)
- **Report zero issues gracefully** (emit success report with coverage statistics)
## Context
{{args}}
"""

View file

@ -0,0 +1,298 @@
description = "Generate a custom checklist for the current feature based on user requirements."
prompt = """
---
description: Generate a custom checklist for the current feature based on user requirements.
---
## Checklist Purpose: "Unit Tests for English"
**CRITICAL CONCEPT**: Checklists are **UNIT TESTS FOR REQUIREMENTS WRITING** - they validate the quality, clarity, and completeness of requirements in a given domain.
**NOT for verification/testing**:
- NOT "Verify the button clicks correctly"
- NOT "Test error handling works"
- NOT "Confirm the API returns 200"
- NOT checking if code/implementation matches the spec
**FOR requirements quality validation**:
- "Are visual hierarchy requirements defined for all card types?" (completeness)
- "Is 'prominent display' quantified with specific sizing/positioning?" (clarity)
- "Are hover state requirements consistent across all interactive elements?" (consistency)
- "Are accessibility requirements defined for keyboard navigation?" (coverage)
- "Does the spec define what happens when logo image fails to load?" (edge cases)
**Metaphor**: If your spec is code written in English, the checklist is its unit test suite. You're testing whether the requirements are well-written, complete, unambiguous, and ready for implementation - NOT whether the implementation works.
## User Input
```text
$ARGUMENTS
```
You **MUST** consider the user input before proceeding (if not empty).
## Execution Steps
1. **Setup**: Run `.specify/scripts/bash/check-prerequisites.sh --json` from repo root and parse JSON for FEATURE_DIR and AVAILABLE_DOCS list.
- All file paths must be absolute.
- For single quotes in args like "I'm Groot", use escape syntax: e.g 'I'\\''m Groot' (or double-quote if possible: "I'm Groot").
2. **Clarify intent (dynamic)**: Derive up to THREE initial contextual clarifying questions (no pre-baked catalog). They MUST:
- Be generated from the user's phrasing + extracted signals from spec/plan/tasks
- Only ask about information that materially changes checklist content
- Be skipped individually if already unambiguous in `$ARGUMENTS`
- Prefer precision over breadth
Generation algorithm:
1. Extract signals: feature domain keywords (e.g., auth, latency, UX, API), risk indicators ("critical", "must", "compliance"), stakeholder hints ("QA", "review", "security team"), and explicit deliverables ("a11y", "rollback", "contracts").
2. Cluster signals into candidate focus areas (max 4) ranked by relevance.
3. Identify probable audience & timing (author, reviewer, QA, release) if not explicit.
4. Detect missing dimensions: scope breadth, depth/rigor, risk emphasis, exclusion boundaries, measurable acceptance criteria.
5. Formulate questions chosen from these archetypes:
- Scope refinement (e.g., "Should this include integration touchpoints with X and Y or stay limited to local module correctness?")
- Risk prioritization (e.g., "Which of these potential risk areas should receive mandatory gating checks?")
- Depth calibration (e.g., "Is this a lightweight pre-commit sanity list or a formal release gate?")
- Audience framing (e.g., "Will this be used by the author only or peers during PR review?")
- Boundary exclusion (e.g., "Should we explicitly exclude performance tuning items this round?")
- Scenario class gap (e.g., "No recovery flows detected—are rollback / partial failure paths in scope?")
Question formatting rules:
- If presenting options, generate a compact table with columns: Option | Candidate | Why It Matters
- Limit to AE options maximum; omit table if a free-form answer is clearer
- Never ask the user to restate what they already said
- Avoid speculative categories (no hallucination). If uncertain, ask explicitly: "Confirm whether X belongs in scope."
Defaults when interaction impossible:
- Depth: Standard
- Audience: Reviewer (PR) if code-related; Author otherwise
- Focus: Top 2 relevance clusters
Output the questions (label Q1/Q2/Q3). After answers: if 2 scenario classes (Alternate / Exception / Recovery / Non-Functional domain) remain unclear, you MAY ask up to TWO more targeted followups (Q4/Q5) with a one-line justification each (e.g., "Unresolved recovery path risk"). Do not exceed five total questions. Skip escalation if user explicitly declines more.
3. **Understand user request**: Combine `$ARGUMENTS` + clarifying answers:
- Derive checklist theme (e.g., security, review, deploy, ux)
- Consolidate explicit must-have items mentioned by user
- Map focus selections to category scaffolding
- Infer any missing context from spec/plan/tasks (do NOT hallucinate)
4. **Load feature context**: Read from FEATURE_DIR:
- spec.md: Feature requirements and scope
- plan.md (if exists): Technical details, dependencies
- tasks.md (if exists): Implementation tasks
**Context Loading Strategy**:
- Load only necessary portions relevant to active focus areas (avoid full-file dumping)
- Prefer summarizing long sections into concise scenario/requirement bullets
- Use progressive disclosure: add follow-on retrieval only if gaps detected
- If source docs are large, generate interim summary items instead of embedding raw text
5. **Generate checklist** - Create "Unit Tests for Requirements":
- Create `FEATURE_DIR/checklists/` directory if it doesn't exist
- Generate unique checklist filename:
- Use short, descriptive name based on domain (e.g., `ux.md`, `api.md`, `security.md`)
- Format: `[domain].md`
- If file exists, append to existing file
- Number items sequentially starting from CHK001
- Each `/speckit.checklist` run creates a NEW file (never overwrites existing checklists)
**CORE PRINCIPLE - Test the Requirements, Not the Implementation**:
Every checklist item MUST evaluate the REQUIREMENTS THEMSELVES for:
- **Completeness**: Are all necessary requirements present?
- **Clarity**: Are requirements unambiguous and specific?
- **Consistency**: Do requirements align with each other?
- **Measurability**: Can requirements be objectively verified?
- **Coverage**: Are all scenarios/edge cases addressed?
**Category Structure** - Group items by requirement quality dimensions:
- **Requirement Completeness** (Are all necessary requirements documented?)
- **Requirement Clarity** (Are requirements specific and unambiguous?)
- **Requirement Consistency** (Do requirements align without conflicts?)
- **Acceptance Criteria Quality** (Are success criteria measurable?)
- **Scenario Coverage** (Are all flows/cases addressed?)
- **Edge Case Coverage** (Are boundary conditions defined?)
- **Non-Functional Requirements** (Performance, Security, Accessibility, etc. - are they specified?)
- **Dependencies & Assumptions** (Are they documented and validated?)
- **Ambiguities & Conflicts** (What needs clarification?)
**HOW TO WRITE CHECKLIST ITEMS - "Unit Tests for English"**:
**WRONG** (Testing implementation):
- "Verify landing page displays 3 episode cards"
- "Test hover states work on desktop"
- "Confirm logo click navigates home"
**CORRECT** (Testing requirements quality):
- "Are the exact number and layout of featured episodes specified?" [Completeness]
- "Is 'prominent display' quantified with specific sizing/positioning?" [Clarity]
- "Are hover state requirements consistent across all interactive elements?" [Consistency]
- "Are keyboard navigation requirements defined for all interactive UI?" [Coverage]
- "Is the fallback behavior specified when logo image fails to load?" [Edge Cases]
- "Are loading states defined for asynchronous episode data?" [Completeness]
- "Does the spec define visual hierarchy for competing UI elements?" [Clarity]
**ITEM STRUCTURE**:
Each item should follow this pattern:
- Question format asking about requirement quality
- Focus on what's WRITTEN (or not written) in the spec/plan
- Include quality dimension in brackets [Completeness/Clarity/Consistency/etc.]
- Reference spec section `[Spec §X.Y]` when checking existing requirements
- Use `[Gap]` marker when checking for missing requirements
**EXAMPLES BY QUALITY DIMENSION**:
Completeness:
- "Are error handling requirements defined for all API failure modes? [Gap]"
- "Are accessibility requirements specified for all interactive elements? [Completeness]"
- "Are mobile breakpoint requirements defined for responsive layouts? [Gap]"
Clarity:
- "Is 'fast loading' quantified with specific timing thresholds? [Clarity, Spec §NFR-2]"
- "Are 'related episodes' selection criteria explicitly defined? [Clarity, Spec §FR-5]"
- "Is 'prominent' defined with measurable visual properties? [Ambiguity, Spec §FR-4]"
Consistency:
- "Do navigation requirements align across all pages? [Consistency, Spec §FR-10]"
- "Are card component requirements consistent between landing and detail pages? [Consistency]"
Coverage:
- "Are requirements defined for zero-state scenarios (no episodes)? [Coverage, Edge Case]"
- "Are concurrent user interaction scenarios addressed? [Coverage, Gap]"
- "Are requirements specified for partial data loading failures? [Coverage, Exception Flow]"
Measurability:
- "Are visual hierarchy requirements measurable/testable? [Acceptance Criteria, Spec §FR-1]"
- "Can 'balanced visual weight' be objectively verified? [Measurability, Spec §FR-2]"
**Scenario Classification & Coverage** (Requirements Quality Focus):
- Check if requirements exist for: Primary, Alternate, Exception/Error, Recovery, Non-Functional scenarios
- For each scenario class, ask: "Are [scenario type] requirements complete, clear, and consistent?"
- If scenario class missing: "Are [scenario type] requirements intentionally excluded or missing? [Gap]"
- Include resilience/rollback when state mutation occurs: "Are rollback requirements defined for migration failures? [Gap]"
**Traceability Requirements**:
- MINIMUM: 80% of items MUST include at least one traceability reference
- Each item should reference: spec section `[Spec §X.Y]`, or use markers: `[Gap]`, `[Ambiguity]`, `[Conflict]`, `[Assumption]`
- If no ID system exists: "Is a requirement & acceptance criteria ID scheme established? [Traceability]"
**Surface & Resolve Issues** (Requirements Quality Problems):
Ask questions about the requirements themselves:
- Ambiguities: "Is the term 'fast' quantified with specific metrics? [Ambiguity, Spec §NFR-1]"
- Conflicts: "Do navigation requirements conflict between §FR-10 and §FR-10a? [Conflict]"
- Assumptions: "Is the assumption of 'always available podcast API' validated? [Assumption]"
- Dependencies: "Are external podcast API requirements documented? [Dependency, Gap]"
- Missing definitions: "Is 'visual hierarchy' defined with measurable criteria? [Gap]"
**Content Consolidation**:
- Soft cap: If raw candidate items > 40, prioritize by risk/impact
- Merge near-duplicates checking the same requirement aspect
- If >5 low-impact edge cases, create one item: "Are edge cases X, Y, Z addressed in requirements? [Coverage]"
**🚫 ABSOLUTELY PROHIBITED** - These make it an implementation test, not a requirements test:
- Any item starting with "Verify", "Test", "Confirm", "Check" + implementation behavior
- References to code execution, user actions, system behavior
- "Displays correctly", "works properly", "functions as expected"
- "Click", "navigate", "render", "load", "execute"
- Test cases, test plans, QA procedures
- Implementation details (frameworks, APIs, algorithms)
** REQUIRED PATTERNS** - These test requirements quality:
- "Are [requirement type] defined/specified/documented for [scenario]?"
- "Is [vague term] quantified/clarified with specific criteria?"
- "Are requirements consistent between [section A] and [section B]?"
- "Can [requirement] be objectively measured/verified?"
- "Are [edge cases/scenarios] addressed in requirements?"
- "Does the spec define [missing aspect]?"
6. **Structure Reference**: Generate the checklist following the canonical template in `.specify/templates/checklist-template.md` for title, meta section, category headings, and ID formatting. If template is unavailable, use: H1 title, purpose/created meta lines, `##` category sections containing `- [ ] CHK### <requirement item>` lines with globally incrementing IDs starting at CHK001.
7. **Report**: Output full path to created checklist, item count, and remind user that each run creates a new file. Summarize:
- Focus areas selected
- Depth level
- Actor/timing
- Any explicit user-specified must-have items incorporated
**Important**: Each `/speckit.checklist` command invocation creates a checklist file using short, descriptive names unless file already exists. This allows:
- Multiple checklists of different types (e.g., `ux.md`, `test.md`, `security.md`)
- Simple, memorable filenames that indicate checklist purpose
- Easy identification and navigation in the `checklists/` folder
To avoid clutter, use descriptive types and clean up obsolete checklists when done.
## Example Checklist Types & Sample Items
**UX Requirements Quality:** `ux.md`
Sample items (testing the requirements, NOT the implementation):
- "Are visual hierarchy requirements defined with measurable criteria? [Clarity, Spec §FR-1]"
- "Is the number and positioning of UI elements explicitly specified? [Completeness, Spec §FR-1]"
- "Are interaction state requirements (hover, focus, active) consistently defined? [Consistency]"
- "Are accessibility requirements specified for all interactive elements? [Coverage, Gap]"
- "Is fallback behavior defined when images fail to load? [Edge Case, Gap]"
- "Can 'prominent display' be objectively measured? [Measurability, Spec §FR-4]"
**API Requirements Quality:** `api.md`
Sample items:
- "Are error response formats specified for all failure scenarios? [Completeness]"
- "Are rate limiting requirements quantified with specific thresholds? [Clarity]"
- "Are authentication requirements consistent across all endpoints? [Consistency]"
- "Are retry/timeout requirements defined for external dependencies? [Coverage, Gap]"
- "Is versioning strategy documented in requirements? [Gap]"
**Performance Requirements Quality:** `performance.md`
Sample items:
- "Are performance requirements quantified with specific metrics? [Clarity]"
- "Are performance targets defined for all critical user journeys? [Coverage]"
- "Are performance requirements under different load conditions specified? [Completeness]"
- "Can performance requirements be objectively measured? [Measurability]"
- "Are degradation requirements defined for high-load scenarios? [Edge Case, Gap]"
**Security Requirements Quality:** `security.md`
Sample items:
- "Are authentication requirements specified for all protected resources? [Coverage]"
- "Are data protection requirements defined for sensitive information? [Completeness]"
- "Is the threat model documented and requirements aligned to it? [Traceability]"
- "Are security requirements consistent with compliance obligations? [Consistency]"
- "Are security failure/breach response requirements defined? [Gap, Exception Flow]"
## Anti-Examples: What NOT To Do
** WRONG - These test implementation, not requirements:**
```markdown
- [ ] CHK001 - Verify landing page displays 3 episode cards [Spec §FR-001]
- [ ] CHK002 - Test hover states work correctly on desktop [Spec §FR-003]
- [ ] CHK003 - Confirm logo click navigates to home page [Spec §FR-010]
- [ ] CHK004 - Check that related episodes section shows 3-5 items [Spec §FR-005]
```
** CORRECT - These test requirements quality:**
```markdown
- [ ] CHK001 - Are the number and layout of featured episodes explicitly specified? [Completeness, Spec §FR-001]
- [ ] CHK002 - Are hover state requirements consistently defined for all interactive elements? [Consistency, Spec §FR-003]
- [ ] CHK003 - Are navigation requirements clear for all clickable brand elements? [Clarity, Spec §FR-010]
- [ ] CHK004 - Is the selection criteria for related episodes documented? [Gap, Spec §FR-005]
- [ ] CHK005 - Are loading state requirements defined for asynchronous episode data? [Gap]
- [ ] CHK006 - Can "visual hierarchy" requirements be objectively measured? [Measurability, Spec §FR-001]
```
**Key Differences:**
- Wrong: Tests if the system works correctly
- Correct: Tests if the requirements are written correctly
- Wrong: Verification of behavior
- Correct: Validation of requirement quality
- Wrong: "Does it do X?"
- Correct: "Is X clearly specified?"
"""

View file

@ -0,0 +1,185 @@
description = "Identify underspecified areas in the current feature spec by asking up to 5 highly targeted clarification questions and encoding answers back into the spec."
prompt = """
---
description: Identify underspecified areas in the current feature spec by asking up to 5 highly targeted clarification questions and encoding answers back into the spec.
handoffs:
- label: Build Technical Plan
agent: speckit.plan
prompt: Create a plan for the spec. I am building with...
---
## User Input
```text
$ARGUMENTS
```
You **MUST** consider the user input before proceeding (if not empty).
## Outline
Goal: Detect and reduce ambiguity or missing decision points in the active feature specification and record the clarifications directly in the spec file.
Note: This clarification workflow is expected to run (and be completed) BEFORE invoking `/speckit.plan`. If the user explicitly states they are skipping clarification (e.g., exploratory spike), you may proceed, but must warn that downstream rework risk increases.
Execution steps:
1. Run `.specify/scripts/bash/check-prerequisites.sh --json --paths-only` from repo root **once** (combined `--json --paths-only` mode / `-Json -PathsOnly`). Parse minimal JSON payload fields:
- `FEATURE_DIR`
- `FEATURE_SPEC`
- (Optionally capture `IMPL_PLAN`, `TASKS` for future chained flows.)
- If JSON parsing fails, abort and instruct user to re-run `/speckit.specify` or verify feature branch environment.
- For single quotes in args like "I'm Groot", use escape syntax: e.g 'I'\\''m Groot' (or double-quote if possible: "I'm Groot").
2. Load the current spec file. Perform a structured ambiguity & coverage scan using this taxonomy. For each category, mark status: Clear / Partial / Missing. Produce an internal coverage map used for prioritization (do not output raw map unless no questions will be asked).
Functional Scope & Behavior:
- Core user goals & success criteria
- Explicit out-of-scope declarations
- User roles / personas differentiation
Domain & Data Model:
- Entities, attributes, relationships
- Identity & uniqueness rules
- Lifecycle/state transitions
- Data volume / scale assumptions
Interaction & UX Flow:
- Critical user journeys / sequences
- Error/empty/loading states
- Accessibility or localization notes
Non-Functional Quality Attributes:
- Performance (latency, throughput targets)
- Scalability (horizontal/vertical, limits)
- Reliability & availability (uptime, recovery expectations)
- Observability (logging, metrics, tracing signals)
- Security & privacy (authN/Z, data protection, threat assumptions)
- Compliance / regulatory constraints (if any)
Integration & External Dependencies:
- External services/APIs and failure modes
- Data import/export formats
- Protocol/versioning assumptions
Edge Cases & Failure Handling:
- Negative scenarios
- Rate limiting / throttling
- Conflict resolution (e.g., concurrent edits)
Constraints & Tradeoffs:
- Technical constraints (language, storage, hosting)
- Explicit tradeoffs or rejected alternatives
Terminology & Consistency:
- Canonical glossary terms
- Avoided synonyms / deprecated terms
Completion Signals:
- Acceptance criteria testability
- Measurable Definition of Done style indicators
Misc / Placeholders:
- TODO markers / unresolved decisions
- Ambiguous adjectives ("robust", "intuitive") lacking quantification
For each category with Partial or Missing status, add a candidate question opportunity unless:
- Clarification would not materially change implementation or validation strategy
- Information is better deferred to planning phase (note internally)
3. Generate (internally) a prioritized queue of candidate clarification questions (maximum 5). Do NOT output them all at once. Apply these constraints:
- Maximum of 10 total questions across the whole session.
- Each question must be answerable with EITHER:
- A short multiplechoice selection (25 distinct, mutually exclusive options), OR
- A one-word / shortphrase answer (explicitly constrain: "Answer in <=5 words").
- Only include questions whose answers materially impact architecture, data modeling, task decomposition, test design, UX behavior, operational readiness, or compliance validation.
- Ensure category coverage balance: attempt to cover the highest impact unresolved categories first; avoid asking two low-impact questions when a single high-impact area (e.g., security posture) is unresolved.
- Exclude questions already answered, trivial stylistic preferences, or plan-level execution details (unless blocking correctness).
- Favor clarifications that reduce downstream rework risk or prevent misaligned acceptance tests.
- If more than 5 categories remain unresolved, select the top 5 by (Impact * Uncertainty) heuristic.
4. Sequential questioning loop (interactive):
- Present EXACTLY ONE question at a time.
- For multiplechoice questions:
- **Analyze all options** and determine the **most suitable option** based on:
- Best practices for the project type
- Common patterns in similar implementations
- Risk reduction (security, performance, maintainability)
- Alignment with any explicit project goals or constraints visible in the spec
- Present your **recommended option prominently** at the top with clear reasoning (1-2 sentences explaining why this is the best choice).
- Format as: `**Recommended:** Option [X] - <reasoning>`
- Then render all options as a Markdown table:
| Option | Description |
|--------|-------------|
| A | <Option A description> |
| B | <Option B description> |
| C | <Option C description> (add D/E as needed up to 5) |
| Short | Provide a different short answer (<=5 words) (Include only if free-form alternative is appropriate) |
- After the table, add: `You can reply with the option letter (e.g., "A"), accept the recommendation by saying "yes" or "recommended", or provide your own short answer.`
- For shortanswer style (no meaningful discrete options):
- Provide your **suggested answer** based on best practices and context.
- Format as: `**Suggested:** <your proposed answer> - <brief reasoning>`
- Then output: `Format: Short answer (<=5 words). You can accept the suggestion by saying "yes" or "suggested", or provide your own answer.`
- After the user answers:
- If the user replies with "yes", "recommended", or "suggested", use your previously stated recommendation/suggestion as the answer.
- Otherwise, validate the answer maps to one option or fits the <=5 word constraint.
- If ambiguous, ask for a quick disambiguation (count still belongs to same question; do not advance).
- Once satisfactory, record it in working memory (do not yet write to disk) and move to the next queued question.
- Stop asking further questions when:
- All critical ambiguities resolved early (remaining queued items become unnecessary), OR
- User signals completion ("done", "good", "no more"), OR
- You reach 5 asked questions.
- Never reveal future queued questions in advance.
- If no valid questions exist at start, immediately report no critical ambiguities.
5. Integration after EACH accepted answer (incremental update approach):
- Maintain in-memory representation of the spec (loaded once at start) plus the raw file contents.
- For the first integrated answer in this session:
- Ensure a `## Clarifications` section exists (create it just after the highest-level contextual/overview section per the spec template if missing).
- Under it, create (if not present) a `### Session YYYY-MM-DD` subheading for today.
- Append a bullet line immediately after acceptance: `- Q: <question> A: <final answer>`.
- Then immediately apply the clarification to the most appropriate section(s):
- Functional ambiguity Update or add a bullet in Functional Requirements.
- User interaction / actor distinction Update User Stories or Actors subsection (if present) with clarified role, constraint, or scenario.
- Data shape / entities Update Data Model (add fields, types, relationships) preserving ordering; note added constraints succinctly.
- Non-functional constraint Add/modify measurable criteria in Non-Functional / Quality Attributes section (convert vague adjective to metric or explicit target).
- Edge case / negative flow Add a new bullet under Edge Cases / Error Handling (or create such subsection if template provides placeholder for it).
- Terminology conflict Normalize term across spec; retain original only if necessary by adding `(formerly referred to as "X")` once.
- If the clarification invalidates an earlier ambiguous statement, replace that statement instead of duplicating; leave no obsolete contradictory text.
- Save the spec file AFTER each integration to minimize risk of context loss (atomic overwrite).
- Preserve formatting: do not reorder unrelated sections; keep heading hierarchy intact.
- Keep each inserted clarification minimal and testable (avoid narrative drift).
6. Validation (performed after EACH write plus final pass):
- Clarifications session contains exactly one bullet per accepted answer (no duplicates).
- Total asked (accepted) questions 5.
- Updated sections contain no lingering vague placeholders the new answer was meant to resolve.
- No contradictory earlier statement remains (scan for now-invalid alternative choices removed).
- Markdown structure valid; only allowed new headings: `## Clarifications`, `### Session YYYY-MM-DD`.
- Terminology consistency: same canonical term used across all updated sections.
7. Write the updated spec back to `FEATURE_SPEC`.
8. Report completion (after questioning loop ends or early termination):
- Number of questions asked & answered.
- Path to updated spec.
- Sections touched (list names).
- Coverage summary table listing each taxonomy category with Status: Resolved (was Partial/Missing and addressed), Deferred (exceeds question quota or better suited for planning), Clear (already sufficient), Outstanding (still Partial/Missing but low impact).
- If any Outstanding or Deferred remain, recommend whether to proceed to `/speckit.plan` or run `/speckit.clarify` again later post-plan.
- Suggested next command.
Behavior rules:
- If no meaningful ambiguities found (or all potential questions would be low-impact), respond: "No critical ambiguities detected worth formal clarification." and suggest proceeding.
- If spec file missing, instruct user to run `/speckit.specify` first (do not create a new spec here).
- Never exceed 5 total asked questions (clarification retries for a single question do not count as new questions).
- Avoid speculative tech stack questions unless the absence blocks functional clarity.
- Respect user early termination signals ("stop", "done", "proceed").
- If no questions asked due to full coverage, output a compact coverage summary (all categories Clear) then suggest advancing.
- If quota reached with unresolved high-impact categories remaining, explicitly flag them under Deferred with rationale.
Context for prioritization: {{args}}
"""

View file

@ -0,0 +1,86 @@
description = "Create or update the project constitution from interactive or provided principle inputs, ensuring all dependent templates stay in sync."
prompt = """
---
description: Create or update the project constitution from interactive or provided principle inputs, ensuring all dependent templates stay in sync.
handoffs:
- label: Build Specification
agent: speckit.specify
prompt: Implement the feature specification based on the updated constitution. I want to build...
---
## User Input
```text
$ARGUMENTS
```
You **MUST** consider the user input before proceeding (if not empty).
## Outline
You are updating the project constitution at `.specify/memory/constitution.md`. This file is a TEMPLATE containing placeholder tokens in square brackets (e.g. `[PROJECT_NAME]`, `[PRINCIPLE_1_NAME]`). Your job is to (a) collect/derive concrete values, (b) fill the template precisely, and (c) propagate any amendments across dependent artifacts.
Follow this execution flow:
1. Load the existing constitution template at `.specify/memory/constitution.md`.
- Identify every placeholder token of the form `[ALL_CAPS_IDENTIFIER]`.
**IMPORTANT**: The user might require less or more principles than the ones used in the template. If a number is specified, respect that - follow the general template. You will update the doc accordingly.
2. Collect/derive values for placeholders:
- If user input (conversation) supplies a value, use it.
- Otherwise infer from existing repo context (README, docs, prior constitution versions if embedded).
- For governance dates: `RATIFICATION_DATE` is the original adoption date (if unknown ask or mark TODO), `LAST_AMENDED_DATE` is today if changes are made, otherwise keep previous.
- `CONSTITUTION_VERSION` must increment according to semantic versioning rules:
- MAJOR: Backward incompatible governance/principle removals or redefinitions.
- MINOR: New principle/section added or materially expanded guidance.
- PATCH: Clarifications, wording, typo fixes, non-semantic refinements.
- If version bump type ambiguous, propose reasoning before finalizing.
3. Draft the updated constitution content:
- Replace every placeholder with concrete text (no bracketed tokens left except intentionally retained template slots that the project has chosen not to define yetexplicitly justify any left).
- Preserve heading hierarchy and comments can be removed once replaced unless they still add clarifying guidance.
- Ensure each Principle section: succinct name line, paragraph (or bullet list) capturing nonnegotiable rules, explicit rationale if not obvious.
- Ensure Governance section lists amendment procedure, versioning policy, and compliance review expectations.
4. Consistency propagation checklist (convert prior checklist into active validations):
- Read `.specify/templates/plan-template.md` and ensure any "Constitution Check" or rules align with updated principles.
- Read `.specify/templates/spec-template.md` for scope/requirements alignmentupdate if constitution adds/removes mandatory sections or constraints.
- Read `.specify/templates/tasks-template.md` and ensure task categorization reflects new or removed principle-driven task types (e.g., observability, versioning, testing discipline).
- Read each command file in `.specify/templates/commands/*.md` (including this one) to verify no outdated references (agent-specific names like CLAUDE only) remain when generic guidance is required.
- Read any runtime guidance docs (e.g., `README.md`, `docs/quickstart.md`, or agent-specific guidance files if present). Update references to principles changed.
5. Produce a Sync Impact Report (prepend as an HTML comment at top of the constitution file after update):
- Version change: old new
- List of modified principles (old title new title if renamed)
- Added sections
- Removed sections
- Templates requiring updates ( updated / pending) with file paths
- Follow-up TODOs if any placeholders intentionally deferred.
6. Validation before final output:
- No remaining unexplained bracket tokens.
- Version line matches report.
- Dates ISO format YYYY-MM-DD.
- Principles are declarative, testable, and free of vague language ("should" replace with MUST/SHOULD rationale where appropriate).
7. Write the completed constitution back to `.specify/memory/constitution.md` (overwrite).
8. Output a final summary to the user with:
- New version and bump rationale.
- Any files flagged for manual follow-up.
- Suggested commit message (e.g., `docs: amend constitution to vX.Y.Z (principle additions + governance update)`).
Formatting & Style Requirements:
- Use Markdown headings exactly as in the template (do not demote/promote levels).
- Wrap long rationale lines to keep readability (<100 chars ideally) but do not hard enforce with awkward breaks.
- Keep a single blank line between sections.
- Avoid trailing whitespace.
If the user supplies partial updates (e.g., only one principle revision), still perform validation and version decision steps.
If critical info missing (e.g., ratification date truly unknown), insert `TODO(<FIELD_NAME>): explanation` and include in the Sync Impact Report under deferred items.
Do not create a new template; always operate on the existing `.specify/memory/constitution.md` file.
"""

View file

@ -0,0 +1,139 @@
description = "Execute the implementation plan by processing and executing all tasks defined in tasks.md"
prompt = """
---
description: Execute the implementation plan by processing and executing all tasks defined in tasks.md
---
## User Input
```text
$ARGUMENTS
```
You **MUST** consider the user input before proceeding (if not empty).
## Outline
1. Run `.specify/scripts/bash/check-prerequisites.sh --json --require-tasks --include-tasks` from repo root and parse FEATURE_DIR and AVAILABLE_DOCS list. All paths must be absolute. For single quotes in args like "I'm Groot", use escape syntax: e.g 'I'\\''m Groot' (or double-quote if possible: "I'm Groot").
2. **Check checklists status** (if FEATURE_DIR/checklists/ exists):
- Scan all checklist files in the checklists/ directory
- For each checklist, count:
- Total items: All lines matching `- [ ]` or `- [X]` or `- [x]`
- Completed items: Lines matching `- [X]` or `- [x]`
- Incomplete items: Lines matching `- [ ]`
- Create a status table:
```text
| Checklist | Total | Completed | Incomplete | Status |
|-----------|-------|-----------|------------|--------|
| ux.md | 12 | 12 | 0 | PASS |
| test.md | 8 | 5 | 3 | FAIL |
| security.md | 6 | 6 | 0 | PASS |
```
- Calculate overall status:
- **PASS**: All checklists have 0 incomplete items
- **FAIL**: One or more checklists have incomplete items
- **If any checklist is incomplete**:
- Display the table with incomplete item counts
- **STOP** and ask: "Some checklists are incomplete. Do you want to proceed with implementation anyway? (yes/no)"
- Wait for user response before continuing
- If user says "no" or "wait" or "stop", halt execution
- If user says "yes" or "proceed" or "continue", proceed to step 3
- **If all checklists are complete**:
- Display the table showing all checklists passed
- Automatically proceed to step 3
3. Load and analyze the implementation context:
- **REQUIRED**: Read tasks.md for the complete task list and execution plan
- **REQUIRED**: Read plan.md for tech stack, architecture, and file structure
- **IF EXISTS**: Read data-model.md for entities and relationships
- **IF EXISTS**: Read contracts/ for API specifications and test requirements
- **IF EXISTS**: Read research.md for technical decisions and constraints
- **IF EXISTS**: Read quickstart.md for integration scenarios
4. **Project Setup Verification**:
- **REQUIRED**: Create/verify ignore files based on actual project setup:
**Detection & Creation Logic**:
- Check if the following command succeeds to determine if the repository is a git repo (create/verify .gitignore if so):
```sh
git rev-parse --git-dir 2>/dev/null
```
- Check if Dockerfile* exists or Docker in plan.md create/verify .dockerignore
- Check if .eslintrc* exists create/verify .eslintignore
- Check if eslint.config.* exists ensure the config's `ignores` entries cover required patterns
- Check if .prettierrc* exists create/verify .prettierignore
- Check if .npmrc or package.json exists create/verify .npmignore (if publishing)
- Check if terraform files (*.tf) exist create/verify .terraformignore
- Check if .helmignore needed (helm charts present) create/verify .helmignore
**If ignore file already exists**: Verify it contains essential patterns, append missing critical patterns only
**If ignore file missing**: Create with full pattern set for detected technology
**Common Patterns by Technology** (from plan.md tech stack):
- **Node.js/JavaScript/TypeScript**: `node_modules/`, `dist/`, `build/`, `*.log`, `.env*`
- **Python**: `__pycache__/`, `*.pyc`, `.venv/`, `venv/`, `dist/`, `*.egg-info/`
- **Java**: `target/`, `*.class`, `*.jar`, `.gradle/`, `build/`
- **C#/.NET**: `bin/`, `obj/`, `*.user`, `*.suo`, `packages/`
- **Go**: `*.exe`, `*.test`, `vendor/`, `*.out`
- **Ruby**: `.bundle/`, `log/`, `tmp/`, `*.gem`, `vendor/bundle/`
- **PHP**: `vendor/`, `*.log`, `*.cache`, `*.env`
- **Rust**: `target/`, `debug/`, `release/`, `*.rs.bk`, `*.rlib`, `*.prof*`, `.idea/`, `*.log`, `.env*`
- **Kotlin**: `build/`, `out/`, `.gradle/`, `.idea/`, `*.class`, `*.jar`, `*.iml`, `*.log`, `.env*`
- **C++**: `build/`, `bin/`, `obj/`, `out/`, `*.o`, `*.so`, `*.a`, `*.exe`, `*.dll`, `.idea/`, `*.log`, `.env*`
- **C**: `build/`, `bin/`, `obj/`, `out/`, `*.o`, `*.a`, `*.so`, `*.exe`, `Makefile`, `config.log`, `.idea/`, `*.log`, `.env*`
- **Swift**: `.build/`, `DerivedData/`, `*.swiftpm/`, `Packages/`
- **R**: `.Rproj.user/`, `.Rhistory`, `.RData`, `.Ruserdata`, `*.Rproj`, `packrat/`, `renv/`
- **Universal**: `.DS_Store`, `Thumbs.db`, `*.tmp`, `*.swp`, `.vscode/`, `.idea/`
**Tool-Specific Patterns**:
- **Docker**: `node_modules/`, `.git/`, `Dockerfile*`, `.dockerignore`, `*.log*`, `.env*`, `coverage/`
- **ESLint**: `node_modules/`, `dist/`, `build/`, `coverage/`, `*.min.js`
- **Prettier**: `node_modules/`, `dist/`, `build/`, `coverage/`, `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`
- **Terraform**: `.terraform/`, `*.tfstate*`, `*.tfvars`, `.terraform.lock.hcl`
- **Kubernetes/k8s**: `*.secret.yaml`, `secrets/`, `.kube/`, `kubeconfig*`, `*.key`, `*.crt`
5. Parse tasks.md structure and extract:
- **Task phases**: Setup, Tests, Core, Integration, Polish
- **Task dependencies**: Sequential vs parallel execution rules
- **Task details**: ID, description, file paths, parallel markers [P]
- **Execution flow**: Order and dependency requirements
6. Execute implementation following the task plan:
- **Phase-by-phase execution**: Complete each phase before moving to the next
- **Respect dependencies**: Run sequential tasks in order, parallel tasks [P] can run together
- **Follow TDD approach**: Execute test tasks before their corresponding implementation tasks
- **File-based coordination**: Tasks affecting the same files must run sequentially
- **Validation checkpoints**: Verify each phase completion before proceeding
7. Implementation execution rules:
- **Setup first**: Initialize project structure, dependencies, configuration
- **Tests before code**: If you need to write tests for contracts, entities, and integration scenarios
- **Core development**: Implement models, services, CLI commands, endpoints
- **Integration work**: Database connections, middleware, logging, external services
- **Polish and validation**: Unit tests, performance optimization, documentation
8. Progress tracking and error handling:
- Report progress after each completed task
- Halt execution if any non-parallel task fails
- For parallel tasks [P], continue with successful tasks, report failed ones
- Provide clear error messages with context for debugging
- Suggest next steps if implementation cannot proceed
- **IMPORTANT** For completed tasks, make sure to mark the task off as [X] in the tasks file.
9. Completion validation:
- Verify all required tasks are completed
- Check that implemented features match the original specification
- Validate that tests pass and coverage meets requirements
- Confirm the implementation follows the technical plan
- Report final status with summary of completed work
Note: This command assumes a complete task breakdown exists in tasks.md. If tasks are incomplete or missing, suggest running `/speckit.tasks` first to regenerate the task list.
"""

View file

@ -0,0 +1,93 @@
description = "Execute the implementation planning workflow using the plan template to generate design artifacts."
prompt = """
---
description: Execute the implementation planning workflow using the plan template to generate design artifacts.
handoffs:
- label: Create Tasks
agent: speckit.tasks
prompt: Break the plan into tasks
send: true
- label: Create Checklist
agent: speckit.checklist
prompt: Create a checklist for the following domain...
---
## User Input
```text
$ARGUMENTS
```
You **MUST** consider the user input before proceeding (if not empty).
## Outline
1. **Setup**: Run `.specify/scripts/bash/setup-plan.sh --json` from repo root and parse JSON for FEATURE_SPEC, IMPL_PLAN, SPECS_DIR, BRANCH. For single quotes in args like "I'm Groot", use escape syntax: e.g 'I'\\''m Groot' (or double-quote if possible: "I'm Groot").
2. **Load context**: Read FEATURE_SPEC and `.specify/memory/constitution.md`. Load IMPL_PLAN template (already copied).
3. **Execute plan workflow**: Follow the structure in IMPL_PLAN template to:
- Fill Technical Context (mark unknowns as "NEEDS CLARIFICATION")
- Fill Constitution Check section from constitution
- Evaluate gates (ERROR if violations unjustified)
- Phase 0: Generate research.md (resolve all NEEDS CLARIFICATION)
- Phase 1: Generate data-model.md, contracts/, quickstart.md
- Phase 1: Update agent context by running the agent script
- Re-evaluate Constitution Check post-design
4. **Stop and report**: Command ends after Phase 2 planning. Report branch, IMPL_PLAN path, and generated artifacts.
## Phases
### Phase 0: Outline & Research
1. **Extract unknowns from Technical Context** above:
- For each NEEDS CLARIFICATION research task
- For each dependency best practices task
- For each integration patterns task
2. **Generate and dispatch research agents**:
```text
For each unknown in Technical Context:
Task: "Research {unknown} for {feature context}"
For each technology choice:
Task: "Find best practices for {tech} in {domain}"
```
3. **Consolidate findings** in `research.md` using format:
- Decision: [what was chosen]
- Rationale: [why chosen]
- Alternatives considered: [what else evaluated]
**Output**: research.md with all NEEDS CLARIFICATION resolved
### Phase 1: Design & Contracts
**Prerequisites:** `research.md` complete
1. **Extract entities from feature spec** `data-model.md`:
- Entity name, fields, relationships
- Validation rules from requirements
- State transitions if applicable
2. **Generate API contracts** from functional requirements:
- For each user action endpoint
- Use standard REST/GraphQL patterns
- Output OpenAPI/GraphQL schema to `/contracts/`
3. **Agent context update**:
- Run `.specify/scripts/bash/update-agent-context.sh gemini`
- These scripts detect which AI agent is in use
- Update the appropriate agent-specific context file
- Add only new technology from current plan
- Preserve manual additions between markers
**Output**: data-model.md, /contracts/*, quickstart.md, agent-specific file
## Key rules
- Use absolute paths
- ERROR on gate failures or unresolved clarifications
"""

View file

@ -0,0 +1,262 @@
description = "Create or update the feature specification from a natural language feature description."
prompt = """
---
description: Create or update the feature specification from a natural language feature description.
handoffs:
- label: Build Technical Plan
agent: speckit.plan
prompt: Create a plan for the spec. I am building with...
- label: Clarify Spec Requirements
agent: speckit.clarify
prompt: Clarify specification requirements
send: true
---
## User Input
```text
$ARGUMENTS
```
You **MUST** consider the user input before proceeding (if not empty).
## Outline
The text the user typed after `/speckit.specify` in the triggering message **is** the feature description. Assume you always have it available in this conversation even if `{{args}}` appears literally below. Do not ask the user to repeat it unless they provided an empty command.
Given that feature description, do this:
1. **Generate a concise short name** (2-4 words) for the branch:
- Analyze the feature description and extract the most meaningful keywords
- Create a 2-4 word short name that captures the essence of the feature
- Use action-noun format when possible (e.g., "add-user-auth", "fix-payment-bug")
- Preserve technical terms and acronyms (OAuth2, API, JWT, etc.)
- Keep it concise but descriptive enough to understand the feature at a glance
- Examples:
- "I want to add user authentication" "user-auth"
- "Implement OAuth2 integration for the API" "oauth2-api-integration"
- "Create a dashboard for analytics" "analytics-dashboard"
- "Fix payment processing timeout bug" "fix-payment-timeout"
2. **Check for existing branches before creating new one**:
a. First, fetch all remote branches to ensure we have the latest information:
```bash
git fetch --all --prune
```
b. Find the highest feature number across all sources for the short-name:
- Remote branches: `git ls-remote --heads origin | grep -E 'refs/heads/[0-9]+-<short-name>$'`
- Local branches: `git branch | grep -E '^[* ]*[0-9]+-<short-name>$'`
- Specs directories: Check for directories matching `specs/[0-9]+-<short-name>`
c. Determine the next available number:
- Extract all numbers from all three sources
- Find the highest number N
- Use N+1 for the new branch number
d. Run the script `.specify/scripts/bash/create-new-feature.sh --json "{{args}}"` with the calculated number and short-name:
- Pass `--number N+1` and `--short-name "your-short-name"` along with the feature description
- Bash example: `.specify/scripts/bash/create-new-feature.sh --json "{{args}}" --json --number 5 --short-name "user-auth" "Add user authentication"`
- PowerShell example: `.specify/scripts/bash/create-new-feature.sh --json "{{args}}" -Json -Number 5 -ShortName "user-auth" "Add user authentication"`
**IMPORTANT**:
- Check all three sources (remote branches, local branches, specs directories) to find the highest number
- Only match branches/directories with the exact short-name pattern
- If no existing branches/directories found with this short-name, start with number 1
- You must only ever run this script once per feature
- The JSON is provided in the terminal as output - always refer to it to get the actual content you're looking for
- The JSON output will contain BRANCH_NAME and SPEC_FILE paths
- For single quotes in args like "I'm Groot", use escape syntax: e.g 'I'\\''m Groot' (or double-quote if possible: "I'm Groot")
3. Load `.specify/templates/spec-template.md` to understand required sections.
4. Follow this execution flow:
1. Parse user description from Input
If empty: ERROR "No feature description provided"
2. Extract key concepts from description
Identify: actors, actions, data, constraints
3. For unclear aspects:
- Make informed guesses based on context and industry standards
- Only mark with [NEEDS CLARIFICATION: specific question] if:
- The choice significantly impacts feature scope or user experience
- Multiple reasonable interpretations exist with different implications
- No reasonable default exists
- **LIMIT: Maximum 3 [NEEDS CLARIFICATION] markers total**
- Prioritize clarifications by impact: scope > security/privacy > user experience > technical details
4. Fill User Scenarios & Testing section
If no clear user flow: ERROR "Cannot determine user scenarios"
5. Generate Functional Requirements
Each requirement must be testable
Use reasonable defaults for unspecified details (document assumptions in Assumptions section)
6. Define Success Criteria
Create measurable, technology-agnostic outcomes
Include both quantitative metrics (time, performance, volume) and qualitative measures (user satisfaction, task completion)
Each criterion must be verifiable without implementation details
7. Identify Key Entities (if data involved)
8. Return: SUCCESS (spec ready for planning)
5. Write the specification to SPEC_FILE using the template structure, replacing placeholders with concrete details derived from the feature description (arguments) while preserving section order and headings.
6. **Specification Quality Validation**: After writing the initial spec, validate it against quality criteria:
a. **Create Spec Quality Checklist**: Generate a checklist file at `FEATURE_DIR/checklists/requirements.md` using the checklist template structure with these validation items:
```markdown
# Specification Quality Checklist: [FEATURE NAME]
**Purpose**: Validate specification completeness and quality before proceeding to planning
**Created**: [DATE]
**Feature**: [Link to spec.md]
## Content Quality
- [ ] No implementation details (languages, frameworks, APIs)
- [ ] Focused on user value and business needs
- [ ] Written for non-technical stakeholders
- [ ] All mandatory sections completed
## Requirement Completeness
- [ ] No [NEEDS CLARIFICATION] markers remain
- [ ] Requirements are testable and unambiguous
- [ ] Success criteria are measurable
- [ ] Success criteria are technology-agnostic (no implementation details)
- [ ] All acceptance scenarios are defined
- [ ] Edge cases are identified
- [ ] Scope is clearly bounded
- [ ] Dependencies and assumptions identified
## Feature Readiness
- [ ] All functional requirements have clear acceptance criteria
- [ ] User scenarios cover primary flows
- [ ] Feature meets measurable outcomes defined in Success Criteria
- [ ] No implementation details leak into specification
## Notes
- Items marked incomplete require spec updates before `/speckit.clarify` or `/speckit.plan`
```
b. **Run Validation Check**: Review the spec against each checklist item:
- For each item, determine if it passes or fails
- Document specific issues found (quote relevant spec sections)
c. **Handle Validation Results**:
- **If all items pass**: Mark checklist complete and proceed to step 6
- **If items fail (excluding [NEEDS CLARIFICATION])**:
1. List the failing items and specific issues
2. Update the spec to address each issue
3. Re-run validation until all items pass (max 3 iterations)
4. If still failing after 3 iterations, document remaining issues in checklist notes and warn user
- **If [NEEDS CLARIFICATION] markers remain**:
1. Extract all [NEEDS CLARIFICATION: ...] markers from the spec
2. **LIMIT CHECK**: If more than 3 markers exist, keep only the 3 most critical (by scope/security/UX impact) and make informed guesses for the rest
3. For each clarification needed (max 3), present options to user in this format:
```markdown
## Question [N]: [Topic]
**Context**: [Quote relevant spec section]
**What we need to know**: [Specific question from NEEDS CLARIFICATION marker]
**Suggested Answers**:
| Option | Answer | Implications |
|--------|--------|--------------|
| A | [First suggested answer] | [What this means for the feature] |
| B | [Second suggested answer] | [What this means for the feature] |
| C | [Third suggested answer] | [What this means for the feature] |
| Custom | Provide your own answer | [Explain how to provide custom input] |
**Your choice**: _[Wait for user response]_
```
4. **CRITICAL - Table Formatting**: Ensure markdown tables are properly formatted:
- Use consistent spacing with pipes aligned
- Each cell should have spaces around content: `| Content |` not `|Content|`
- Header separator must have at least 3 dashes: `|--------|`
- Test that the table renders correctly in markdown preview
5. Number questions sequentially (Q1, Q2, Q3 - max 3 total)
6. Present all questions together before waiting for responses
7. Wait for user to respond with their choices for all questions (e.g., "Q1: A, Q2: Custom - [details], Q3: B")
8. Update the spec by replacing each [NEEDS CLARIFICATION] marker with the user's selected or provided answer
9. Re-run validation after all clarifications are resolved
d. **Update Checklist**: After each validation iteration, update the checklist file with current pass/fail status
7. Report completion with branch name, spec file path, checklist results, and readiness for the next phase (`/speckit.clarify` or `/speckit.plan`).
**NOTE:** The script creates and checks out the new branch and initializes the spec file before writing.
## General Guidelines
## Quick Guidelines
- Focus on **WHAT** users need and **WHY**.
- Avoid HOW to implement (no tech stack, APIs, code structure).
- Written for business stakeholders, not developers.
- DO NOT create any checklists that are embedded in the spec. That will be a separate command.
### Section Requirements
- **Mandatory sections**: Must be completed for every feature
- **Optional sections**: Include only when relevant to the feature
- When a section doesn't apply, remove it entirely (don't leave as "N/A")
### For AI Generation
When creating this spec from a user prompt:
1. **Make informed guesses**: Use context, industry standards, and common patterns to fill gaps
2. **Document assumptions**: Record reasonable defaults in the Assumptions section
3. **Limit clarifications**: Maximum 3 [NEEDS CLARIFICATION] markers - use only for critical decisions that:
- Significantly impact feature scope or user experience
- Have multiple reasonable interpretations with different implications
- Lack any reasonable default
4. **Prioritize clarifications**: scope > security/privacy > user experience > technical details
5. **Think like a tester**: Every vague requirement should fail the "testable and unambiguous" checklist item
6. **Common areas needing clarification** (only if no reasonable default exists):
- Feature scope and boundaries (include/exclude specific use cases)
- User types and permissions (if multiple conflicting interpretations possible)
- Security/compliance requirements (when legally/financially significant)
**Examples of reasonable defaults** (don't ask about these):
- Data retention: Industry-standard practices for the domain
- Performance targets: Standard web/mobile app expectations unless specified
- Error handling: User-friendly messages with appropriate fallbacks
- Authentication method: Standard session-based or OAuth2 for web apps
- Integration patterns: RESTful APIs unless specified otherwise
### Success Criteria Guidelines
Success criteria must be:
1. **Measurable**: Include specific metrics (time, percentage, count, rate)
2. **Technology-agnostic**: No mention of frameworks, languages, databases, or tools
3. **User-focused**: Describe outcomes from user/business perspective, not system internals
4. **Verifiable**: Can be tested/validated without knowing implementation details
**Good examples**:
- "Users can complete checkout in under 3 minutes"
- "System supports 10,000 concurrent users"
- "95% of searches return results in under 1 second"
- "Task completion rate improves by 40%"
**Bad examples** (implementation-focused):
- "API response time is under 200ms" (too technical, use "Users see results instantly")
- "Database can handle 1000 TPS" (implementation detail, use user-facing metric)
- "React components render efficiently" (framework-specific)
- "Redis cache hit rate above 80%" (technology-specific)
"""

View file

@ -0,0 +1,141 @@
description = "Generate an actionable, dependency-ordered tasks.md for the feature based on available design artifacts."
prompt = """
---
description: Generate an actionable, dependency-ordered tasks.md for the feature based on available design artifacts.
handoffs:
- label: Analyze For Consistency
agent: speckit.analyze
prompt: Run a project analysis for consistency
send: true
- label: Implement Project
agent: speckit.implement
prompt: Start the implementation in phases
send: true
---
## User Input
```text
$ARGUMENTS
```
You **MUST** consider the user input before proceeding (if not empty).
## Outline
1. **Setup**: Run `.specify/scripts/bash/check-prerequisites.sh --json` from repo root and parse FEATURE_DIR and AVAILABLE_DOCS list. All paths must be absolute. For single quotes in args like "I'm Groot", use escape syntax: e.g 'I'\\''m Groot' (or double-quote if possible: "I'm Groot").
2. **Load design documents**: Read from FEATURE_DIR:
- **Required**: plan.md (tech stack, libraries, structure), spec.md (user stories with priorities)
- **Optional**: data-model.md (entities), contracts/ (API endpoints), research.md (decisions), quickstart.md (test scenarios)
- Note: Not all projects have all documents. Generate tasks based on what's available.
3. **Execute task generation workflow**:
- Load plan.md and extract tech stack, libraries, project structure
- Load spec.md and extract user stories with their priorities (P1, P2, P3, etc.)
- If data-model.md exists: Extract entities and map to user stories
- If contracts/ exists: Map endpoints to user stories
- If research.md exists: Extract decisions for setup tasks
- Generate tasks organized by user story (see Task Generation Rules below)
- Generate dependency graph showing user story completion order
- Create parallel execution examples per user story
- Validate task completeness (each user story has all needed tasks, independently testable)
4. **Generate tasks.md**: Use `.specify/templates/tasks-template.md` as structure, fill with:
- Correct feature name from plan.md
- Phase 1: Setup tasks (project initialization)
- Phase 2: Foundational tasks (blocking prerequisites for all user stories)
- Phase 3+: One phase per user story (in priority order from spec.md)
- Each phase includes: story goal, independent test criteria, tests (if requested), implementation tasks
- Final Phase: Polish & cross-cutting concerns
- All tasks must follow the strict checklist format (see Task Generation Rules below)
- Clear file paths for each task
- Dependencies section showing story completion order
- Parallel execution examples per story
- Implementation strategy section (MVP first, incremental delivery)
5. **Report**: Output path to generated tasks.md and summary:
- Total task count
- Task count per user story
- Parallel opportunities identified
- Independent test criteria for each story
- Suggested MVP scope (typically just User Story 1)
- Format validation: Confirm ALL tasks follow the checklist format (checkbox, ID, labels, file paths)
Context for task generation: {{args}}
The tasks.md should be immediately executable - each task must be specific enough that an LLM can complete it without additional context.
## Task Generation Rules
**CRITICAL**: Tasks MUST be organized by user story to enable independent implementation and testing.
**Tests are OPTIONAL**: Only generate test tasks if explicitly requested in the feature specification or if user requests TDD approach.
### Checklist Format (REQUIRED)
Every task MUST strictly follow this format:
```text
- [ ] [TaskID] [P?] [Story?] Description with file path
```
**Format Components**:
1. **Checkbox**: ALWAYS start with `- [ ]` (markdown checkbox)
2. **Task ID**: Sequential number (T001, T002, T003...) in execution order
3. **[P] marker**: Include ONLY if task is parallelizable (different files, no dependencies on incomplete tasks)
4. **[Story] label**: REQUIRED for user story phase tasks only
- Format: [US1], [US2], [US3], etc. (maps to user stories from spec.md)
- Setup phase: NO story label
- Foundational phase: NO story label
- User Story phases: MUST have story label
- Polish phase: NO story label
5. **Description**: Clear action with exact file path
**Examples**:
- CORRECT: `- [ ] T001 Create project structure per implementation plan`
- CORRECT: `- [ ] T005 [P] Implement authentication middleware in src/middleware/auth.py`
- CORRECT: `- [ ] T012 [P] [US1] Create User model in src/models/user.py`
- CORRECT: `- [ ] T014 [US1] Implement UserService in src/services/user_service.py`
- WRONG: `- [ ] Create User model` (missing ID and Story label)
- WRONG: `T001 [US1] Create model` (missing checkbox)
- WRONG: `- [ ] [US1] Create User model` (missing Task ID)
- WRONG: `- [ ] T001 [US1] Create model` (missing file path)
### Task Organization
1. **From User Stories (spec.md)** - PRIMARY ORGANIZATION:
- Each user story (P1, P2, P3...) gets its own phase
- Map all related components to their story:
- Models needed for that story
- Services needed for that story
- Endpoints/UI needed for that story
- If tests requested: Tests specific to that story
- Mark story dependencies (most stories should be independent)
2. **From Contracts**:
- Map each contract/endpoint to the user story it serves
- If tests requested: Each contract contract test task [P] before implementation in that story's phase
3. **From Data Model**:
- Map each entity to the user story(ies) that need it
- If entity serves multiple stories: Put in earliest story or Setup phase
- Relationships service layer tasks in appropriate story phase
4. **From Setup/Infrastructure**:
- Shared infrastructure Setup phase (Phase 1)
- Foundational/blocking tasks Foundational phase (Phase 2)
- Story-specific setup within that story's phase
### Phase Structure
- **Phase 1**: Setup (project initialization)
- **Phase 2**: Foundational (blocking prerequisites - MUST complete before user stories)
- **Phase 3+**: User Stories in priority order (P1, P2, P3...)
- Within each story: Tests (if requested) Models Services Endpoints Integration
- Each phase should be a complete, independently testable increment
- **Final Phase**: Polish & Cross-Cutting Concerns
"""

View file

@ -0,0 +1,34 @@
description = "Convert existing tasks into actionable, dependency-ordered GitHub issues for the feature based on available design artifacts."
prompt = """
---
description: Convert existing tasks into actionable, dependency-ordered GitHub issues for the feature based on available design artifacts.
tools: ['github/github-mcp-server/issue_write']
---
## User Input
```text
$ARGUMENTS
```
You **MUST** consider the user input before proceeding (if not empty).
## Outline
1. Run `.specify/scripts/bash/check-prerequisites.sh --json --require-tasks --include-tasks` from repo root and parse FEATURE_DIR and AVAILABLE_DOCS list. All paths must be absolute. For single quotes in args like "I'm Groot", use escape syntax: e.g 'I'\\''m Groot' (or double-quote if possible: "I'm Groot").
1. From the executed script, extract the path to **tasks**.
1. Get the Git remote by running:
```bash
git config --get remote.origin.url
```
> [!CAUTION]
> ONLY PROCEED TO NEXT STEPS IF THE REMOTE IS A GITHUB URL
1. For each task in the list, use the GitHub MCP server to create a new issue in the repository that is representative of the Git remote.
> [!CAUTION]
> UNDER NO CIRCUMSTANCES EVER CREATE ISSUES IN REPOSITORIES THAT DO NOT MATCH THE REMOTE URL
"""

9
.gitignore vendored Normal file
View file

@ -0,0 +1,9 @@
venv/
__pycache__/
*.pyc
*.db
node_modules/
.next/
.env
*.log
.DS_Store

View file

@ -0,0 +1,50 @@
# [PROJECT_NAME] Constitution
<!-- Example: Spec Constitution, TaskFlow Constitution, etc. -->
## Core Principles
### [PRINCIPLE_1_NAME]
<!-- Example: I. Library-First -->
[PRINCIPLE_1_DESCRIPTION]
<!-- Example: Every feature starts as a standalone library; Libraries must be self-contained, independently testable, documented; Clear purpose required - no organizational-only libraries -->
### [PRINCIPLE_2_NAME]
<!-- Example: II. CLI Interface -->
[PRINCIPLE_2_DESCRIPTION]
<!-- Example: Every library exposes functionality via CLI; Text in/out protocol: stdin/args → stdout, errors → stderr; Support JSON + human-readable formats -->
### [PRINCIPLE_3_NAME]
<!-- Example: III. Test-First (NON-NEGOTIABLE) -->
[PRINCIPLE_3_DESCRIPTION]
<!-- Example: TDD mandatory: Tests written → User approved → Tests fail → Then implement; Red-Green-Refactor cycle strictly enforced -->
### [PRINCIPLE_4_NAME]
<!-- Example: IV. Integration Testing -->
[PRINCIPLE_4_DESCRIPTION]
<!-- Example: Focus areas requiring integration tests: New library contract tests, Contract changes, Inter-service communication, Shared schemas -->
### [PRINCIPLE_5_NAME]
<!-- Example: V. Observability, VI. Versioning & Breaking Changes, VII. Simplicity -->
[PRINCIPLE_5_DESCRIPTION]
<!-- Example: Text I/O ensures debuggability; Structured logging required; Or: MAJOR.MINOR.BUILD format; Or: Start simple, YAGNI principles -->
## [SECTION_2_NAME]
<!-- Example: Additional Constraints, Security Requirements, Performance Standards, etc. -->
[SECTION_2_CONTENT]
<!-- Example: Technology stack requirements, compliance standards, deployment policies, etc. -->
## [SECTION_3_NAME]
<!-- Example: Development Workflow, Review Process, Quality Gates, etc. -->
[SECTION_3_CONTENT]
<!-- Example: Code review requirements, testing gates, deployment approval process, etc. -->
## Governance
<!-- Example: Constitution supersedes all other practices; Amendments require documentation, approval, migration plan -->
[GOVERNANCE_RULES]
<!-- Example: All PRs/reviews must verify compliance; Complexity must be justified; Use [GUIDANCE_FILE] for runtime development guidance -->
**Version**: [CONSTITUTION_VERSION] | **Ratified**: [RATIFICATION_DATE] | **Last Amended**: [LAST_AMENDED_DATE]
<!-- Example: Version: 2.1.1 | Ratified: 2025-06-13 | Last Amended: 2025-07-16 -->

View file

@ -0,0 +1,166 @@
#!/usr/bin/env bash
# Consolidated prerequisite checking script
#
# This script provides unified prerequisite checking for Spec-Driven Development workflow.
# It replaces the functionality previously spread across multiple scripts.
#
# Usage: ./check-prerequisites.sh [OPTIONS]
#
# OPTIONS:
# --json Output in JSON format
# --require-tasks Require tasks.md to exist (for implementation phase)
# --include-tasks Include tasks.md in AVAILABLE_DOCS list
# --paths-only Only output path variables (no validation)
# --help, -h Show help message
#
# OUTPUTS:
# JSON mode: {"FEATURE_DIR":"...", "AVAILABLE_DOCS":["..."]}
# Text mode: FEATURE_DIR:... \n AVAILABLE_DOCS: \n ✓/✗ file.md
# Paths only: REPO_ROOT: ... \n BRANCH: ... \n FEATURE_DIR: ... etc.
set -e
# Parse command line arguments
JSON_MODE=false
REQUIRE_TASKS=false
INCLUDE_TASKS=false
PATHS_ONLY=false
for arg in "$@"; do
case "$arg" in
--json)
JSON_MODE=true
;;
--require-tasks)
REQUIRE_TASKS=true
;;
--include-tasks)
INCLUDE_TASKS=true
;;
--paths-only)
PATHS_ONLY=true
;;
--help|-h)
cat << 'EOF'
Usage: check-prerequisites.sh [OPTIONS]
Consolidated prerequisite checking for Spec-Driven Development workflow.
OPTIONS:
--json Output in JSON format
--require-tasks Require tasks.md to exist (for implementation phase)
--include-tasks Include tasks.md in AVAILABLE_DOCS list
--paths-only Only output path variables (no prerequisite validation)
--help, -h Show this help message
EXAMPLES:
# Check task prerequisites (plan.md required)
./check-prerequisites.sh --json
# Check implementation prerequisites (plan.md + tasks.md required)
./check-prerequisites.sh --json --require-tasks --include-tasks
# Get feature paths only (no validation)
./check-prerequisites.sh --paths-only
EOF
exit 0
;;
*)
echo "ERROR: Unknown option '$arg'. Use --help for usage information." >&2
exit 1
;;
esac
done
# Source common functions
SCRIPT_DIR="$(CDPATH="" cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/common.sh"
# Get feature paths and validate branch
eval $(get_feature_paths)
check_feature_branch "$CURRENT_BRANCH" "$HAS_GIT" || exit 1
# If paths-only mode, output paths and exit (support JSON + paths-only combined)
if $PATHS_ONLY; then
if $JSON_MODE; then
# Minimal JSON paths payload (no validation performed)
printf '{"REPO_ROOT":"%s","BRANCH":"%s","FEATURE_DIR":"%s","FEATURE_SPEC":"%s","IMPL_PLAN":"%s","TASKS":"%s"}\n' \
"$REPO_ROOT" "$CURRENT_BRANCH" "$FEATURE_DIR" "$FEATURE_SPEC" "$IMPL_PLAN" "$TASKS"
else
echo "REPO_ROOT: $REPO_ROOT"
echo "BRANCH: $CURRENT_BRANCH"
echo "FEATURE_DIR: $FEATURE_DIR"
echo "FEATURE_SPEC: $FEATURE_SPEC"
echo "IMPL_PLAN: $IMPL_PLAN"
echo "TASKS: $TASKS"
fi
exit 0
fi
# Validate required directories and files
if [[ ! -d "$FEATURE_DIR" ]]; then
echo "ERROR: Feature directory not found: $FEATURE_DIR" >&2
echo "Run /speckit.specify first to create the feature structure." >&2
exit 1
fi
if [[ ! -f "$IMPL_PLAN" ]]; then
echo "ERROR: plan.md not found in $FEATURE_DIR" >&2
echo "Run /speckit.plan first to create the implementation plan." >&2
exit 1
fi
# Check for tasks.md if required
if $REQUIRE_TASKS && [[ ! -f "$TASKS" ]]; then
echo "ERROR: tasks.md not found in $FEATURE_DIR" >&2
echo "Run /speckit.tasks first to create the task list." >&2
exit 1
fi
# Build list of available documents
docs=()
# Always check these optional docs
[[ -f "$RESEARCH" ]] && docs+=("research.md")
[[ -f "$DATA_MODEL" ]] && docs+=("data-model.md")
# Check contracts directory (only if it exists and has files)
if [[ -d "$CONTRACTS_DIR" ]] && [[ -n "$(ls -A "$CONTRACTS_DIR" 2>/dev/null)" ]]; then
docs+=("contracts/")
fi
[[ -f "$QUICKSTART" ]] && docs+=("quickstart.md")
# Include tasks.md if requested and it exists
if $INCLUDE_TASKS && [[ -f "$TASKS" ]]; then
docs+=("tasks.md")
fi
# Output results
if $JSON_MODE; then
# Build JSON array of documents
if [[ ${#docs[@]} -eq 0 ]]; then
json_docs="[]"
else
json_docs=$(printf '"%s",' "${docs[@]}")
json_docs="[${json_docs%,}]"
fi
printf '{"FEATURE_DIR":"%s","AVAILABLE_DOCS":%s}\n' "$FEATURE_DIR" "$json_docs"
else
# Text output
echo "FEATURE_DIR:$FEATURE_DIR"
echo "AVAILABLE_DOCS:"
# Show status of each potential document
check_file "$RESEARCH" "research.md"
check_file "$DATA_MODEL" "data-model.md"
check_dir "$CONTRACTS_DIR" "contracts/"
check_file "$QUICKSTART" "quickstart.md"
if $INCLUDE_TASKS; then
check_file "$TASKS" "tasks.md"
fi
fi

156
.specify/scripts/bash/common.sh Executable file
View file

@ -0,0 +1,156 @@
#!/usr/bin/env bash
# Common functions and variables for all scripts
# Get repository root, with fallback for non-git repositories
get_repo_root() {
if git rev-parse --show-toplevel >/dev/null 2>&1; then
git rev-parse --show-toplevel
else
# Fall back to script location for non-git repos
local script_dir="$(CDPATH="" cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
(cd "$script_dir/../../.." && pwd)
fi
}
# Get current branch, with fallback for non-git repositories
get_current_branch() {
# First check if SPECIFY_FEATURE environment variable is set
if [[ -n "${SPECIFY_FEATURE:-}" ]]; then
echo "$SPECIFY_FEATURE"
return
fi
# Then check git if available
if git rev-parse --abbrev-ref HEAD >/dev/null 2>&1; then
git rev-parse --abbrev-ref HEAD
return
fi
# For non-git repos, try to find the latest feature directory
local repo_root=$(get_repo_root)
local specs_dir="$repo_root/specs"
if [[ -d "$specs_dir" ]]; then
local latest_feature=""
local highest=0
for dir in "$specs_dir"/*; do
if [[ -d "$dir" ]]; then
local dirname=$(basename "$dir")
if [[ "$dirname" =~ ^([0-9]{3})- ]]; then
local number=${BASH_REMATCH[1]}
number=$((10#$number))
if [[ "$number" -gt "$highest" ]]; then
highest=$number
latest_feature=$dirname
fi
fi
fi
done
if [[ -n "$latest_feature" ]]; then
echo "$latest_feature"
return
fi
fi
echo "main" # Final fallback
}
# Check if we have git available
has_git() {
git rev-parse --show-toplevel >/dev/null 2>&1
}
check_feature_branch() {
local branch="$1"
local has_git_repo="$2"
# For non-git repos, we can't enforce branch naming but still provide output
if [[ "$has_git_repo" != "true" ]]; then
echo "[specify] Warning: Git repository not detected; skipped branch validation" >&2
return 0
fi
if [[ ! "$branch" =~ ^[0-9]{3}- ]]; then
echo "ERROR: Not on a feature branch. Current branch: $branch" >&2
echo "Feature branches should be named like: 001-feature-name" >&2
return 1
fi
return 0
}
get_feature_dir() { echo "$1/specs/$2"; }
# Find feature directory by numeric prefix instead of exact branch match
# This allows multiple branches to work on the same spec (e.g., 004-fix-bug, 004-add-feature)
find_feature_dir_by_prefix() {
local repo_root="$1"
local branch_name="$2"
local specs_dir="$repo_root/specs"
# Extract numeric prefix from branch (e.g., "004" from "004-whatever")
if [[ ! "$branch_name" =~ ^([0-9]{3})- ]]; then
# If branch doesn't have numeric prefix, fall back to exact match
echo "$specs_dir/$branch_name"
return
fi
local prefix="${BASH_REMATCH[1]}"
# Search for directories in specs/ that start with this prefix
local matches=()
if [[ -d "$specs_dir" ]]; then
for dir in "$specs_dir"/"$prefix"-*; do
if [[ -d "$dir" ]]; then
matches+=("$(basename "$dir")")
fi
done
fi
# Handle results
if [[ ${#matches[@]} -eq 0 ]]; then
# No match found - return the branch name path (will fail later with clear error)
echo "$specs_dir/$branch_name"
elif [[ ${#matches[@]} -eq 1 ]]; then
# Exactly one match - perfect!
echo "$specs_dir/${matches[0]}"
else
# Multiple matches - this shouldn't happen with proper naming convention
echo "ERROR: Multiple spec directories found with prefix '$prefix': ${matches[*]}" >&2
echo "Please ensure only one spec directory exists per numeric prefix." >&2
echo "$specs_dir/$branch_name" # Return something to avoid breaking the script
fi
}
get_feature_paths() {
local repo_root=$(get_repo_root)
local current_branch=$(get_current_branch)
local has_git_repo="false"
if has_git; then
has_git_repo="true"
fi
# Use prefix-based lookup to support multiple branches per spec
local feature_dir=$(find_feature_dir_by_prefix "$repo_root" "$current_branch")
cat <<EOF
REPO_ROOT='$repo_root'
CURRENT_BRANCH='$current_branch'
HAS_GIT='$has_git_repo'
FEATURE_DIR='$feature_dir'
FEATURE_SPEC='$feature_dir/spec.md'
IMPL_PLAN='$feature_dir/plan.md'
TASKS='$feature_dir/tasks.md'
RESEARCH='$feature_dir/research.md'
DATA_MODEL='$feature_dir/data-model.md'
QUICKSTART='$feature_dir/quickstart.md'
CONTRACTS_DIR='$feature_dir/contracts'
EOF
}
check_file() { [[ -f "$1" ]] && echo "$2" || echo "$2"; }
check_dir() { [[ -d "$1" && -n $(ls -A "$1" 2>/dev/null) ]] && echo "$2" || echo "$2"; }

View file

@ -0,0 +1,297 @@
#!/usr/bin/env bash
set -e
JSON_MODE=false
SHORT_NAME=""
BRANCH_NUMBER=""
ARGS=()
i=1
while [ $i -le $# ]; do
arg="${!i}"
case "$arg" in
--json)
JSON_MODE=true
;;
--short-name)
if [ $((i + 1)) -gt $# ]; then
echo 'Error: --short-name requires a value' >&2
exit 1
fi
i=$((i + 1))
next_arg="${!i}"
# Check if the next argument is another option (starts with --)
if [[ "$next_arg" == --* ]]; then
echo 'Error: --short-name requires a value' >&2
exit 1
fi
SHORT_NAME="$next_arg"
;;
--number)
if [ $((i + 1)) -gt $# ]; then
echo 'Error: --number requires a value' >&2
exit 1
fi
i=$((i + 1))
next_arg="${!i}"
if [[ "$next_arg" == --* ]]; then
echo 'Error: --number requires a value' >&2
exit 1
fi
BRANCH_NUMBER="$next_arg"
;;
--help|-h)
echo "Usage: $0 [--json] [--short-name <name>] [--number N] <feature_description>"
echo ""
echo "Options:"
echo " --json Output in JSON format"
echo " --short-name <name> Provide a custom short name (2-4 words) for the branch"
echo " --number N Specify branch number manually (overrides auto-detection)"
echo " --help, -h Show this help message"
echo ""
echo "Examples:"
echo " $0 'Add user authentication system' --short-name 'user-auth'"
echo " $0 'Implement OAuth2 integration for API' --number 5"
exit 0
;;
*)
ARGS+=("$arg")
;;
esac
i=$((i + 1))
done
FEATURE_DESCRIPTION="${ARGS[*]}"
if [ -z "$FEATURE_DESCRIPTION" ]; then
echo "Usage: $0 [--json] [--short-name <name>] [--number N] <feature_description>" >&2
exit 1
fi
# Function to find the repository root by searching for existing project markers
find_repo_root() {
local dir="$1"
while [ "$dir" != "/" ]; do
if [ -d "$dir/.git" ] || [ -d "$dir/.specify" ]; then
echo "$dir"
return 0
fi
dir="$(dirname "$dir")"
done
return 1
}
# Function to get highest number from specs directory
get_highest_from_specs() {
local specs_dir="$1"
local highest=0
if [ -d "$specs_dir" ]; then
for dir in "$specs_dir"/*; do
[ -d "$dir" ] || continue
dirname=$(basename "$dir")
number=$(echo "$dirname" | grep -o '^[0-9]\+' || echo "0")
number=$((10#$number))
if [ "$number" -gt "$highest" ]; then
highest=$number
fi
done
fi
echo "$highest"
}
# Function to get highest number from git branches
get_highest_from_branches() {
local highest=0
# Get all branches (local and remote)
branches=$(git branch -a 2>/dev/null || echo "")
if [ -n "$branches" ]; then
while IFS= read -r branch; do
# Clean branch name: remove leading markers and remote prefixes
clean_branch=$(echo "$branch" | sed 's/^[* ]*//; s|^remotes/[^/]*/||')
# Extract feature number if branch matches pattern ###-*
if echo "$clean_branch" | grep -q '^[0-9]\{3\}-'; then
number=$(echo "$clean_branch" | grep -o '^[0-9]\{3\}' || echo "0")
number=$((10#$number))
if [ "$number" -gt "$highest" ]; then
highest=$number
fi
fi
done <<< "$branches"
fi
echo "$highest"
}
# Function to check existing branches (local and remote) and return next available number
check_existing_branches() {
local specs_dir="$1"
# Fetch all remotes to get latest branch info (suppress errors if no remotes)
git fetch --all --prune 2>/dev/null || true
# Get highest number from ALL branches (not just matching short name)
local highest_branch=$(get_highest_from_branches)
# Get highest number from ALL specs (not just matching short name)
local highest_spec=$(get_highest_from_specs "$specs_dir")
# Take the maximum of both
local max_num=$highest_branch
if [ "$highest_spec" -gt "$max_num" ]; then
max_num=$highest_spec
fi
# Return next number
echo $((max_num + 1))
}
# Function to clean and format a branch name
clean_branch_name() {
local name="$1"
echo "$name" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/-\+/-/g' | sed 's/^-//' | sed 's/-$//'
}
# Resolve repository root. Prefer git information when available, but fall back
# to searching for repository markers so the workflow still functions in repositories that
# were initialised with --no-git.
SCRIPT_DIR="$(CDPATH="" cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if git rev-parse --show-toplevel >/dev/null 2>&1; then
REPO_ROOT=$(git rev-parse --show-toplevel)
HAS_GIT=true
else
REPO_ROOT="$(find_repo_root "$SCRIPT_DIR")"
if [ -z "$REPO_ROOT" ]; then
echo "Error: Could not determine repository root. Please run this script from within the repository." >&2
exit 1
fi
HAS_GIT=false
fi
cd "$REPO_ROOT"
SPECS_DIR="$REPO_ROOT/specs"
mkdir -p "$SPECS_DIR"
# Function to generate branch name with stop word filtering and length filtering
generate_branch_name() {
local description="$1"
# Common stop words to filter out
local stop_words="^(i|a|an|the|to|for|of|in|on|at|by|with|from|is|are|was|were|be|been|being|have|has|had|do|does|did|will|would|should|could|can|may|might|must|shall|this|that|these|those|my|your|our|their|want|need|add|get|set)$"
# Convert to lowercase and split into words
local clean_name=$(echo "$description" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/ /g')
# Filter words: remove stop words and words shorter than 3 chars (unless they're uppercase acronyms in original)
local meaningful_words=()
for word in $clean_name; do
# Skip empty words
[ -z "$word" ] && continue
# Keep words that are NOT stop words AND (length >= 3 OR are potential acronyms)
if ! echo "$word" | grep -qiE "$stop_words"; then
if [ ${#word} -ge 3 ]; then
meaningful_words+=("$word")
elif echo "$description" | grep -q "\b${word^^}\b"; then
# Keep short words if they appear as uppercase in original (likely acronyms)
meaningful_words+=("$word")
fi
fi
done
# If we have meaningful words, use first 3-4 of them
if [ ${#meaningful_words[@]} -gt 0 ]; then
local max_words=3
if [ ${#meaningful_words[@]} -eq 4 ]; then max_words=4; fi
local result=""
local count=0
for word in "${meaningful_words[@]}"; do
if [ $count -ge $max_words ]; then break; fi
if [ -n "$result" ]; then result="$result-"; fi
result="$result$word"
count=$((count + 1))
done
echo "$result"
else
# Fallback to original logic if no meaningful words found
local cleaned=$(clean_branch_name "$description")
echo "$cleaned" | tr '-' '\n' | grep -v '^$' | head -3 | tr '\n' '-' | sed 's/-$//'
fi
}
# Generate branch name
if [ -n "$SHORT_NAME" ]; then
# Use provided short name, just clean it up
BRANCH_SUFFIX=$(clean_branch_name "$SHORT_NAME")
else
# Generate from description with smart filtering
BRANCH_SUFFIX=$(generate_branch_name "$FEATURE_DESCRIPTION")
fi
# Determine branch number
if [ -z "$BRANCH_NUMBER" ]; then
if [ "$HAS_GIT" = true ]; then
# Check existing branches on remotes
BRANCH_NUMBER=$(check_existing_branches "$SPECS_DIR")
else
# Fall back to local directory check
HIGHEST=$(get_highest_from_specs "$SPECS_DIR")
BRANCH_NUMBER=$((HIGHEST + 1))
fi
fi
# Force base-10 interpretation to prevent octal conversion (e.g., 010 → 8 in octal, but should be 10 in decimal)
FEATURE_NUM=$(printf "%03d" "$((10#$BRANCH_NUMBER))")
BRANCH_NAME="${FEATURE_NUM}-${BRANCH_SUFFIX}"
# GitHub enforces a 244-byte limit on branch names
# Validate and truncate if necessary
MAX_BRANCH_LENGTH=244
if [ ${#BRANCH_NAME} -gt $MAX_BRANCH_LENGTH ]; then
# Calculate how much we need to trim from suffix
# Account for: feature number (3) + hyphen (1) = 4 chars
MAX_SUFFIX_LENGTH=$((MAX_BRANCH_LENGTH - 4))
# Truncate suffix at word boundary if possible
TRUNCATED_SUFFIX=$(echo "$BRANCH_SUFFIX" | cut -c1-$MAX_SUFFIX_LENGTH)
# Remove trailing hyphen if truncation created one
TRUNCATED_SUFFIX=$(echo "$TRUNCATED_SUFFIX" | sed 's/-$//')
ORIGINAL_BRANCH_NAME="$BRANCH_NAME"
BRANCH_NAME="${FEATURE_NUM}-${TRUNCATED_SUFFIX}"
>&2 echo "[specify] Warning: Branch name exceeded GitHub's 244-byte limit"
>&2 echo "[specify] Original: $ORIGINAL_BRANCH_NAME (${#ORIGINAL_BRANCH_NAME} bytes)"
>&2 echo "[specify] Truncated to: $BRANCH_NAME (${#BRANCH_NAME} bytes)"
fi
if [ "$HAS_GIT" = true ]; then
git checkout -b "$BRANCH_NAME"
else
>&2 echo "[specify] Warning: Git repository not detected; skipped branch creation for $BRANCH_NAME"
fi
FEATURE_DIR="$SPECS_DIR/$BRANCH_NAME"
mkdir -p "$FEATURE_DIR"
TEMPLATE="$REPO_ROOT/.specify/templates/spec-template.md"
SPEC_FILE="$FEATURE_DIR/spec.md"
if [ -f "$TEMPLATE" ]; then cp "$TEMPLATE" "$SPEC_FILE"; else touch "$SPEC_FILE"; fi
# Set the SPECIFY_FEATURE environment variable for the current session
export SPECIFY_FEATURE="$BRANCH_NAME"
if $JSON_MODE; then
printf '{"BRANCH_NAME":"%s","SPEC_FILE":"%s","FEATURE_NUM":"%s"}\n' "$BRANCH_NAME" "$SPEC_FILE" "$FEATURE_NUM"
else
echo "BRANCH_NAME: $BRANCH_NAME"
echo "SPEC_FILE: $SPEC_FILE"
echo "FEATURE_NUM: $FEATURE_NUM"
echo "SPECIFY_FEATURE environment variable set to: $BRANCH_NAME"
fi

View file

@ -0,0 +1,61 @@
#!/usr/bin/env bash
set -e
# Parse command line arguments
JSON_MODE=false
ARGS=()
for arg in "$@"; do
case "$arg" in
--json)
JSON_MODE=true
;;
--help|-h)
echo "Usage: $0 [--json]"
echo " --json Output results in JSON format"
echo " --help Show this help message"
exit 0
;;
*)
ARGS+=("$arg")
;;
esac
done
# Get script directory and load common functions
SCRIPT_DIR="$(CDPATH="" cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/common.sh"
# Get all paths and variables from common functions
eval $(get_feature_paths)
# Check if we're on a proper feature branch (only for git repos)
check_feature_branch "$CURRENT_BRANCH" "$HAS_GIT" || exit 1
# Ensure the feature directory exists
mkdir -p "$FEATURE_DIR"
# Copy plan template if it exists
TEMPLATE="$REPO_ROOT/.specify/templates/plan-template.md"
if [[ -f "$TEMPLATE" ]]; then
cp "$TEMPLATE" "$IMPL_PLAN"
echo "Copied plan template to $IMPL_PLAN"
else
echo "Warning: Plan template not found at $TEMPLATE"
# Create a basic plan file if template doesn't exist
touch "$IMPL_PLAN"
fi
# Output results
if $JSON_MODE; then
printf '{"FEATURE_SPEC":"%s","IMPL_PLAN":"%s","SPECS_DIR":"%s","BRANCH":"%s","HAS_GIT":"%s"}\n' \
"$FEATURE_SPEC" "$IMPL_PLAN" "$FEATURE_DIR" "$CURRENT_BRANCH" "$HAS_GIT"
else
echo "FEATURE_SPEC: $FEATURE_SPEC"
echo "IMPL_PLAN: $IMPL_PLAN"
echo "SPECS_DIR: $FEATURE_DIR"
echo "BRANCH: $CURRENT_BRANCH"
echo "HAS_GIT: $HAS_GIT"
fi

View file

@ -0,0 +1,799 @@
#!/usr/bin/env bash
# Update agent context files with information from plan.md
#
# This script maintains AI agent context files by parsing feature specifications
# and updating agent-specific configuration files with project information.
#
# MAIN FUNCTIONS:
# 1. Environment Validation
# - Verifies git repository structure and branch information
# - Checks for required plan.md files and templates
# - Validates file permissions and accessibility
#
# 2. Plan Data Extraction
# - Parses plan.md files to extract project metadata
# - Identifies language/version, frameworks, databases, and project types
# - Handles missing or incomplete specification data gracefully
#
# 3. Agent File Management
# - Creates new agent context files from templates when needed
# - Updates existing agent files with new project information
# - Preserves manual additions and custom configurations
# - Supports multiple AI agent formats and directory structures
#
# 4. Content Generation
# - Generates language-specific build/test commands
# - Creates appropriate project directory structures
# - Updates technology stacks and recent changes sections
# - Maintains consistent formatting and timestamps
#
# 5. Multi-Agent Support
# - Handles agent-specific file paths and naming conventions
# - Supports: Claude, Gemini, Copilot, Cursor, Qwen, opencode, Codex, Windsurf, Kilo Code, Auggie CLI, Roo Code, CodeBuddy CLI, Qoder CLI, Amp, SHAI, or Amazon Q Developer CLI
# - Can update single agents or all existing agent files
# - Creates default Claude file if no agent files exist
#
# Usage: ./update-agent-context.sh [agent_type]
# Agent types: claude|gemini|copilot|cursor-agent|qwen|opencode|codex|windsurf|kilocode|auggie|shai|q|bob|qoder
# Leave empty to update all existing agent files
set -e
# Enable strict error handling
set -u
set -o pipefail
#==============================================================================
# Configuration and Global Variables
#==============================================================================
# Get script directory and load common functions
SCRIPT_DIR="$(CDPATH="" cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/common.sh"
# Get all paths and variables from common functions
eval $(get_feature_paths)
NEW_PLAN="$IMPL_PLAN" # Alias for compatibility with existing code
AGENT_TYPE="${1:-}"
# Agent-specific file paths
CLAUDE_FILE="$REPO_ROOT/CLAUDE.md"
GEMINI_FILE="$REPO_ROOT/GEMINI.md"
COPILOT_FILE="$REPO_ROOT/.github/agents/copilot-instructions.md"
CURSOR_FILE="$REPO_ROOT/.cursor/rules/specify-rules.mdc"
QWEN_FILE="$REPO_ROOT/QWEN.md"
AGENTS_FILE="$REPO_ROOT/AGENTS.md"
WINDSURF_FILE="$REPO_ROOT/.windsurf/rules/specify-rules.md"
KILOCODE_FILE="$REPO_ROOT/.kilocode/rules/specify-rules.md"
AUGGIE_FILE="$REPO_ROOT/.augment/rules/specify-rules.md"
ROO_FILE="$REPO_ROOT/.roo/rules/specify-rules.md"
CODEBUDDY_FILE="$REPO_ROOT/CODEBUDDY.md"
QODER_FILE="$REPO_ROOT/QODER.md"
AMP_FILE="$REPO_ROOT/AGENTS.md"
SHAI_FILE="$REPO_ROOT/SHAI.md"
Q_FILE="$REPO_ROOT/AGENTS.md"
BOB_FILE="$REPO_ROOT/AGENTS.md"
# Template file
TEMPLATE_FILE="$REPO_ROOT/.specify/templates/agent-file-template.md"
# Global variables for parsed plan data
NEW_LANG=""
NEW_FRAMEWORK=""
NEW_DB=""
NEW_PROJECT_TYPE=""
#==============================================================================
# Utility Functions
#==============================================================================
log_info() {
echo "INFO: $1"
}
log_success() {
echo "$1"
}
log_error() {
echo "ERROR: $1" >&2
}
log_warning() {
echo "WARNING: $1" >&2
}
# Cleanup function for temporary files
cleanup() {
local exit_code=$?
rm -f /tmp/agent_update_*_$$
rm -f /tmp/manual_additions_$$
exit $exit_code
}
# Set up cleanup trap
trap cleanup EXIT INT TERM
#==============================================================================
# Validation Functions
#==============================================================================
validate_environment() {
# Check if we have a current branch/feature (git or non-git)
if [[ -z "$CURRENT_BRANCH" ]]; then
log_error "Unable to determine current feature"
if [[ "$HAS_GIT" == "true" ]]; then
log_info "Make sure you're on a feature branch"
else
log_info "Set SPECIFY_FEATURE environment variable or create a feature first"
fi
exit 1
fi
# Check if plan.md exists
if [[ ! -f "$NEW_PLAN" ]]; then
log_error "No plan.md found at $NEW_PLAN"
log_info "Make sure you're working on a feature with a corresponding spec directory"
if [[ "$HAS_GIT" != "true" ]]; then
log_info "Use: export SPECIFY_FEATURE=your-feature-name or create a new feature first"
fi
exit 1
fi
# Check if template exists (needed for new files)
if [[ ! -f "$TEMPLATE_FILE" ]]; then
log_warning "Template file not found at $TEMPLATE_FILE"
log_warning "Creating new agent files will fail"
fi
}
#==============================================================================
# Plan Parsing Functions
#==============================================================================
extract_plan_field() {
local field_pattern="$1"
local plan_file="$2"
grep "^\*\*${field_pattern}\*\*: " "$plan_file" 2>/dev/null | \
head -1 | \
sed "s|^\*\*${field_pattern}\*\*: ||" | \
sed 's/^[ \t]*//;s/[ \t]*$//' | \
grep -v "NEEDS CLARIFICATION" | \
grep -v "^N/A$" || echo ""
}
parse_plan_data() {
local plan_file="$1"
if [[ ! -f "$plan_file" ]]; then
log_error "Plan file not found: $plan_file"
return 1
fi
if [[ ! -r "$plan_file" ]]; then
log_error "Plan file is not readable: $plan_file"
return 1
fi
log_info "Parsing plan data from $plan_file"
NEW_LANG=$(extract_plan_field "Language/Version" "$plan_file")
NEW_FRAMEWORK=$(extract_plan_field "Primary Dependencies" "$plan_file")
NEW_DB=$(extract_plan_field "Storage" "$plan_file")
NEW_PROJECT_TYPE=$(extract_plan_field "Project Type" "$plan_file")
# Log what we found
if [[ -n "$NEW_LANG" ]]; then
log_info "Found language: $NEW_LANG"
else
log_warning "No language information found in plan"
fi
if [[ -n "$NEW_FRAMEWORK" ]]; then
log_info "Found framework: $NEW_FRAMEWORK"
fi
if [[ -n "$NEW_DB" ]] && [[ "$NEW_DB" != "N/A" ]]; then
log_info "Found database: $NEW_DB"
fi
if [[ -n "$NEW_PROJECT_TYPE" ]]; then
log_info "Found project type: $NEW_PROJECT_TYPE"
fi
}
format_technology_stack() {
local lang="$1"
local framework="$2"
local parts=()
# Add non-empty parts
[[ -n "$lang" && "$lang" != "NEEDS CLARIFICATION" ]] && parts+=("$lang")
[[ -n "$framework" && "$framework" != "NEEDS CLARIFICATION" && "$framework" != "N/A" ]] && parts+=("$framework")
# Join with proper formatting
if [[ ${#parts[@]} -eq 0 ]]; then
echo ""
elif [[ ${#parts[@]} -eq 1 ]]; then
echo "${parts[0]}"
else
# Join multiple parts with " + "
local result="${parts[0]}"
for ((i=1; i<${#parts[@]}; i++)); do
result="$result + ${parts[i]}"
done
echo "$result"
fi
}
#==============================================================================
# Template and Content Generation Functions
#==============================================================================
get_project_structure() {
local project_type="$1"
if [[ "$project_type" == *"web"* ]]; then
echo "backend/\\nfrontend/\\ntests/"
else
echo "src/\\ntests/"
fi
}
get_commands_for_language() {
local lang="$1"
case "$lang" in
*"Python"*)
echo "cd src && pytest && ruff check ."
;;
*"Rust"*)
echo "cargo test && cargo clippy"
;;
*"JavaScript"*|*"TypeScript"*)
echo "npm test \\&\\& npm run lint"
;;
*)
echo "# Add commands for $lang"
;;
esac
}
get_language_conventions() {
local lang="$1"
echo "$lang: Follow standard conventions"
}
create_new_agent_file() {
local target_file="$1"
local temp_file="$2"
local project_name="$3"
local current_date="$4"
if [[ ! -f "$TEMPLATE_FILE" ]]; then
log_error "Template not found at $TEMPLATE_FILE"
return 1
fi
if [[ ! -r "$TEMPLATE_FILE" ]]; then
log_error "Template file is not readable: $TEMPLATE_FILE"
return 1
fi
log_info "Creating new agent context file from template..."
if ! cp "$TEMPLATE_FILE" "$temp_file"; then
log_error "Failed to copy template file"
return 1
fi
# Replace template placeholders
local project_structure
project_structure=$(get_project_structure "$NEW_PROJECT_TYPE")
local commands
commands=$(get_commands_for_language "$NEW_LANG")
local language_conventions
language_conventions=$(get_language_conventions "$NEW_LANG")
# Perform substitutions with error checking using safer approach
# Escape special characters for sed by using a different delimiter or escaping
local escaped_lang=$(printf '%s\n' "$NEW_LANG" | sed 's/[\[\.*^$()+{}|]/\\&/g')
local escaped_framework=$(printf '%s\n' "$NEW_FRAMEWORK" | sed 's/[\[\.*^$()+{}|]/\\&/g')
local escaped_branch=$(printf '%s\n' "$CURRENT_BRANCH" | sed 's/[\[\.*^$()+{}|]/\\&/g')
# Build technology stack and recent change strings conditionally
local tech_stack
if [[ -n "$escaped_lang" && -n "$escaped_framework" ]]; then
tech_stack="- $escaped_lang + $escaped_framework ($escaped_branch)"
elif [[ -n "$escaped_lang" ]]; then
tech_stack="- $escaped_lang ($escaped_branch)"
elif [[ -n "$escaped_framework" ]]; then
tech_stack="- $escaped_framework ($escaped_branch)"
else
tech_stack="- ($escaped_branch)"
fi
local recent_change
if [[ -n "$escaped_lang" && -n "$escaped_framework" ]]; then
recent_change="- $escaped_branch: Added $escaped_lang + $escaped_framework"
elif [[ -n "$escaped_lang" ]]; then
recent_change="- $escaped_branch: Added $escaped_lang"
elif [[ -n "$escaped_framework" ]]; then
recent_change="- $escaped_branch: Added $escaped_framework"
else
recent_change="- $escaped_branch: Added"
fi
local substitutions=(
"s|\[PROJECT NAME\]|$project_name|"
"s|\[DATE\]|$current_date|"
"s|\[EXTRACTED FROM ALL PLAN.MD FILES\]|$tech_stack|"
"s|\[ACTUAL STRUCTURE FROM PLANS\]|$project_structure|g"
"s|\[ONLY COMMANDS FOR ACTIVE TECHNOLOGIES\]|$commands|"
"s|\[LANGUAGE-SPECIFIC, ONLY FOR LANGUAGES IN USE\]|$language_conventions|"
"s|\[LAST 3 FEATURES AND WHAT THEY ADDED\]|$recent_change|"
)
for substitution in "${substitutions[@]}"; do
if ! sed -i.bak -e "$substitution" "$temp_file"; then
log_error "Failed to perform substitution: $substitution"
rm -f "$temp_file" "$temp_file.bak"
return 1
fi
done
# Convert \n sequences to actual newlines
newline=$(printf '\n')
sed -i.bak2 "s/\\\\n/${newline}/g" "$temp_file"
# Clean up backup files
rm -f "$temp_file.bak" "$temp_file.bak2"
return 0
}
update_existing_agent_file() {
local target_file="$1"
local current_date="$2"
log_info "Updating existing agent context file..."
# Use a single temporary file for atomic update
local temp_file
temp_file=$(mktemp) || {
log_error "Failed to create temporary file"
return 1
}
# Process the file in one pass
local tech_stack=$(format_technology_stack "$NEW_LANG" "$NEW_FRAMEWORK")
local new_tech_entries=()
local new_change_entry=""
# Prepare new technology entries
if [[ -n "$tech_stack" ]] && ! grep -q "$tech_stack" "$target_file"; then
new_tech_entries+=("- $tech_stack ($CURRENT_BRANCH)")
fi
if [[ -n "$NEW_DB" ]] && [[ "$NEW_DB" != "N/A" ]] && [[ "$NEW_DB" != "NEEDS CLARIFICATION" ]] && ! grep -q "$NEW_DB" "$target_file"; then
new_tech_entries+=("- $NEW_DB ($CURRENT_BRANCH)")
fi
# Prepare new change entry
if [[ -n "$tech_stack" ]]; then
new_change_entry="- $CURRENT_BRANCH: Added $tech_stack"
elif [[ -n "$NEW_DB" ]] && [[ "$NEW_DB" != "N/A" ]] && [[ "$NEW_DB" != "NEEDS CLARIFICATION" ]]; then
new_change_entry="- $CURRENT_BRANCH: Added $NEW_DB"
fi
# Check if sections exist in the file
local has_active_technologies=0
local has_recent_changes=0
if grep -q "^## Active Technologies" "$target_file" 2>/dev/null; then
has_active_technologies=1
fi
if grep -q "^## Recent Changes" "$target_file" 2>/dev/null; then
has_recent_changes=1
fi
# Process file line by line
local in_tech_section=false
local in_changes_section=false
local tech_entries_added=false
local changes_entries_added=false
local existing_changes_count=0
local file_ended=false
while IFS= read -r line || [[ -n "$line" ]]; do
# Handle Active Technologies section
if [[ "$line" == "## Active Technologies" ]]; then
echo "$line" >> "$temp_file"
in_tech_section=true
continue
elif [[ $in_tech_section == true ]] && [[ "$line" =~ ^##[[:space:]] ]]; then
# Add new tech entries before closing the section
if [[ $tech_entries_added == false ]] && [[ ${#new_tech_entries[@]} -gt 0 ]]; then
printf '%s\n' "${new_tech_entries[@]}" >> "$temp_file"
tech_entries_added=true
fi
echo "$line" >> "$temp_file"
in_tech_section=false
continue
elif [[ $in_tech_section == true ]] && [[ -z "$line" ]]; then
# Add new tech entries before empty line in tech section
if [[ $tech_entries_added == false ]] && [[ ${#new_tech_entries[@]} -gt 0 ]]; then
printf '%s\n' "${new_tech_entries[@]}" >> "$temp_file"
tech_entries_added=true
fi
echo "$line" >> "$temp_file"
continue
fi
# Handle Recent Changes section
if [[ "$line" == "## Recent Changes" ]]; then
echo "$line" >> "$temp_file"
# Add new change entry right after the heading
if [[ -n "$new_change_entry" ]]; then
echo "$new_change_entry" >> "$temp_file"
fi
in_changes_section=true
changes_entries_added=true
continue
elif [[ $in_changes_section == true ]] && [[ "$line" =~ ^##[[:space:]] ]]; then
echo "$line" >> "$temp_file"
in_changes_section=false
continue
elif [[ $in_changes_section == true ]] && [[ "$line" == "- "* ]]; then
# Keep only first 2 existing changes
if [[ $existing_changes_count -lt 2 ]]; then
echo "$line" >> "$temp_file"
((existing_changes_count++))
fi
continue
fi
# Update timestamp
if [[ "$line" =~ \*\*Last\ updated\*\*:.*[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] ]]; then
echo "$line" | sed "s/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/$current_date/" >> "$temp_file"
else
echo "$line" >> "$temp_file"
fi
done < "$target_file"
# Post-loop check: if we're still in the Active Technologies section and haven't added new entries
if [[ $in_tech_section == true ]] && [[ $tech_entries_added == false ]] && [[ ${#new_tech_entries[@]} -gt 0 ]]; then
printf '%s\n' "${new_tech_entries[@]}" >> "$temp_file"
tech_entries_added=true
fi
# If sections don't exist, add them at the end of the file
if [[ $has_active_technologies -eq 0 ]] && [[ ${#new_tech_entries[@]} -gt 0 ]]; then
echo "" >> "$temp_file"
echo "## Active Technologies" >> "$temp_file"
printf '%s\n' "${new_tech_entries[@]}" >> "$temp_file"
tech_entries_added=true
fi
if [[ $has_recent_changes -eq 0 ]] && [[ -n "$new_change_entry" ]]; then
echo "" >> "$temp_file"
echo "## Recent Changes" >> "$temp_file"
echo "$new_change_entry" >> "$temp_file"
changes_entries_added=true
fi
# Move temp file to target atomically
if ! mv "$temp_file" "$target_file"; then
log_error "Failed to update target file"
rm -f "$temp_file"
return 1
fi
return 0
}
#==============================================================================
# Main Agent File Update Function
#==============================================================================
update_agent_file() {
local target_file="$1"
local agent_name="$2"
if [[ -z "$target_file" ]] || [[ -z "$agent_name" ]]; then
log_error "update_agent_file requires target_file and agent_name parameters"
return 1
fi
log_info "Updating $agent_name context file: $target_file"
local project_name
project_name=$(basename "$REPO_ROOT")
local current_date
current_date=$(date +%Y-%m-%d)
# Create directory if it doesn't exist
local target_dir
target_dir=$(dirname "$target_file")
if [[ ! -d "$target_dir" ]]; then
if ! mkdir -p "$target_dir"; then
log_error "Failed to create directory: $target_dir"
return 1
fi
fi
if [[ ! -f "$target_file" ]]; then
# Create new file from template
local temp_file
temp_file=$(mktemp) || {
log_error "Failed to create temporary file"
return 1
}
if create_new_agent_file "$target_file" "$temp_file" "$project_name" "$current_date"; then
if mv "$temp_file" "$target_file"; then
log_success "Created new $agent_name context file"
else
log_error "Failed to move temporary file to $target_file"
rm -f "$temp_file"
return 1
fi
else
log_error "Failed to create new agent file"
rm -f "$temp_file"
return 1
fi
else
# Update existing file
if [[ ! -r "$target_file" ]]; then
log_error "Cannot read existing file: $target_file"
return 1
fi
if [[ ! -w "$target_file" ]]; then
log_error "Cannot write to existing file: $target_file"
return 1
fi
if update_existing_agent_file "$target_file" "$current_date"; then
log_success "Updated existing $agent_name context file"
else
log_error "Failed to update existing agent file"
return 1
fi
fi
return 0
}
#==============================================================================
# Agent Selection and Processing
#==============================================================================
update_specific_agent() {
local agent_type="$1"
case "$agent_type" in
claude)
update_agent_file "$CLAUDE_FILE" "Claude Code"
;;
gemini)
update_agent_file "$GEMINI_FILE" "Gemini CLI"
;;
copilot)
update_agent_file "$COPILOT_FILE" "GitHub Copilot"
;;
cursor-agent)
update_agent_file "$CURSOR_FILE" "Cursor IDE"
;;
qwen)
update_agent_file "$QWEN_FILE" "Qwen Code"
;;
opencode)
update_agent_file "$AGENTS_FILE" "opencode"
;;
codex)
update_agent_file "$AGENTS_FILE" "Codex CLI"
;;
windsurf)
update_agent_file "$WINDSURF_FILE" "Windsurf"
;;
kilocode)
update_agent_file "$KILOCODE_FILE" "Kilo Code"
;;
auggie)
update_agent_file "$AUGGIE_FILE" "Auggie CLI"
;;
roo)
update_agent_file "$ROO_FILE" "Roo Code"
;;
codebuddy)
update_agent_file "$CODEBUDDY_FILE" "CodeBuddy CLI"
;;
qoder)
update_agent_file "$QODER_FILE" "Qoder CLI"
;;
amp)
update_agent_file "$AMP_FILE" "Amp"
;;
shai)
update_agent_file "$SHAI_FILE" "SHAI"
;;
q)
update_agent_file "$Q_FILE" "Amazon Q Developer CLI"
;;
bob)
update_agent_file "$BOB_FILE" "IBM Bob"
;;
*)
log_error "Unknown agent type '$agent_type'"
log_error "Expected: claude|gemini|copilot|cursor-agent|qwen|opencode|codex|windsurf|kilocode|auggie|roo|amp|shai|q|bob|qoder"
exit 1
;;
esac
}
update_all_existing_agents() {
local found_agent=false
# Check each possible agent file and update if it exists
if [[ -f "$CLAUDE_FILE" ]]; then
update_agent_file "$CLAUDE_FILE" "Claude Code"
found_agent=true
fi
if [[ -f "$GEMINI_FILE" ]]; then
update_agent_file "$GEMINI_FILE" "Gemini CLI"
found_agent=true
fi
if [[ -f "$COPILOT_FILE" ]]; then
update_agent_file "$COPILOT_FILE" "GitHub Copilot"
found_agent=true
fi
if [[ -f "$CURSOR_FILE" ]]; then
update_agent_file "$CURSOR_FILE" "Cursor IDE"
found_agent=true
fi
if [[ -f "$QWEN_FILE" ]]; then
update_agent_file "$QWEN_FILE" "Qwen Code"
found_agent=true
fi
if [[ -f "$AGENTS_FILE" ]]; then
update_agent_file "$AGENTS_FILE" "Codex/opencode"
found_agent=true
fi
if [[ -f "$WINDSURF_FILE" ]]; then
update_agent_file "$WINDSURF_FILE" "Windsurf"
found_agent=true
fi
if [[ -f "$KILOCODE_FILE" ]]; then
update_agent_file "$KILOCODE_FILE" "Kilo Code"
found_agent=true
fi
if [[ -f "$AUGGIE_FILE" ]]; then
update_agent_file "$AUGGIE_FILE" "Auggie CLI"
found_agent=true
fi
if [[ -f "$ROO_FILE" ]]; then
update_agent_file "$ROO_FILE" "Roo Code"
found_agent=true
fi
if [[ -f "$CODEBUDDY_FILE" ]]; then
update_agent_file "$CODEBUDDY_FILE" "CodeBuddy CLI"
found_agent=true
fi
if [[ -f "$SHAI_FILE" ]]; then
update_agent_file "$SHAI_FILE" "SHAI"
found_agent=true
fi
if [[ -f "$QODER_FILE" ]]; then
update_agent_file "$QODER_FILE" "Qoder CLI"
found_agent=true
fi
if [[ -f "$Q_FILE" ]]; then
update_agent_file "$Q_FILE" "Amazon Q Developer CLI"
found_agent=true
fi
if [[ -f "$BOB_FILE" ]]; then
update_agent_file "$BOB_FILE" "IBM Bob"
found_agent=true
fi
# If no agent files exist, create a default Claude file
if [[ "$found_agent" == false ]]; then
log_info "No existing agent files found, creating default Claude file..."
update_agent_file "$CLAUDE_FILE" "Claude Code"
fi
}
print_summary() {
echo
log_info "Summary of changes:"
if [[ -n "$NEW_LANG" ]]; then
echo " - Added language: $NEW_LANG"
fi
if [[ -n "$NEW_FRAMEWORK" ]]; then
echo " - Added framework: $NEW_FRAMEWORK"
fi
if [[ -n "$NEW_DB" ]] && [[ "$NEW_DB" != "N/A" ]]; then
echo " - Added database: $NEW_DB"
fi
echo
log_info "Usage: $0 [claude|gemini|copilot|cursor-agent|qwen|opencode|codex|windsurf|kilocode|auggie|codebuddy|shai|q|bob|qoder]"
}
#==============================================================================
# Main Execution
#==============================================================================
main() {
# Validate environment before proceeding
validate_environment
log_info "=== Updating agent context files for feature $CURRENT_BRANCH ==="
# Parse the plan file to extract project information
if ! parse_plan_data "$NEW_PLAN"; then
log_error "Failed to parse plan data"
exit 1
fi
# Process based on agent type argument
local success=true
if [[ -z "$AGENT_TYPE" ]]; then
# No specific agent provided - update all existing agent files
log_info "No agent specified, updating all existing agent files..."
if ! update_all_existing_agents; then
success=false
fi
else
# Specific agent provided - update only that agent
log_info "Updating specific agent: $AGENT_TYPE"
if ! update_specific_agent "$AGENT_TYPE"; then
success=false
fi
fi
# Print summary
print_summary
if [[ "$success" == true ]]; then
log_success "Agent context update completed successfully"
exit 0
else
log_error "Agent context update completed with errors"
exit 1
fi
}
# Execute main function if script is run directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi

View file

@ -0,0 +1,185 @@
# Feature Specification: Fediversion - Multi-Band Jam Platform
**Feature Branch**: `001-fediversion-multi-band`
**Created**: 2025-12-28
**Status**: Draft
**Input**: Expand elmeg.xyz (Goose) to support Grateful Dead, Dead & Company, Phish, and Billy Strings
---
## Executive Summary
Fediversion is a unified "HeadyVersion" platform for multiple jam bands. It extends the proven elmeg.xyz architecture to support multiple "verticals" (bands) while sharing common infrastructure for users, social features, and the core setlist/performance tracking system.
---
## User Scenarios & Testing
### User Story 1 - Cross-Band Discovery (Priority: P1)
A jam band fan visits the platform and can browse shows and performances across multiple bands they follow (Phish, Dead & Company, Billy Strings) from a single account.
**Why this priority**: This is the core value proposition - one account, all bands.
**Independent Test**: User can register once, mark attendance at shows from different bands, and see unified activity feed.
**Acceptance Scenarios**:
1. **Given** a logged-in user, **When** they navigate to the band selector, **Then** they see all supported bands (Goose, Phish, Grateful Dead, Dead & Company, Billy Strings)
2. **Given** a user on Phish section, **When** they click a show, **Then** they see the full setlist with performance pages
3. **Given** a user with attendance records on multiple bands, **When** they view their profile, **Then** attendance is organized by band
---
### User Story 2 - Phish Fan Migration (Priority: P1)
A Phish fan can access complete setlist data, rate performances, and track their show attendance with the same depth as Phish.net but with enhanced social features.
**Why this priority**: Phish has the most complete API and largest community.
**Independent Test**: User can browse Phish shows from 1983-present, view setlists, rate performances, and see gap statistics.
**Acceptance Scenarios**:
1. **Given** complete Phish data import, **When** user searches "Tweezer", **Then** they see all 600+ performances with dates
2. **Given** a Phish show page, **When** user views setlist, **Then** they see Set 1, Set 2, Encore with segue indicators (>)
---
### User Story 3 - Dead Family Navigation (Priority: P2)
A Deadhead can navigate between Grateful Dead, Dead & Company, and related projects, with song history spanning the entire lineage.
**Why this priority**: Dead family bands share repertoire, enabling unique cross-band song tracking.
**Independent Test**: User can view "Dark Star" song page showing performances across GD, D&C, and side projects.
**Acceptance Scenarios**:
1. **Given** a song played by both GD and D&C, **When** user views song stats, **Then** they see aggregate and per-band breakdowns
2. **Given** D&C show page, **When** viewing performance, **Then** user can see "also played by Grateful Dead X times"
---
### User Story 4 - Billy Strings Fan Experience (Priority: P2)
A Billy Strings fan can access complete setlist data and engage with community features for the fast-growing bluegrass jam scene.
**Why this priority**: Billy Strings is the fastest-growing jam act, appealing to both bluegrass and jamband audiences.
**Independent Test**: User can browse all Billy Strings shows, view setlists, and rate performances.
**Acceptance Scenarios**:
1. **Given** Billy Strings data import, **When** user browses shows, **Then** they see shows from 2016-present
2. **Given** a BMFS show, **When** viewing setlist, **Then** user sees song titles, covers attributed to original artists
---
### Edge Cases
- What happens when a song is shared between multiple bands with different arrangements?
- How do we handle guest sit-ins across bands (e.g., Bobby Weir sitting in with Billy Strings)?
- How do we handle date conflicts (two bands playing same date)?
- What if a data source API becomes unavailable?
---
## Requirements
### Functional Requirements
- **FR-001**: System MUST support multiple "Verticals" (bands) with independent show/song data
- **FR-002**: System MUST allow users to track attendance across all bands from single account
- **FR-003**: System MUST import setlist data from band-specific APIs (Phish.net, Grateful Stats, etc.)
- **FR-004**: System MUST provide per-band navigation with clear visual distinction
- **FR-005**: System MUST display song gap statistics independently per band
- **FR-006**: System MUST allow performance ratings scoped to specific performances
- **FR-007**: System MUST support chase songs per band (user wants to see song X by band Y)
- **FR-008**: System SHOULD track cross-band song appearances where applicable
- **FR-009**: System SHOULD support band-specific theming/branding
### Key Entities
- **Vertical**: A band/artist (Goose, Phish, Grateful Dead, Dead & Company, Billy Strings)
- **Show**: A concert tied to a Vertical, Venue, and optional Tour
- **Song**: A composition tied to a Vertical (but may have cross-references)
- **Performance**: A specific play of a Song at a Show
- **User**: Single account spanning all Verticals
- **Attendance**: User's attendance at a Show
- **Rating/Review**: Tied to Performance, Show, or Song
---
## Success Criteria
### Measurable Outcomes
- **SC-001**: All target band data imported (500+ Phish shows, 2,000+ GD shows, 100+ D&C shows, 500+ BMFS shows)
- **SC-002**: Users can navigate between bands in <2 clicks
- **SC-003**: Search returns results across all bands in <500ms
- **SC-004**: Data import runs incrementally without duplicating existing records
- **SC-005**: Gap statistics calculate correctly per-band
---
## Data Source Specifications
### Phish.net API v5
- **Base URL**: `https://api.phish.net/v5`
- **Auth**: API key required (register at phish.net)
- **Endpoints**: `/shows`, `/setlists`, `/songs`, `/venues`
- **Rate Limit**: Unspecified, cache heavily
- **Attribution**: "Data courtesy of Phish.net"
### Grateful Stats API
- **Base URL**: `https://gratefulstats.com/api`
- **Auth**: TBD (may require key)
- **Coverage**: Grateful Dead complete, may include D&C
- **Attribution**: Required
### Setlist.fm API (Fallback)
- **Base URL**: `https://api.setlist.fm/rest/1.0`
- **Auth**: API key required
- **Coverage**: Universal, good for Billy Strings and D&C
- **Limitations**: Less structured than band-specific APIs
### Billy Strings Sources
- **bmfsdb.com**: Fan database, structure TBD
- **BillyBase (billybase.net)**: Alternative source
- **Fallback**: Setlist.fm
---
## Technical Approach
### Architecture Pattern
The existing elmeg-demo uses a `Vertical` model that already supports multi-band architecture:
```python
class Vertical(SQLModel, table=True):
id: Optional[int]
name: str # "Phish"
slug: str # "phish"
description: str
class Show(SQLModel, table=True):
vertical_id: int # Links to Vertical
# ...
class Song(SQLModel, table=True):
vertical_id: int # Links to Vertical
# ...
```
### Recommended Changes
1. **Data Import Layer**: Create pluggable importer classes per data source
2. **Frontend Routing**: Add `/{vertical}/` prefix to all routes
3. **API Scoping**: Add vertical filter to all list endpoints
4. **Theme System**: Per-vertical color/branding configuration

View file

@ -0,0 +1,28 @@
# [PROJECT NAME] Development Guidelines
Auto-generated from all feature plans. Last updated: [DATE]
## Active Technologies
[EXTRACTED FROM ALL PLAN.MD FILES]
## Project Structure
```text
[ACTUAL STRUCTURE FROM PLANS]
```
## Commands
[ONLY COMMANDS FOR ACTIVE TECHNOLOGIES]
## Code Style
[LANGUAGE-SPECIFIC, ONLY FOR LANGUAGES IN USE]
## Recent Changes
[LAST 3 FEATURES AND WHAT THEY ADDED]
<!-- MANUAL ADDITIONS START -->
<!-- MANUAL ADDITIONS END -->

View file

@ -0,0 +1,40 @@
# [CHECKLIST TYPE] Checklist: [FEATURE NAME]
**Purpose**: [Brief description of what this checklist covers]
**Created**: [DATE]
**Feature**: [Link to spec.md or relevant documentation]
**Note**: This checklist is generated by the `/speckit.checklist` command based on feature context and requirements.
<!--
============================================================================
IMPORTANT: The checklist items below are SAMPLE ITEMS for illustration only.
The /speckit.checklist command MUST replace these with actual items based on:
- User's specific checklist request
- Feature requirements from spec.md
- Technical context from plan.md
- Implementation details from tasks.md
DO NOT keep these sample items in the generated checklist file.
============================================================================
-->
## [Category 1]
- [ ] CHK001 First checklist item with clear action
- [ ] CHK002 Second checklist item
- [ ] CHK003 Third checklist item
## [Category 2]
- [ ] CHK004 Another category item
- [ ] CHK005 Item with specific criteria
- [ ] CHK006 Final item in this category
## Notes
- Check items off as completed: `[x]`
- Add comments or findings inline
- Link to relevant resources or documentation
- Items are numbered sequentially for easy reference

View file

@ -0,0 +1,104 @@
# Implementation Plan: [FEATURE]
**Branch**: `[###-feature-name]` | **Date**: [DATE] | **Spec**: [link]
**Input**: Feature specification from `/specs/[###-feature-name]/spec.md`
**Note**: This template is filled in by the `/speckit.plan` command. See `.specify/templates/commands/plan.md` for the execution workflow.
## Summary
[Extract from feature spec: primary requirement + technical approach from research]
## Technical Context
<!--
ACTION REQUIRED: Replace the content in this section with the technical details
for the project. The structure here is presented in advisory capacity to guide
the iteration process.
-->
**Language/Version**: [e.g., Python 3.11, Swift 5.9, Rust 1.75 or NEEDS CLARIFICATION]
**Primary Dependencies**: [e.g., FastAPI, UIKit, LLVM or NEEDS CLARIFICATION]
**Storage**: [if applicable, e.g., PostgreSQL, CoreData, files or N/A]
**Testing**: [e.g., pytest, XCTest, cargo test or NEEDS CLARIFICATION]
**Target Platform**: [e.g., Linux server, iOS 15+, WASM or NEEDS CLARIFICATION]
**Project Type**: [single/web/mobile - determines source structure]
**Performance Goals**: [domain-specific, e.g., 1000 req/s, 10k lines/sec, 60 fps or NEEDS CLARIFICATION]
**Constraints**: [domain-specific, e.g., <200ms p95, <100MB memory, offline-capable or NEEDS CLARIFICATION]
**Scale/Scope**: [domain-specific, e.g., 10k users, 1M LOC, 50 screens or NEEDS CLARIFICATION]
## Constitution Check
*GATE: Must pass before Phase 0 research. Re-check after Phase 1 design.*
[Gates determined based on constitution file]
## Project Structure
### Documentation (this feature)
```text
specs/[###-feature]/
├── plan.md # This file (/speckit.plan command output)
├── research.md # Phase 0 output (/speckit.plan command)
├── data-model.md # Phase 1 output (/speckit.plan command)
├── quickstart.md # Phase 1 output (/speckit.plan command)
├── contracts/ # Phase 1 output (/speckit.plan command)
└── tasks.md # Phase 2 output (/speckit.tasks command - NOT created by /speckit.plan)
```
### Source Code (repository root)
<!--
ACTION REQUIRED: Replace the placeholder tree below with the concrete layout
for this feature. Delete unused options and expand the chosen structure with
real paths (e.g., apps/admin, packages/something). The delivered plan must
not include Option labels.
-->
```text
# [REMOVE IF UNUSED] Option 1: Single project (DEFAULT)
src/
├── models/
├── services/
├── cli/
└── lib/
tests/
├── contract/
├── integration/
└── unit/
# [REMOVE IF UNUSED] Option 2: Web application (when "frontend" + "backend" detected)
backend/
├── src/
│ ├── models/
│ ├── services/
│ └── api/
└── tests/
frontend/
├── src/
│ ├── components/
│ ├── pages/
│ └── services/
└── tests/
# [REMOVE IF UNUSED] Option 3: Mobile + API (when "iOS/Android" detected)
api/
└── [same as backend above]
ios/ or android/
└── [platform-specific structure: feature modules, UI flows, platform tests]
```
**Structure Decision**: [Document the selected structure and reference the real
directories captured above]
## Complexity Tracking
> **Fill ONLY if Constitution Check has violations that must be justified**
| Violation | Why Needed | Simpler Alternative Rejected Because |
|-----------|------------|-------------------------------------|
| [e.g., 4th project] | [current need] | [why 3 projects insufficient] |
| [e.g., Repository pattern] | [specific problem] | [why direct DB access insufficient] |

View file

@ -0,0 +1,115 @@
# Feature Specification: [FEATURE NAME]
**Feature Branch**: `[###-feature-name]`
**Created**: [DATE]
**Status**: Draft
**Input**: User description: "$ARGUMENTS"
## User Scenarios & Testing *(mandatory)*
<!--
IMPORTANT: User stories should be PRIORITIZED as user journeys ordered by importance.
Each user story/journey must be INDEPENDENTLY TESTABLE - meaning if you implement just ONE of them,
you should still have a viable MVP (Minimum Viable Product) that delivers value.
Assign priorities (P1, P2, P3, etc.) to each story, where P1 is the most critical.
Think of each story as a standalone slice of functionality that can be:
- Developed independently
- Tested independently
- Deployed independently
- Demonstrated to users independently
-->
### User Story 1 - [Brief Title] (Priority: P1)
[Describe this user journey in plain language]
**Why this priority**: [Explain the value and why it has this priority level]
**Independent Test**: [Describe how this can be tested independently - e.g., "Can be fully tested by [specific action] and delivers [specific value]"]
**Acceptance Scenarios**:
1. **Given** [initial state], **When** [action], **Then** [expected outcome]
2. **Given** [initial state], **When** [action], **Then** [expected outcome]
---
### User Story 2 - [Brief Title] (Priority: P2)
[Describe this user journey in plain language]
**Why this priority**: [Explain the value and why it has this priority level]
**Independent Test**: [Describe how this can be tested independently]
**Acceptance Scenarios**:
1. **Given** [initial state], **When** [action], **Then** [expected outcome]
---
### User Story 3 - [Brief Title] (Priority: P3)
[Describe this user journey in plain language]
**Why this priority**: [Explain the value and why it has this priority level]
**Independent Test**: [Describe how this can be tested independently]
**Acceptance Scenarios**:
1. **Given** [initial state], **When** [action], **Then** [expected outcome]
---
[Add more user stories as needed, each with an assigned priority]
### Edge Cases
<!--
ACTION REQUIRED: The content in this section represents placeholders.
Fill them out with the right edge cases.
-->
- What happens when [boundary condition]?
- How does system handle [error scenario]?
## Requirements *(mandatory)*
<!--
ACTION REQUIRED: The content in this section represents placeholders.
Fill them out with the right functional requirements.
-->
### Functional Requirements
- **FR-001**: System MUST [specific capability, e.g., "allow users to create accounts"]
- **FR-002**: System MUST [specific capability, e.g., "validate email addresses"]
- **FR-003**: Users MUST be able to [key interaction, e.g., "reset their password"]
- **FR-004**: System MUST [data requirement, e.g., "persist user preferences"]
- **FR-005**: System MUST [behavior, e.g., "log all security events"]
*Example of marking unclear requirements:*
- **FR-006**: System MUST authenticate users via [NEEDS CLARIFICATION: auth method not specified - email/password, SSO, OAuth?]
- **FR-007**: System MUST retain user data for [NEEDS CLARIFICATION: retention period not specified]
### Key Entities *(include if feature involves data)*
- **[Entity 1]**: [What it represents, key attributes without implementation]
- **[Entity 2]**: [What it represents, relationships to other entities]
## Success Criteria *(mandatory)*
<!--
ACTION REQUIRED: Define measurable success criteria.
These must be technology-agnostic and measurable.
-->
### Measurable Outcomes
- **SC-001**: [Measurable metric, e.g., "Users can complete account creation in under 2 minutes"]
- **SC-002**: [Measurable metric, e.g., "System handles 1000 concurrent users without degradation"]
- **SC-003**: [User satisfaction metric, e.g., "90% of users successfully complete primary task on first attempt"]
- **SC-004**: [Business metric, e.g., "Reduce support tickets related to [X] by 50%"]

View file

@ -0,0 +1,251 @@
---
description: "Task list template for feature implementation"
---
# Tasks: [FEATURE NAME]
**Input**: Design documents from `/specs/[###-feature-name]/`
**Prerequisites**: plan.md (required), spec.md (required for user stories), research.md, data-model.md, contracts/
**Tests**: The examples below include test tasks. Tests are OPTIONAL - only include them if explicitly requested in the feature specification.
**Organization**: Tasks are grouped by user story to enable independent implementation and testing of each story.
## Format: `[ID] [P?] [Story] Description`
- **[P]**: Can run in parallel (different files, no dependencies)
- **[Story]**: Which user story this task belongs to (e.g., US1, US2, US3)
- Include exact file paths in descriptions
## Path Conventions
- **Single project**: `src/`, `tests/` at repository root
- **Web app**: `backend/src/`, `frontend/src/`
- **Mobile**: `api/src/`, `ios/src/` or `android/src/`
- Paths shown below assume single project - adjust based on plan.md structure
<!--
============================================================================
IMPORTANT: The tasks below are SAMPLE TASKS for illustration purposes only.
The /speckit.tasks command MUST replace these with actual tasks based on:
- User stories from spec.md (with their priorities P1, P2, P3...)
- Feature requirements from plan.md
- Entities from data-model.md
- Endpoints from contracts/
Tasks MUST be organized by user story so each story can be:
- Implemented independently
- Tested independently
- Delivered as an MVP increment
DO NOT keep these sample tasks in the generated tasks.md file.
============================================================================
-->
## Phase 1: Setup (Shared Infrastructure)
**Purpose**: Project initialization and basic structure
- [ ] T001 Create project structure per implementation plan
- [ ] T002 Initialize [language] project with [framework] dependencies
- [ ] T003 [P] Configure linting and formatting tools
---
## Phase 2: Foundational (Blocking Prerequisites)
**Purpose**: Core infrastructure that MUST be complete before ANY user story can be implemented
**⚠️ CRITICAL**: No user story work can begin until this phase is complete
Examples of foundational tasks (adjust based on your project):
- [ ] T004 Setup database schema and migrations framework
- [ ] T005 [P] Implement authentication/authorization framework
- [ ] T006 [P] Setup API routing and middleware structure
- [ ] T007 Create base models/entities that all stories depend on
- [ ] T008 Configure error handling and logging infrastructure
- [ ] T009 Setup environment configuration management
**Checkpoint**: Foundation ready - user story implementation can now begin in parallel
---
## Phase 3: User Story 1 - [Title] (Priority: P1) 🎯 MVP
**Goal**: [Brief description of what this story delivers]
**Independent Test**: [How to verify this story works on its own]
### Tests for User Story 1 (OPTIONAL - only if tests requested) ⚠️
> **NOTE: Write these tests FIRST, ensure they FAIL before implementation**
- [ ] T010 [P] [US1] Contract test for [endpoint] in tests/contract/test_[name].py
- [ ] T011 [P] [US1] Integration test for [user journey] in tests/integration/test_[name].py
### Implementation for User Story 1
- [ ] T012 [P] [US1] Create [Entity1] model in src/models/[entity1].py
- [ ] T013 [P] [US1] Create [Entity2] model in src/models/[entity2].py
- [ ] T014 [US1] Implement [Service] in src/services/[service].py (depends on T012, T013)
- [ ] T015 [US1] Implement [endpoint/feature] in src/[location]/[file].py
- [ ] T016 [US1] Add validation and error handling
- [ ] T017 [US1] Add logging for user story 1 operations
**Checkpoint**: At this point, User Story 1 should be fully functional and testable independently
---
## Phase 4: User Story 2 - [Title] (Priority: P2)
**Goal**: [Brief description of what this story delivers]
**Independent Test**: [How to verify this story works on its own]
### Tests for User Story 2 (OPTIONAL - only if tests requested) ⚠️
- [ ] T018 [P] [US2] Contract test for [endpoint] in tests/contract/test_[name].py
- [ ] T019 [P] [US2] Integration test for [user journey] in tests/integration/test_[name].py
### Implementation for User Story 2
- [ ] T020 [P] [US2] Create [Entity] model in src/models/[entity].py
- [ ] T021 [US2] Implement [Service] in src/services/[service].py
- [ ] T022 [US2] Implement [endpoint/feature] in src/[location]/[file].py
- [ ] T023 [US2] Integrate with User Story 1 components (if needed)
**Checkpoint**: At this point, User Stories 1 AND 2 should both work independently
---
## Phase 5: User Story 3 - [Title] (Priority: P3)
**Goal**: [Brief description of what this story delivers]
**Independent Test**: [How to verify this story works on its own]
### Tests for User Story 3 (OPTIONAL - only if tests requested) ⚠️
- [ ] T024 [P] [US3] Contract test for [endpoint] in tests/contract/test_[name].py
- [ ] T025 [P] [US3] Integration test for [user journey] in tests/integration/test_[name].py
### Implementation for User Story 3
- [ ] T026 [P] [US3] Create [Entity] model in src/models/[entity].py
- [ ] T027 [US3] Implement [Service] in src/services/[service].py
- [ ] T028 [US3] Implement [endpoint/feature] in src/[location]/[file].py
**Checkpoint**: All user stories should now be independently functional
---
[Add more user story phases as needed, following the same pattern]
---
## Phase N: Polish & Cross-Cutting Concerns
**Purpose**: Improvements that affect multiple user stories
- [ ] TXXX [P] Documentation updates in docs/
- [ ] TXXX Code cleanup and refactoring
- [ ] TXXX Performance optimization across all stories
- [ ] TXXX [P] Additional unit tests (if requested) in tests/unit/
- [ ] TXXX Security hardening
- [ ] TXXX Run quickstart.md validation
---
## Dependencies & Execution Order
### Phase Dependencies
- **Setup (Phase 1)**: No dependencies - can start immediately
- **Foundational (Phase 2)**: Depends on Setup completion - BLOCKS all user stories
- **User Stories (Phase 3+)**: All depend on Foundational phase completion
- User stories can then proceed in parallel (if staffed)
- Or sequentially in priority order (P1 → P2 → P3)
- **Polish (Final Phase)**: Depends on all desired user stories being complete
### User Story Dependencies
- **User Story 1 (P1)**: Can start after Foundational (Phase 2) - No dependencies on other stories
- **User Story 2 (P2)**: Can start after Foundational (Phase 2) - May integrate with US1 but should be independently testable
- **User Story 3 (P3)**: Can start after Foundational (Phase 2) - May integrate with US1/US2 but should be independently testable
### Within Each User Story
- Tests (if included) MUST be written and FAIL before implementation
- Models before services
- Services before endpoints
- Core implementation before integration
- Story complete before moving to next priority
### Parallel Opportunities
- All Setup tasks marked [P] can run in parallel
- All Foundational tasks marked [P] can run in parallel (within Phase 2)
- Once Foundational phase completes, all user stories can start in parallel (if team capacity allows)
- All tests for a user story marked [P] can run in parallel
- Models within a story marked [P] can run in parallel
- Different user stories can be worked on in parallel by different team members
---
## Parallel Example: User Story 1
```bash
# Launch all tests for User Story 1 together (if tests requested):
Task: "Contract test for [endpoint] in tests/contract/test_[name].py"
Task: "Integration test for [user journey] in tests/integration/test_[name].py"
# Launch all models for User Story 1 together:
Task: "Create [Entity1] model in src/models/[entity1].py"
Task: "Create [Entity2] model in src/models/[entity2].py"
```
---
## Implementation Strategy
### MVP First (User Story 1 Only)
1. Complete Phase 1: Setup
2. Complete Phase 2: Foundational (CRITICAL - blocks all stories)
3. Complete Phase 3: User Story 1
4. **STOP and VALIDATE**: Test User Story 1 independently
5. Deploy/demo if ready
### Incremental Delivery
1. Complete Setup + Foundational → Foundation ready
2. Add User Story 1 → Test independently → Deploy/Demo (MVP!)
3. Add User Story 2 → Test independently → Deploy/Demo
4. Add User Story 3 → Test independently → Deploy/Demo
5. Each story adds value without breaking previous stories
### Parallel Team Strategy
With multiple developers:
1. Team completes Setup + Foundational together
2. Once Foundational is done:
- Developer A: User Story 1
- Developer B: User Story 2
- Developer C: User Story 3
3. Stories complete and integrate independently
---
## Notes
- [P] tasks = different files, no dependencies
- [Story] label maps task to specific user story for traceability
- Each user story should be independently completable and testable
- Verify tests fail before implementing
- Commit after each task or logical group
- Stop at any checkpoint to validate story independently
- Avoid: vague tasks, same file conflicts, cross-story dependencies that break independence

48
DEPLOY.md Normal file
View file

@ -0,0 +1,48 @@
# Deployment Guide
## Prerequisites
- Docker & Docker Compose
- Git
## Steps
1. **Clone the repository** (if not already on the server):
```bash
git clone <repo-url>
cd elmeg
```
2. **Environment Variables**:
Create a `.env` file in the root directory (or rely on `docker-compose.yml` defaults for dev).
For production, you should set:
```env
POSTGRES_USER=your_user
POSTGRES_PASSWORD=your_password
POSTGRES_DB=elmeg_db
SECRET_KEY=your_production_secret_key
```
3. **Build and Run**:
```bash
docker-compose up --build -d
```
4. **Run Migrations**:
The backend container needs to run migrations.
```bash
docker-compose exec backend alembic upgrade head
```
5. **Access the App**:
- Frontend: `http://localhost:3000` (or your server IP)
- Backend API: `http://localhost:8000`
## Troubleshooting
- **Database Connection**: Ensure the `backend` service can reach `db`. The `DATABASE_URL` in `docker-compose.yml` should match the postgres credentials.
- **API Connectivity**: If the frontend (SSR) fails to fetch data, check `INTERNAL_API_URL` in `docker-compose.yml`. It should point to `http://backend:8000`.

125
LOCAL_DEV.md Normal file
View file

@ -0,0 +1,125 @@
# Local Development Setup (No Docker)
## Backend Setup
1. **Create Virtual Environment** (if not already done):
```bash
cd backend
python3 -m venv venv
source venv/bin/activate # On Mac/Linux
```
2. **Install Dependencies**:
```bash
pip install -r requirements.txt
```
3. **Set Environment Variables**:
```bash
export DATABASE_URL="sqlite:///./elmeg.db"
export SECRET_KEY="your-secret-key-for-jwt"
```
4. **Run Migrations**:
```bash
alembic upgrade head
```
5. **Start Backend**:
```bash
uvicorn main:app --reload --port 8000
```
Backend will be available at: `http://localhost:8000`
---
## Frontend Setup
1. **Install Dependencies**:
```bash
cd frontend
npm install
```
2. **Set Environment Variables**:
Create `frontend/.env.local`:
```
NEXT_PUBLIC_API_URL=http://localhost:8000
```
3. **Start Frontend**:
```bash
npm run dev
```
Frontend will be available at: `http://localhost:3000`
---
## Testing the Application
1. **Create a User**:
- Navigate to `http://localhost:3000`
- Register a new account
2. **Test Features**:
- Browse shows at `/archive`
- Search with `Cmd+K`
- Create a group at `/groups`
- Check settings at `/settings`
- View admin dashboard at `/admin` (if superuser)
3. **Create Superuser** (for admin access):
```bash
# In backend directory with venv activated
python -c "
from database import engine
from models import User
from sqlmodel import Session, select
from passlib.context import CryptContext
pwd_context = CryptContext(schemes=['bcrypt'], deprecated='auto')
with Session(engine) as session:
user = session.exec(select(User).where(User.email == 'your@email.com')).first()
if user:
user.is_superuser = True
user.role = 'admin'
session.add(user)
session.commit()
print(f'User {user.email} is now a superuser')
else:
print('User not found')
"
```
---
## Common Issues
### Backend won't start
- Check if port 8000 is already in use: `lsof -i :8000`
- Ensure virtual environment is activated
- Verify all dependencies installed: `pip list`
### Frontend won't start
- Check if port 3000 is already in use: `lsof -i :3000`
- Clear `.next` cache: `rm -rf .next`
- Reinstall dependencies: `rm -rf node_modules && npm install`
### Database issues
- Delete and recreate: `rm elmeg.db` then `alembic upgrade head`
- Check migration status: `alembic current`

121
README.md Normal file
View file

@ -0,0 +1,121 @@
# Fediversion
**The ultimate HeadyVersion platform for ALL jam bands.**
Fediversion is a unified setlist tracking, rating, and community platform supporting multiple jam bands from a single account.
## Supported Bands
| Band | Data Source | Status |
|------|-------------|--------|
| 🦆 Goose | El Goose API | ✅ Active |
| 🐟 Phish | Phish.net API v5 | 🔄 Ready |
| 💀 Grateful Dead | Grateful Stats API | 🔄 Ready |
| ⚡ Dead & Company | Setlist.fm | 🔄 Ready |
| 🎸 Billy Strings | Setlist.fm | 🔄 Ready |
## Quick Start
### Prerequisites
- Python 3.11+
- Node.js 18+
- PostgreSQL (optional, SQLite works for dev)
### 1. Backend (Port 8000)
```bash
cd backend
pip install -r requirements.txt
# Set API keys for data import (optional)
export PHISHNET_API_KEY="your-key"
export SETLISTFM_API_KEY="your-key"
# Run migrations
alembic upgrade head
# Start server
uvicorn main:app --reload --port 8000
```
### 2. Frontend (Port 3000)
```bash
cd frontend
npm install
npm run dev
```
### 3. Import Band Data
```bash
cd backend
# Import Goose (existing)
python import_elgoose.py
# Import Phish
python -m importers.phish
# Import Grateful Dead
python -m importers.grateful_dead
# Import Dead & Company
python -m importers.setlistfm deadco
# Import Billy Strings
python -m importers.setlistfm bmfs
```
## API Keys
| Service | Get Key At | Required For |
|---------|------------|--------------|
| Phish.net | <https://phish.net/api> | Phish data |
| Setlist.fm | <https://api.setlist.fm> | D&C, Billy Strings |
| Grateful Stats | <https://gratefulstats.com> | Grateful Dead |
## Architecture
```
fediversion/
├── backend/
│ ├── importers/ # Band-specific data importers
│ │ ├── base.py # Abstract base class
│ │ ├── phish.py # Phish.net API
│ │ ├── grateful_dead.py # Grateful Stats API
│ │ └── setlistfm.py # D&C, Billy Strings
│ ├── routers/ # API endpoints
│ ├── models.py # SQLModel database models
│ └── main.py # FastAPI app
├── frontend/
│ ├── app/ # Next.js 14 app router
│ └── components/ # React components
└── docker-compose.yml
```
## Core Concept: Verticals
Fediversion uses the "Vertical" model to support multiple bands:
```python
class Vertical(SQLModel):
name: str # "Phish"
slug: str # "phish"
description: str
class Show(SQLModel):
vertical_id: int # Links to band
# ...
```
Routes support both single-band (`/shows`) and multi-band (`/phish/shows`) patterns.
## Based On
Fediversion is forked from [elmeg-demo](https://git.runfoo.run/runfoo-org/elmeg-demo) (elmeg.xyz), the Goose setlist platform.
## License
MIT

130
VPS_HANDOFF.md Normal file
View file

@ -0,0 +1,130 @@
# Handoff to VPS Agent
**Project:** Elmeg
**Date:** 2025-12-03
**Status:** Feature Complete / Ready for Deployment
## 1. Summary of Changes
We have implemented seven major feature sets:
1. **Advanced Content (Performance Nicknames)**:
* **Backend**: Added `PerformanceNickname` model. API endpoints for suggesting and approving nicknames.
* **Frontend**: "Suggest Nickname" dialog on Show Detail page. Display of approved nicknames on the setlist.
2. **Review System**:
* **Backend**: Added `Review` model supporting multiple entity types (Show, Venue, Song, Performance, Tour, Year).
* **Frontend**: Generic `EntityReviews` component. Integrated into Show Detail page.
3. **Groups / Communities**:
* **Backend**: Added `Group`, `GroupMember`, `GroupPost` models and APIs.
* **Frontend**: `GroupsPage` (list), `GroupDetailPage` (feed), `CreateGroupPage`.
4. **User Profile Enhancements**:
* **Backend**: Added `routers/users.py` for fetching user stats, attendance, reviews, and groups.
* **Frontend**: Updated `ProfilePage` with tabs for Overview, Attendance, Reviews, and Groups.
5. **Global Search**:
* **Backend**: Added `routers/search.py` for multi-entity search (Songs, Venues, Tours, Groups, Users, Nicknames, Performances).
* **Frontend**: Implemented `Cmd+K` dialog with `cmdk` and `shadcn/ui`.
6. **Performance Pages**:
* **Backend**: Added `routers/performances.py` with logic to calculate "Gap" and "Times Played" stats, and identify Previous/Next performances.
* **Frontend**: Created `/performances/[id]` page with stats, navigation, and social features.
7. **Notifications**:
* **Backend**: Added `Notification` model and `routers/notifications.py`. Implemented logic to notify group owners on new member joins.
* **Frontend**: Added `NotificationBell` to Navbar with unread count and popover list.
## 2. Technical Updates
* **Database**:
* New tables/columns added via Alembic migrations.
* **Critical**: Migration `6659cb1e0ca5_add_review_targets.py` fixed.
* **New**: Migration `1305863562e7_add_groups.py` added.
* **New**: Migration `a526deda28e0_add_notifications.py` added.
* **Dependencies**:
* Added `psycopg2-binary` to `backend/requirements.txt` for PostgreSQL support.
* Added `argon2-cffi` for improved password hashing.
* **Frontend Config**:
* Added `lib/api-config.ts` to handle API URL resolution (`getApiUrl()`) which correctly distinguishes between Server-Side Rendering (internal Docker network) and Client-Side (public URL).
## 3. Deployment Instructions
### Option A: Docker Compose (Recommended)
If the VPS has Docker and Docker Compose:
1. **Update Codebase**: Pull the latest changes to the server.
2. **Rebuild Containers**:
```bash
docker-compose up --build -d
```
3. **Run Migrations**:
```bash
docker-compose exec backend alembic upgrade head
```
4. **Verify**: Check logs to ensure services started correctly.
```bash
docker-compose logs -f
```
### Option B: Manual / Bare Metal
If running services directly (Systemd/PM2):
1. **Backend**:
* Activate virtual environment.
* Install new requirements:
```bash
pip install -r backend/requirements.txt
```
* Run migrations:
```bash
cd backend
alembic upgrade head
```
* Restart Backend Service (e.g., `systemctl restart elmeg-backend`).
2. **Frontend**:
* Install dependencies:
```bash
cd frontend
npm install
```
* Build the application:
```bash
npm run build
```
* Restart Frontend Service (e.g., `pm2 restart elmeg-frontend`).
## 4. Verification Steps
1. **Navigate to a Show Page**: Ensure the page loads (tests SSR connectivity).
2. **Check Reviews**: Verify the "Reviews" section is visible at the bottom.
3. **Check Groups**: Navigate to `/groups`, create a group, and post a message.
4. **Check Profile**: Log in and verify your profile shows your attendance, reviews, and groups.
5. **Test Search**: Press `Cmd+K` (or `Ctrl+K`) and search for "Tweezer" (Song) or "Tahoe Tweezer" (Nickname).
1. **Navigate to a Show Page**: Ensure the page loads (tests SSR connectivity).
2. **Check Reviews**: Verify the "Reviews" section is visible at the bottom.
3. **Check Groups**: Navigate to `/groups`, create a group, and post a message.
4. **Check Profile**: Log in and verify your profile shows your attendance, reviews, and groups.
5. **Test Search**: Press `Cmd+K` (or `Ctrl+K`) and search for "Tweezer" (Song) or "Tahoe Tweezer" (Nickname).
6. **Check Performance Page**: Click a search result for a Performance or Nickname and verify you land on `/performances/[id]`.
7. **Test Navigation**: On a Performance Page, click "Previous Version" or "Next Version" to traverse the song's history.
8. **Test Notifications**: Have another user join a group you created and verify the bell icon updates.
## 5. Known Issues / Notes
* **Environment Variables**: Ensure `DATABASE_URL` is set correctly in the backend environment. Ensure `INTERNAL_API_URL` is set for the frontend if using Docker (e.g., `http://backend:8000`).
## 6. Future Roadmap
See [docs/ROADMAP.md](docs/ROADMAP.md) for the detailed plan regarding Cross-Vertical Federation, Wiki Mode, Moderation, and Advanced Stats.

11
backend/Dockerfile Normal file
View file

@ -0,0 +1,11 @@
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
# Run migrations then start server (shell form handles permissions)
CMD ["sh", "start.sh"]

147
backend/alembic.ini Normal file
View file

@ -0,0 +1,147 @@
# A generic, single database configuration.
[alembic]
# path to migration scripts.
# this is typically a path given in POSIX (e.g. forward slashes)
# format, relative to the token %(here)s which refers to the location of this
# ini file
script_location = %(here)s/alembic
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
# for all available tokens
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
# sys.path path, will be prepended to sys.path if present.
# defaults to the current working directory. for multiple paths, the path separator
# is defined by "path_separator" below.
prepend_sys_path = .
# timezone to use when rendering the date within the migration file
# as well as the filename.
# If specified, requires the tzdata library which can be installed by adding
# `alembic[tz]` to the pip requirements.
# string value is passed to ZoneInfo()
# leave blank for localtime
# timezone =
# max length of characters to apply to the "slug" field
# truncate_slug_length = 40
# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false
# version location specification; This defaults
# to <script_location>/versions. When using multiple version
# directories, initial revisions must be specified with --version-path.
# The path separator used here should be the separator specified by "path_separator"
# below.
# version_locations = %(here)s/bar:%(here)s/bat:%(here)s/alembic/versions
# path_separator; This indicates what character is used to split lists of file
# paths, including version_locations and prepend_sys_path within configparser
# files such as alembic.ini.
# The default rendered in new alembic.ini files is "os", which uses os.pathsep
# to provide os-dependent path splitting.
#
# Note that in order to support legacy alembic.ini files, this default does NOT
# take place if path_separator is not present in alembic.ini. If this
# option is omitted entirely, fallback logic is as follows:
#
# 1. Parsing of the version_locations option falls back to using the legacy
# "version_path_separator" key, which if absent then falls back to the legacy
# behavior of splitting on spaces and/or commas.
# 2. Parsing of the prepend_sys_path option falls back to the legacy
# behavior of splitting on spaces, commas, or colons.
#
# Valid values for path_separator are:
#
# path_separator = :
# path_separator = ;
# path_separator = space
# path_separator = newline
#
# Use os.pathsep. Default configuration used for new projects.
path_separator = os
# set to 'true' to search source files recursively
# in each "version_locations" directory
# new in Alembic version 1.10
# recursive_version_locations = false
# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8
# database URL. This is consumed by the user-maintained env.py script only.
# other means of configuring database URLs may be customized within the env.py
# file.
sqlalchemy.url = driver://user:pass@localhost/dbname
[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run
# on newly generated revision scripts. See the documentation for further
# detail and examples
# format using "black" - use the console_scripts runner, against the "black" entrypoint
# hooks = black
# black.type = console_scripts
# black.entrypoint = black
# black.options = -l 79 REVISION_SCRIPT_FILENAME
# lint with attempts to fix using "ruff" - use the module runner, against the "ruff" module
# hooks = ruff
# ruff.type = module
# ruff.module = ruff
# ruff.options = check --fix REVISION_SCRIPT_FILENAME
# Alternatively, use the exec runner to execute a binary found on your PATH
# hooks = ruff
# ruff.type = exec
# ruff.executable = ruff
# ruff.options = check --fix REVISION_SCRIPT_FILENAME
# Logging configuration. This is also consumed by the user-maintained
# env.py script only.
[loggers]
keys = root,sqlalchemy,alembic
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARNING
handlers = console
qualname =
[logger_sqlalchemy]
level = WARNING
handlers =
qualname = sqlalchemy.engine
[logger_alembic]
level = INFO
handlers =
qualname = alembic
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S

1
backend/alembic/README Normal file
View file

@ -0,0 +1 @@
Generic single-database configuration.

79
backend/alembic/env.py Normal file
View file

@ -0,0 +1,79 @@
from logging.config import fileConfig
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from alembic import context
# Import SQLModel and your models
from sqlmodel import SQLModel
from database import DATABASE_URL
import models # This registers the models with SQLModel.metadata
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
# target_metadata = None
target_metadata = SQLModel.metadata
# Override sqlalchemy.url with our DATABASE_URL
config.set_main_option("sqlalchemy.url", DATABASE_URL)
def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online() -> None:
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
render_as_batch=True
)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

View file

@ -0,0 +1,28 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision: str = ${repr(up_revision)}
down_revision: Union[str, Sequence[str], None] = ${repr(down_revision)}
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
def upgrade() -> None:
"""Upgrade schema."""
${upgrades if upgrades else "pass"}
def downgrade() -> None:
"""Downgrade schema."""
${downgrades if downgrades else "pass"}

View file

@ -0,0 +1,76 @@
"""add_groups
Revision ID: 1305863562e7
Revises: 6659cb1e0ca5
Create Date: 2025-12-03 14:49:44.973922
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import sqlmodel
# revision identifiers, used by Alembic.
revision: str = '1305863562e7'
down_revision: Union[str, Sequence[str], None] = '6659cb1e0ca5'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('group',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('privacy', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('created_by', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['created_by'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('group', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_group_name'), ['name'], unique=True)
op.create_table('groupmember',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('group_id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('role', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('joined_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['group_id'], ['group.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('grouppost',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('group_id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('content', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['group_id'], ['group.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
# with op.batch_alter_table('review', schema=None) as batch_op:
# batch_op.drop_column('created_at')
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('review', schema=None) as batch_op:
batch_op.add_column(sa.Column('created_at', sa.DATETIME(), nullable=False))
op.drop_table('grouppost')
op.drop_table('groupmember')
with op.batch_alter_table('group', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_group_name'))
op.drop_table('group')
# ### end Alembic commands ###

View file

@ -0,0 +1,42 @@
"""Add user preferences
Revision ID: 32ebf231693a
Revises: a0b7abe57112
Create Date: 2025-12-02 02:46:02.955217
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import sqlmodel
# revision identifiers, used by Alembic.
revision: str = '32ebf231693a'
down_revision: Union[str, Sequence[str], None] = 'a0b7abe57112'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('userpreferences',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('wiki_mode', sa.Boolean(), nullable=False),
sa.Column('show_ratings', sa.Boolean(), nullable=False),
sa.Column('show_comments', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('user_id')
)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('userpreferences')
# ### end Alembic commands ###

View file

@ -0,0 +1,58 @@
"""Add gamification models
Revision ID: 341b95b6e098
Revises: 366067fc1318
Create Date: 2025-12-02 02:59:20.293100
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import sqlmodel
# revision identifiers, used by Alembic.
revision: str = '341b95b6e098'
down_revision: Union[str, Sequence[str], None] = '366067fc1318'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('badge',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('icon', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('badge', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_badge_name'), ['name'], unique=True)
batch_op.create_index(batch_op.f('ix_badge_slug'), ['slug'], unique=True)
op.create_table('userbadge',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('badge_id', sa.Integer(), nullable=False),
sa.Column('awarded_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['badge_id'], ['badge.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('userbadge')
with op.batch_alter_table('badge', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_badge_slug'))
batch_op.drop_index(batch_op.f('ix_badge_name'))
op.drop_table('badge')
# ### end Alembic commands ###

View file

@ -0,0 +1,48 @@
"""Add review system
Revision ID: 366067fc1318
Revises: 32ebf231693a
Create Date: 2025-12-02 02:50:57.830097
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import sqlmodel
# revision identifiers, used by Alembic.
revision: str = '366067fc1318'
down_revision: Union[str, Sequence[str], None] = '32ebf231693a'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('review',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('blurb', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('content', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('score', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('show_id', sa.Integer(), nullable=True),
sa.Column('venue_id', sa.Integer(), nullable=True),
sa.Column('song_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['show_id'], ['show.id'], ),
sa.ForeignKeyConstraint(['song_id'], ['song.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.ForeignKeyConstraint(['venue_id'], ['venue.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('review')
# ### end Alembic commands ###

View file

@ -0,0 +1,213 @@
"""Add slugs
Revision ID: 65c515b4722a
Revises: e50a60c5d343
Create Date: 2025-12-21 20:24:07.968495
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import sqlmodel
# revision identifiers, used by Alembic.
revision: str = '65c515b4722a'
down_revision: Union[str, Sequence[str], None] = 'e50a60c5d343'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
# op.create_table('reaction',
# sa.Column('id', sa.Integer(), nullable=False),
# sa.Column('user_id', sa.Integer(), nullable=False),
# sa.Column('entity_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
# sa.Column('entity_id', sa.Integer(), nullable=False),
# sa.Column('emoji', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
# sa.Column('created_at', sa.DateTime(), nullable=False),
# sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
# sa.PrimaryKeyConstraint('id')
# )
# with op.batch_alter_table('reaction', schema=None) as batch_op:
# batch_op.create_index(batch_op.f('ix_reaction_entity_id'), ['entity_id'], unique=False)
# batch_op.create_index(batch_op.f('ix_reaction_entity_type'), ['entity_type'], unique=False)
# op.create_table('chasesong',
# sa.Column('id', sa.Integer(), nullable=False),
# sa.Column('user_id', sa.Integer(), nullable=False),
# sa.Column('song_id', sa.Integer(), nullable=False),
# sa.Column('priority', sa.Integer(), nullable=False),
# sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
# sa.Column('created_at', sa.DateTime(), nullable=False),
# sa.Column('caught_at', sa.DateTime(), nullable=True),
# sa.Column('caught_show_id', sa.Integer(), nullable=True),
# sa.ForeignKeyConstraint(['caught_show_id'], ['show.id'], ),
# sa.ForeignKeyConstraint(['song_id'], ['song.id'], ),
# sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
# sa.PrimaryKeyConstraint('id')
# )
# with op.batch_alter_table('chasesong', schema=None) as batch_op:
# batch_op.create_index(batch_op.f('ix_chasesong_song_id'), ['song_id'], unique=False)
# batch_op.create_index(batch_op.f('ix_chasesong_user_id'), ['user_id'], unique=False)
# with op.batch_alter_table('badge', schema=None) as batch_op:
# batch_op.add_column(sa.Column('tier', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
# batch_op.add_column(sa.Column('category', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
# batch_op.add_column(sa.Column('xp_reward', sa.Integer(), nullable=False))
with op.batch_alter_table('comment', schema=None) as batch_op:
batch_op.add_column(sa.Column('parent_id', sa.Integer(), nullable=True))
batch_op.create_foreign_key('fk_comment_parent_id', 'comment', ['parent_id'], ['id'])
with op.batch_alter_table('performance', schema=None) as batch_op:
batch_op.add_column(sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.add_column(sa.Column('track_url', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.add_column(sa.Column('youtube_link', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.create_index(batch_op.f('ix_performance_slug'), ['slug'], unique=True)
with op.batch_alter_table('rating', schema=None) as batch_op:
batch_op.add_column(sa.Column('performance_id', sa.Integer(), nullable=True))
batch_op.add_column(sa.Column('venue_id', sa.Integer(), nullable=True))
batch_op.add_column(sa.Column('tour_id', sa.Integer(), nullable=True))
batch_op.alter_column('score',
existing_type=sa.INTEGER(),
type_=sa.Float(),
existing_nullable=False)
batch_op.create_foreign_key('fk_rating_tour_id', 'tour', ['tour_id'], ['id'])
batch_op.create_foreign_key('fk_rating_performance_id', 'performance', ['performance_id'], ['id'])
batch_op.create_foreign_key('fk_rating_venue_id', 'venue', ['venue_id'], ['id'])
with op.batch_alter_table('review', schema=None) as batch_op:
batch_op.alter_column('score',
existing_type=sa.INTEGER(),
type_=sa.Float(),
existing_nullable=False)
with op.batch_alter_table('show', schema=None) as batch_op:
batch_op.add_column(sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.add_column(sa.Column('bandcamp_link', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.add_column(sa.Column('nugs_link', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.add_column(sa.Column('youtube_link', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.create_index(batch_op.f('ix_show_slug'), ['slug'], unique=True)
with op.batch_alter_table('song', schema=None) as batch_op:
batch_op.add_column(sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.add_column(sa.Column('youtube_link', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.create_index(batch_op.f('ix_song_slug'), ['slug'], unique=True)
with op.batch_alter_table('tour', schema=None) as batch_op:
batch_op.add_column(sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.create_index(batch_op.f('ix_tour_slug'), ['slug'], unique=True)
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.add_column(sa.Column('xp', sa.Integer(), nullable=False, server_default="0"))
batch_op.add_column(sa.Column('level', sa.Integer(), nullable=False, server_default="1"))
batch_op.add_column(sa.Column('streak_days', sa.Integer(), nullable=False, server_default="0"))
batch_op.add_column(sa.Column('last_activity', sa.DateTime(), nullable=True))
batch_op.add_column(sa.Column('custom_title', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.add_column(sa.Column('title_color', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.add_column(sa.Column('flair', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.add_column(sa.Column('is_early_adopter', sa.Boolean(), nullable=False, server_default="0"))
batch_op.add_column(sa.Column('is_supporter', sa.Boolean(), nullable=False, server_default="0"))
batch_op.add_column(sa.Column('joined_at', sa.DateTime(), nullable=False, server_default=sa.func.now()))
batch_op.add_column(sa.Column('email_verified', sa.Boolean(), nullable=False, server_default="0"))
batch_op.add_column(sa.Column('verification_token', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.add_column(sa.Column('verification_token_expires', sa.DateTime(), nullable=True))
batch_op.add_column(sa.Column('reset_token', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.add_column(sa.Column('reset_token_expires', sa.DateTime(), nullable=True))
with op.batch_alter_table('venue', schema=None) as batch_op:
batch_op.add_column(sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.create_index(batch_op.f('ix_venue_slug'), ['slug'], unique=True)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('venue', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_venue_slug'))
batch_op.drop_column('slug')
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_column('reset_token_expires')
batch_op.drop_column('reset_token')
batch_op.drop_column('verification_token_expires')
batch_op.drop_column('verification_token')
batch_op.drop_column('email_verified')
batch_op.drop_column('joined_at')
batch_op.drop_column('is_supporter')
batch_op.drop_column('is_early_adopter')
batch_op.drop_column('flair')
batch_op.drop_column('title_color')
batch_op.drop_column('custom_title')
batch_op.drop_column('last_activity')
batch_op.drop_column('streak_days')
batch_op.drop_column('level')
batch_op.drop_column('xp')
with op.batch_alter_table('tour', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_tour_slug'))
batch_op.drop_column('slug')
with op.batch_alter_table('song', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_song_slug'))
batch_op.drop_column('youtube_link')
batch_op.drop_column('slug')
with op.batch_alter_table('show', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_show_slug'))
batch_op.drop_column('youtube_link')
batch_op.drop_column('nugs_link')
batch_op.drop_column('bandcamp_link')
batch_op.drop_column('slug')
with op.batch_alter_table('review', schema=None) as batch_op:
batch_op.alter_column('score',
existing_type=sa.Float(),
type_=sa.INTEGER(),
existing_nullable=False)
with op.batch_alter_table('rating', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.alter_column('score',
existing_type=sa.Float(),
type_=sa.INTEGER(),
existing_nullable=False)
batch_op.drop_column('tour_id')
batch_op.drop_column('venue_id')
batch_op.drop_column('performance_id')
with op.batch_alter_table('performance', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_performance_slug'))
batch_op.drop_column('youtube_link')
batch_op.drop_column('track_url')
batch_op.drop_column('slug')
with op.batch_alter_table('comment', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.drop_column('parent_id')
with op.batch_alter_table('badge', schema=None) as batch_op:
batch_op.drop_column('xp_reward')
batch_op.drop_column('category')
batch_op.drop_column('tier')
with op.batch_alter_table('chasesong', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_chasesong_user_id'))
batch_op.drop_index(batch_op.f('ix_chasesong_song_id'))
op.drop_table('chasesong')
with op.batch_alter_table('reaction', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_reaction_entity_type'))
batch_op.drop_index(batch_op.f('ix_reaction_entity_id'))
op.drop_table('reaction')
# ### end Alembic commands ###

View file

@ -0,0 +1,45 @@
"""add_review_targets
Revision ID: 6659cb1e0ca5
Revises: 83e6fd46fa2b
Create Date: 2025-12-03 13:05:43.037872
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '6659cb1e0ca5'
down_revision: Union[str, Sequence[str], None] = '83e6fd46fa2b'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('review', schema=None) as batch_op:
batch_op.add_column(sa.Column('performance_id', sa.Integer(), nullable=True))
batch_op.add_column(sa.Column('tour_id', sa.Integer(), nullable=True))
batch_op.add_column(sa.Column('year', sa.Integer(), nullable=True))
batch_op.create_foreign_key('fk_review_tour_id', 'tour', ['tour_id'], ['id'])
batch_op.create_foreign_key('fk_review_performance_id', 'performance', ['performance_id'], ['id'])
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('review', schema=None) as batch_op:
batch_op.add_column(sa.Column('created_at', sa.DATETIME(), nullable=False))
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.drop_column('year')
batch_op.drop_column('tour_id')
batch_op.drop_column('performance_id')
# ### end Alembic commands ###

View file

@ -0,0 +1,59 @@
"""Add moderation system
Revision ID: 83e6fd46fa2b
Revises: bc32a0b7efbb
Create Date: 2025-12-02 03:28:35.663970
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import sqlmodel
# revision identifiers, used by Alembic.
revision: str = '83e6fd46fa2b'
down_revision: Union[str, Sequence[str], None] = 'bc32a0b7efbb'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('report',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('target_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('target_id', sa.Integer(), nullable=False),
sa.Column('reason', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('status', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('report', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_report_status'), ['status'], unique=False)
batch_op.create_index(batch_op.f('ix_report_target_id'), ['target_id'], unique=False)
batch_op.create_index(batch_op.f('ix_report_target_type'), ['target_type'], unique=False)
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.add_column(sa.Column('role', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_column('role')
with op.batch_alter_table('report', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_report_target_type'))
batch_op.drop_index(batch_op.f('ix_report_target_id'))
batch_op.drop_index(batch_op.f('ix_report_status'))
op.drop_table('report')
# ### end Alembic commands ###

View file

@ -0,0 +1,122 @@
"""Add core enhancements
Revision ID: a0b7abe57112
Revises: c26cc8212061
Create Date: 2025-12-02 01:33:56.476865
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import sqlmodel
# revision identifiers, used by Alembic.
revision: str = 'a0b7abe57112'
down_revision: Union[str, Sequence[str], None] = 'c26cc8212061'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('artist',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('instrument', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_artist_name'), 'artist', ['name'], unique=False)
op.create_table('tag',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_tag_name'), 'tag', ['name'], unique=True)
op.create_index(op.f('ix_tag_slug'), 'tag', ['slug'], unique=True)
op.create_table('tour',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('start_date', sa.DateTime(), nullable=True),
sa.Column('end_date', sa.DateTime(), nullable=True),
sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_tour_name'), 'tour', ['name'], unique=False)
op.create_table('entitytag',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('tag_id', sa.Integer(), nullable=False),
sa.Column('entity_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('entity_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['tag_id'], ['tag.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_entitytag_entity_id'), 'entitytag', ['entity_id'], unique=False)
op.create_index(op.f('ix_entitytag_entity_type'), 'entitytag', ['entity_type'], unique=False)
op.create_table('attendance',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('show_id', sa.Integer(), nullable=False),
sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['show_id'], ['show.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('showartist',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('show_id', sa.Integer(), nullable=False),
sa.Column('artist_id', sa.Integer(), nullable=False),
sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.ForeignKeyConstraint(['artist_id'], ['artist.id'], ),
sa.ForeignKeyConstraint(['show_id'], ['show.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('performanceartist',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('performance_id', sa.Integer(), nullable=False),
sa.Column('artist_id', sa.Integer(), nullable=False),
sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.ForeignKeyConstraint(['artist_id'], ['artist.id'], ),
sa.ForeignKeyConstraint(['performance_id'], ['performance.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('show', schema=None) as batch_op:
batch_op.add_column(sa.Column('tour_id', sa.Integer(), nullable=True))
batch_op.add_column(sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.create_foreign_key('fk_show_tour', 'tour', ['tour_id'], ['id'])
with op.batch_alter_table('song', schema=None) as batch_op:
batch_op.add_column(sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
with op.batch_alter_table('venue', schema=None) as batch_op:
batch_op.add_column(sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('venue', 'notes')
op.drop_column('song', 'notes')
op.drop_constraint(None, 'show', type_='foreignkey')
op.drop_column('show', 'notes')
op.drop_column('show', 'tour_id')
op.drop_table('performanceartist')
op.drop_table('showartist')
op.drop_table('attendance')
op.drop_index(op.f('ix_entitytag_entity_type'), table_name='entitytag')
op.drop_index(op.f('ix_entitytag_entity_id'), table_name='entitytag')
op.drop_table('entitytag')
op.drop_index(op.f('ix_tour_name'), table_name='tour')
op.drop_table('tour')
op.drop_index(op.f('ix_tag_slug'), table_name='tag')
op.drop_index(op.f('ix_tag_name'), table_name='tag')
op.drop_table('tag')
op.drop_index(op.f('ix_artist_name'), table_name='artist')
op.drop_table('artist')
# ### end Alembic commands ###

View file

@ -0,0 +1,57 @@
"""add_notifications
Revision ID: a526deda28e0
Revises: 1305863562e7
Create Date: 2025-12-03 15:40:20.810781
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import sqlmodel
# revision identifiers, used by Alembic.
revision: str = 'a526deda28e0'
down_revision: Union[str, Sequence[str], None] = '1305863562e7'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('notification',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('type', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('title', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('message', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('link', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('is_read', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('notification', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_notification_user_id'), ['user_id'], unique=False)
with op.batch_alter_table('review', schema=None) as batch_op:
# batch_op.drop_column('created_at')
pass
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('review', schema=None) as batch_op:
batch_op.add_column(sa.Column('created_at', sa.DATETIME(), nullable=False))
with op.batch_alter_table('notification', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_notification_user_id'))
op.drop_table('notification')
# ### end Alembic commands ###

View file

@ -0,0 +1,53 @@
"""add_review_created_at_and_report_details
Revision ID: b16ef2228130
Revises: a526deda28e0
Create Date: 2025-12-03 16:15:16.644205
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import sqlmodel
# revision identifiers, used by Alembic.
revision: str = 'b16ef2228130'
down_revision: Union[str, Sequence[str], None] = 'a526deda28e0'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('report', schema=None) as batch_op:
batch_op.add_column(sa.Column('entity_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
batch_op.add_column(sa.Column('entity_id', sa.Integer(), nullable=False))
batch_op.add_column(sa.Column('details', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
batch_op.drop_index(batch_op.f('ix_report_target_id'))
batch_op.drop_index(batch_op.f('ix_report_target_type'))
batch_op.create_index(batch_op.f('ix_report_entity_id'), ['entity_id'], unique=False)
batch_op.create_index(batch_op.f('ix_report_entity_type'), ['entity_type'], unique=False)
batch_op.drop_column('target_type')
batch_op.drop_column('target_id')
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('report', schema=None) as batch_op:
batch_op.add_column(sa.Column('target_id', sa.INTEGER(), nullable=False))
batch_op.add_column(sa.Column('target_type', sa.VARCHAR(), nullable=False))
batch_op.drop_index(batch_op.f('ix_report_entity_type'))
batch_op.drop_index(batch_op.f('ix_report_entity_id'))
batch_op.create_index(batch_op.f('ix_report_target_type'), ['target_type'], unique=False)
batch_op.create_index(batch_op.f('ix_report_target_id'), ['target_id'], unique=False)
batch_op.drop_column('details')
batch_op.drop_column('entity_id')
batch_op.drop_column('entity_type')
# ### end Alembic commands ###

View file

@ -0,0 +1,52 @@
"""Add performance nicknames
Revision ID: bc32a0b7efbb
Revises: 341b95b6e098
Create Date: 2025-12-02 03:16:05.516007
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import sqlmodel
# revision identifiers, used by Alembic.
revision: str = 'bc32a0b7efbb'
down_revision: Union[str, Sequence[str], None] = '341b95b6e098'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('performancenickname',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('performance_id', sa.Integer(), nullable=False),
sa.Column('nickname', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('status', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('suggested_by', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['performance_id'], ['performance.id'], ),
sa.ForeignKeyConstraint(['suggested_by'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('performancenickname', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_performancenickname_nickname'), ['nickname'], unique=False)
batch_op.create_index(batch_op.f('ix_performancenickname_status'), ['status'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('performancenickname', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_performancenickname_status'))
batch_op.drop_index(batch_op.f('ix_performancenickname_nickname'))
op.drop_table('performancenickname')
# ### end Alembic commands ###

View file

@ -0,0 +1,59 @@
"""Add social models
Revision ID: c26cc8212061
Revises: f5ca1b7c50b1
Create Date: 2025-12-02 01:14:05.048299
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import sqlmodel
# revision identifiers, used by Alembic.
revision: str = 'c26cc8212061'
down_revision: Union[str, Sequence[str], None] = 'f5ca1b7c50b1'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('comment',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('content', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('show_id', sa.Integer(), nullable=True),
sa.Column('venue_id', sa.Integer(), nullable=True),
sa.Column('song_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['show_id'], ['show.id'], ),
sa.ForeignKeyConstraint(['song_id'], ['song.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.ForeignKeyConstraint(['venue_id'], ['venue.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('rating',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('score', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('show_id', sa.Integer(), nullable=True),
sa.Column('song_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['show_id'], ['show.id'], ),
sa.ForeignKeyConstraint(['song_id'], ['song.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('rating')
op.drop_table('comment')
# ### end Alembic commands ###

View file

@ -0,0 +1,39 @@
"""Add user bio and avatar
Revision ID: e50a60c5d343
Revises: b16ef2228130
Create Date: 2025-12-20 06:44:30.761707
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import sqlmodel
# revision identifiers, used by Alembic.
revision: str = 'e50a60c5d343'
down_revision: Union[str, Sequence[str], None] = 'b16ef2228130'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.add_column(sa.Column('bio', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
batch_op.add_column(sa.Column('avatar', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_column('avatar')
batch_op.drop_column('bio')
# ### end Alembic commands ###

View file

@ -0,0 +1,113 @@
"""Initial migration
Revision ID: f5ca1b7c50b1
Revises:
Create Date: 2025-12-02 00:47:26.543594
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import sqlmodel
# revision identifiers, used by Alembic.
revision: str = 'f5ca1b7c50b1'
down_revision: Union[str, Sequence[str], None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('email', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('hashed_password', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('is_superuser', sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=True)
op.create_table('venue',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('city', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('state', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('country', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('capacity', sa.Integer(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_venue_name'), 'venue', ['name'], unique=False)
op.create_table('vertical',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_vertical_name'), 'vertical', ['name'], unique=False)
op.create_index(op.f('ix_vertical_slug'), 'vertical', ['slug'], unique=True)
op.create_table('profile',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('username', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('display_name', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_profile_username'), 'profile', ['username'], unique=False)
op.create_table('show',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('date', sa.DateTime(), nullable=False),
sa.Column('vertical_id', sa.Integer(), nullable=False),
sa.Column('venue_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['venue_id'], ['venue.id'], ),
sa.ForeignKeyConstraint(['vertical_id'], ['vertical.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_show_date'), 'show', ['date'], unique=False)
op.create_table('song',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('original_artist', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('vertical_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['vertical_id'], ['vertical.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_song_title'), 'song', ['title'], unique=False)
op.create_table('performance',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('show_id', sa.Integer(), nullable=False),
sa.Column('song_id', sa.Integer(), nullable=False),
sa.Column('position', sa.Integer(), nullable=False),
sa.Column('set_name', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('segue', sa.Boolean(), nullable=False),
sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.ForeignKeyConstraint(['show_id'], ['show.id'], ),
sa.ForeignKeyConstraint(['song_id'], ['song.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('performance')
op.drop_index(op.f('ix_song_title'), table_name='song')
op.drop_table('song')
op.drop_index(op.f('ix_show_date'), table_name='show')
op.drop_table('show')
op.drop_index(op.f('ix_profile_username'), table_name='profile')
op.drop_table('profile')
op.drop_index(op.f('ix_vertical_slug'), table_name='vertical')
op.drop_index(op.f('ix_vertical_name'), table_name='vertical')
op.drop_table('vertical')
op.drop_index(op.f('ix_venue_name'), table_name='venue')
op.drop_table('venue')
op.drop_index(op.f('ix_user_email'), table_name='user')
op.drop_table('user')
# ### end Alembic commands ###

61
backend/auth.py Normal file
View file

@ -0,0 +1,61 @@
from datetime import datetime, timedelta
from typing import Optional
from jose import JWTError, jwt
from passlib.context import CryptContext
from fastapi import Depends, HTTPException, status
from fastapi.security import OAuth2PasswordBearer
from sqlmodel import Session, select
from database import get_session
from models import User
import os
# Configuration
SECRET_KEY = os.getenv("SECRET_KEY", "supersecretkey") # Change this in production!
ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES = 10080 # 7 days
pwd_context = CryptContext(schemes=["argon2"], deprecated="auto")
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="auth/token")
def verify_password(plain_password, hashed_password):
return pwd_context.verify(plain_password, hashed_password)
def get_password_hash(password):
return pwd_context.hash(password)
def create_access_token(data: dict, expires_delta: Optional[timedelta] = None):
to_encode = data.copy()
if expires_delta:
expire = datetime.utcnow() + expires_delta
else:
expire = datetime.utcnow() + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
async def get_current_user(token: str = Depends(oauth2_scheme), session: Session = Depends(get_session)):
credentials_exception = HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Could not validate credentials",
headers={"WWW-Authenticate": "Bearer"},
)
try:
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
email: str = payload.get("sub")
if email is None:
raise credentials_exception
except JWTError:
raise credentials_exception
user = session.exec(select(User).where(User.email == email)).first()
if user is None:
raise credentials_exception
return user
async def get_current_superuser(current_user: User = Depends(get_current_user)):
if not current_user.is_superuser:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="The user doesn't have enough privileges"
)
return current_user

View file

@ -0,0 +1,52 @@
import sys
from database import get_session
from models import Performance, Show, Song
from sqlmodel import select, col
def check_videos():
video_ids = [
"PvdtMSifDqU", "7vujKUzGtcg", "nCnYJaIxBzo", "Yeno3bJs4Ws",
"zQI6-LloYwI", "F66jL0skeT4", "JdWnhOIWh-I", "wtTiAwA5Ha4",
"USQNba0t-4A", "vCdiwBSGtpk", "1BbtYhhCMWs", "yCPFRcIByqI",
"vE1F77CZbXQ", "rek58BRByTw", "rhP0-gKD_d8", "jMhayG6WCIw",
"osPxSR5GmX8", "cyLYgo9r3xM", "nZE_w8hDukI", "W93zvUz4vyI"
]
session = next(get_session())
found_count = 0
missing = []
print(f"Checking {len(video_ids)} videos...")
for vid in video_ids:
# Check Shows
s = session.exec(select(Show).where(Show.youtube_link.contains(vid))).first()
if s:
print(f"[FOUND] {vid}: Show {s.date}")
found_count += 1
continue
# Check Performances
p = session.exec(select(Performance).where(Performance.youtube_link.contains(vid))).first()
if p:
# Get song title
song = session.get(Song, p.song_id)
print(f"[FOUND] {vid}: Performance {song.title} (Show {p.show_id})")
found_count += 1
continue
# Check Songs (Direct link)
song = session.exec(select(Song).where(Song.youtube_link.contains(vid))).first()
if song:
print(f"[FOUND] {vid}: Song Master {song.title}")
found_count += 1
continue
print(f"[MISSING] {vid}")
missing.append(vid)
print(f"\nSummary: Found {found_count}/{len(video_ids)}")
print(f"Missing IDs: {missing}")
if __name__ == "__main__":
check_videos()

View file

@ -0,0 +1,230 @@
#!/usr/bin/env python3
"""
Comprehensive Elgoose Data Importer
Imports all shows, setlists, songs, venues, and tours from elgoose.net API
"""
import requests
from datetime import datetime, date
from sqlmodel import Session, select
from database import engine
from models import Show, Song, Performance, Venue, Tour, Vertical
BASE_URL = "https://elgoose.net/api/v2"
GOOSE_ARTIST_ID = 1 # Main Goose artist
def get_api_data(endpoint):
"""Fetch data from elgoose API"""
url = f"{BASE_URL}/{endpoint}"
print(f"Fetching: {url}")
response = requests.get(url, timeout=30)
response.raise_for_status()
return response.json()
def import_shows_and_setlists():
"""Import all shows and their setlists"""
print("="*60)
print("COMPREHENSIVE ELGOOSE IMPORT")
print("="*60)
with Session(engine) as session:
# Ensure Goose vertical exists (id=1)
goose_vertical = session.get(Vertical, 1)
if not goose_vertical:
print("Creating Goose vertical...")
goose_vertical = Vertical(
name="Goose",
slug="goose",
description="The band Goose."
)
session.add(goose_vertical)
session.commit()
session.refresh(goose_vertical)
print(f"Created vertical with id: {goose_vertical.id}")
else:
print(f"Using existing Goose vertical (id={goose_vertical.id})")
# Get all shows from API
shows_data = get_api_data("shows.json")
if shows_data.get("error"):
print(f"API Error: {shows_data.get('error_message')}")
return
api_shows = shows_data.get("data", [])
print(f"Found {len(api_shows)} shows in elgoose API")
# Filter to Goose shows only (artist_id=1)
goose_shows = [s for s in api_shows if s.get("artist_id") == GOOSE_ARTIST_ID]
print(f"Found {len(goose_shows)} Goose shows")
# Get today's date for filtering
today = date.today()
past_shows = []
future_shows = []
for show in goose_shows:
show_date_str = show.get("showdate", "")
if show_date_str:
show_date = datetime.strptime(show_date_str, "%Y-%m-%d").date()
if show_date <= today:
past_shows.append(show)
else:
future_shows.append(show)
print(f"Past shows: {len(past_shows)}")
print(f"Future/upcoming shows: {len(future_shows)}")
with Session(engine) as session:
# Build lookup maps
existing_shows = {s.date: s for s in session.exec(select(Show)).all()}
existing_songs = {s.title.lower(): s for s in session.exec(select(Song)).all()}
existing_venues = {v.name.lower(): v for v in session.exec(select(Venue)).all()}
existing_tours = {t.name.lower(): t for t in session.exec(select(Tour)).all()}
print(f"Existing shows in DB: {len(existing_shows)}")
print(f"Existing songs in DB: {len(existing_songs)}")
print(f"Existing venues in DB: {len(existing_venues)}")
print(f"Existing tours in DB: {len(existing_tours)}")
shows_added = 0
shows_updated = 0
performances_added = 0
venues_added = 0
tours_added = 0
songs_added = 0
# Process ALL shows (past and future)
all_shows_to_process = past_shows + future_shows
print(f"Processing {len(all_shows_to_process)} shows...")
for api_show in all_shows_to_process:
show_date_str = api_show.get("showdate")
show_date = datetime.strptime(show_date_str, "%Y-%m-%d")
api_show_id = api_show.get("show_id")
venue_name = api_show.get("venuename", "").replace("&amp;", "&")
tour_name = api_show.get("tourname", "")
location = api_show.get("location", "")
city = api_show.get("city", "")
state = api_show.get("state", "")
# Find or create venue
venue = None
if venue_name:
venue = existing_venues.get(venue_name.lower())
if not venue:
venue = Venue(
name=venue_name,
city=city,
state=state,
country=api_show.get("country", "USA"), # Get country from API
vertical_id=1 # Goose vertical
)
session.add(venue)
session.flush()
existing_venues[venue_name.lower()] = venue
venues_added += 1
# Find or create tour
tour = None
if tour_name and tour_name != "Not Part of a Tour":
tour = existing_tours.get(tour_name.lower())
if not tour:
tour = Tour(
name=tour_name,
vertical_id=1
)
session.add(tour)
session.flush()
existing_tours[tour_name.lower()] = tour
tours_added += 1
# Check if show exists
existing_show = existing_shows.get(show_date)
if existing_show:
# Update venue/tour if missing
if venue and not existing_show.venue_id:
existing_show.venue_id = venue.id
shows_updated += 1
if tour and not existing_show.tour_id:
existing_show.tour_id = tour.id
shows_updated += 1
show = existing_show
else:
# Create new show
show = Show(
date=show_date,
venue_id=venue.id if venue else None,
tour_id=tour.id if tour else None,
vertical_id=1
)
session.add(show)
session.flush()
existing_shows[show_date] = show
shows_added += 1
# Fetch setlist for this show by date
try:
setlist_data = get_api_data(f"setlists/showdate/{show_date_str}.json")
if not setlist_data.get("error"):
setlist = setlist_data.get("data", [])
# Check existing performances
existing_perfs = session.exec(
select(Performance).where(Performance.show_id == show.id)
).all()
if not existing_perfs and setlist:
for idx, perf_data in enumerate(setlist):
song_title = perf_data.get("songname", "").strip()
set_name = perf_data.get("set", "")
position = perf_data.get("position", idx + 1)
segue = perf_data.get("segue", "") == ">"
notes = perf_data.get("footnote", "")
if not song_title:
continue
# Find or create song
song = existing_songs.get(song_title.lower())
if not song:
song = Song(
title=song_title,
vertical_id=1
)
session.add(song)
session.flush()
existing_songs[song_title.lower()] = song
songs_added += 1
# Create performance
perf = Performance(
show_id=show.id,
song_id=song.id,
position=position,
set_name=set_name,
segue=segue,
notes=notes
)
session.add(perf)
performances_added += 1
except Exception as e:
print(f" Error fetching setlist for show {api_show_id}: {e}")
# Commit periodically
if (shows_added + shows_updated) % 50 == 0:
session.commit()
print(f" Progress: {shows_added} added, {shows_updated} updated, {performances_added} performances")
session.commit()
print("\n" + "="*60)
print("IMPORT COMPLETE")
print("="*60)
print(f"Shows added: {shows_added}")
print(f"Shows updated: {shows_updated}")
print(f"Venues added: {venues_added}")
print(f"Tours added: {tours_added}")
print(f"Songs added: {songs_added}")
print(f"Performances added: {performances_added}")
if __name__ == "__main__":
import_shows_and_setlists()

17
backend/database.py Normal file
View file

@ -0,0 +1,17 @@
from sqlmodel import SQLModel, create_engine, Session
import os
# Use SQLite for local dev by default, or override with DATABASE_URL env var
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./database.db")
# check_same_thread is needed for SQLite
connect_args = {"check_same_thread": False} if "sqlite" in DATABASE_URL else {}
engine = create_engine(DATABASE_URL, echo=True, connect_args=connect_args)
def create_db_and_tables():
SQLModel.metadata.create_all(engine)
def get_session():
with Session(engine) as session:
yield session

15
backend/dependencies.py Normal file
View file

@ -0,0 +1,15 @@
from fastapi import Depends, HTTPException, status
from models import User
from auth import get_current_user
class RoleChecker:
def __init__(self, allowed_roles: list[str]):
self.allowed_roles = allowed_roles
def __call__(self, user: User = Depends(get_current_user)):
if user.role not in self.allowed_roles:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Operation not permitted"
)
return user

View file

@ -0,0 +1,213 @@
"""
Show Audio Link Discovery Script
This script discovers show-specific Bandcamp and Nugs.net URLs by:
1. For Bandcamp: Testing URL patterns based on date and venue
2. For Nugs: Scraping the Nugs catalog page to extract show URLs
Run from backend container: python discover_audio_links.py
"""
import re
import requests
from datetime import datetime
from sqlmodel import Session, select
from database import engine
from models import Show, Venue
from slugify import generate_slug
# Session headers to mimic browser
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36'
}
def slugify_for_bandcamp(text: str) -> str:
"""Convert text to Bandcamp-friendly slug (lowercase, hyphens, no special chars)"""
text = text.lower()
text = re.sub(r'[^a-z0-9\s-]', '', text)
text = re.sub(r'[\s_]+', '-', text)
text = re.sub(r'-+', '-', text)
return text.strip('-')
def check_url_exists(url: str) -> bool:
"""Check if a URL returns 200 OK"""
try:
resp = requests.head(url, headers=HEADERS, timeout=5, allow_redirects=True)
return resp.status_code == 200
except:
return False
def discover_bandcamp_url(show: Show, venue: Venue) -> str | None:
"""
Try to find Bandcamp album URL for a show.
Pattern: https://goosetheband.bandcamp.com/album/YYYY-MM-DD-venue-city-state
"""
if not venue:
return None
date_str = show.date.strftime("%Y-%m-%d")
# Build venue slug variations
venue_slugs = []
# Try: venue-city-state
if venue.city and venue.state:
venue_slugs.append(f"{slugify_for_bandcamp(venue.name)}-{slugify_for_bandcamp(venue.city)}-{venue.state.lower()}")
# Try: city-state (some albums just use location)
if venue.city and venue.state:
venue_slugs.append(f"{slugify_for_bandcamp(venue.city)}-{venue.state.lower()}")
# Try: venue-city
if venue.city:
venue_slugs.append(f"{slugify_for_bandcamp(venue.name)}-{slugify_for_bandcamp(venue.city)}")
for venue_slug in venue_slugs:
url = f"https://goosetheband.bandcamp.com/album/{date_str}-{venue_slug}"
if check_url_exists(url):
return url
return None
def scrape_nugs_catalog() -> dict:
"""
Scrape the Nugs Goose catalog page to build a mapping of date -> URL.
Returns dict like {"2024-12-31": "https://www.nugs.net/..."}
"""
catalog_url = "https://www.nugs.net/goose-concerts-live-downloads-in-mp3-flac-or-online-music-streaming/"
nugs_shows = {}
try:
resp = requests.get(catalog_url, headers=HEADERS, timeout=30)
if resp.status_code != 200:
print(f"Failed to fetch Nugs catalog: {resp.status_code}")
return {}
html = resp.text
# Extract URLs and dates using regex
# URL pattern: https://www.nugs.net/live-download-of-goose-...-MM-DD-YYYY-mp3-flac-or-online-music-streaming/ID.html
url_pattern = r'(https://www\.nugs\.net/live-download-of-goose-[^"]+\.html)'
urls = re.findall(url_pattern, html)
# Date pattern in URL: MM-DD-YYYY (before mp3-flac...)
for url in set(urls): # deduplicate
# Try to extract date from URL
date_match = re.search(r'-(\d{1,2})-(\d{1,2})-(\d{4})-mp3-flac', url)
if date_match:
month, day, year = date_match.groups()
date_str = f"{year}-{int(month):02d}-{int(day):02d}"
nugs_shows[date_str] = url
print(f" Scraped {len(nugs_shows)} Nugs show URLs from catalog")
except Exception as e:
print(f"Error scraping Nugs: {e}")
return nugs_shows
# Global cache for Nugs catalog
_nugs_catalog = None
def get_nugs_catalog():
"""Get or build Nugs catalog cache"""
global _nugs_catalog
if _nugs_catalog is None:
print("Building Nugs catalog from website...")
_nugs_catalog = scrape_nugs_catalog()
return _nugs_catalog
def discover_nugs_url(show: Show) -> str | None:
"""
Look up Nugs URL from catalog by date.
"""
date_str = show.date.strftime("%Y-%m-%d")
catalog = get_nugs_catalog()
return catalog.get(date_str)
def main(dry_run: bool = True, limit: int = None):
"""
Main discovery function.
Args:
dry_run: If True, print changes but don't write to DB
limit: Max number of shows to process (for testing)
"""
print("=" * 60)
print("Show Audio Link Discovery")
print("=" * 60)
with Session(engine) as session:
# Get all shows with venue info
query = select(Show).order_by(Show.date.desc())
if limit:
query = query.limit(limit)
shows = session.exec(query).all()
print(f"Found {len(shows)} shows to process")
# Stats
bandcamp_found = 0
nugs_found = 0
already_have_bandcamp = 0
already_have_nugs = 0
for show in shows:
venue = session.get(Venue, show.venue_id) if show.venue_id else None
date_str = show.date.strftime("%Y-%m-%d")
# Skip if already has specific links (not the generic band-level ones)
generic_bandcamp = "goosetheband.bandcamp.com" in (show.bandcamp_link or "") and "/album/" not in (show.bandcamp_link or "")
generic_nugs = "utm_source=goose" in (show.nugs_link or "")
# Bandcamp discovery
if not show.bandcamp_link or generic_bandcamp:
bc_url = discover_bandcamp_url(show, venue)
if bc_url:
print(f"✓ Bandcamp: {date_str} -> {bc_url}")
bandcamp_found += 1
if not dry_run:
show.bandcamp_link = bc_url
session.add(show)
else:
already_have_bandcamp += 1
# Nugs discovery
if not show.nugs_link or generic_nugs:
nugs_url = discover_nugs_url(show)
if nugs_url:
print(f"✓ Nugs: {date_str} -> {nugs_url}")
nugs_found += 1
if not dry_run:
show.nugs_link = nugs_url
session.add(show)
else:
already_have_nugs += 1
if not dry_run:
session.commit()
print("\n" + "=" * 60)
print("Summary")
print("=" * 60)
print(f"Shows processed: {len(shows)}")
print(f"Bandcamp links found: {bandcamp_found}")
print(f"Nugs links found: {nugs_found}")
print(f"Already had Bandcamp: {already_have_bandcamp}")
print(f"Already had Nugs: {already_have_nugs}")
if dry_run:
print("\n[DRY RUN - No changes saved. Run with dry_run=False to save]")
if __name__ == "__main__":
import sys
dry_run = True
limit = 20 # Test with 20 shows first
if len(sys.argv) > 1:
if "--save" in sys.argv:
dry_run = False
if "--all" in sys.argv:
limit = None
main(dry_run=dry_run, limit=limit)

146
backend/email_service.py Normal file
View file

@ -0,0 +1,146 @@
"""
Email Service - AWS SES v2 integration using stored templates.
Uses SES stored templates for consistent, branded transactional emails:
- ELMEG_EMAIL_VERIFICATION
- ELMEG_PASSWORD_RESET
- ELMEG_SECURITY_ALERT
"""
import os
import json
import secrets
from datetime import datetime, timedelta
from typing import Optional
import boto3
from botocore.exceptions import ClientError
# Configuration
AWS_REGION = os.getenv("AWS_SES_REGION", "us-east-1")
EMAIL_FROM = os.getenv("EMAIL_FROM", "noreply@elmeg.xyz")
FRONTEND_URL = os.getenv("FRONTEND_URL", "https://elmeg.xyz")
SUPPORT_EMAIL = os.getenv("SUPPORT_EMAIL", "support@elmeg.xyz")
APP_NAME = "Elmeg"
# SES Template Names
TEMPLATE_VERIFICATION = "ELMEG_EMAIL_VERIFICATION"
TEMPLATE_PASSWORD_RESET = "ELMEG_PASSWORD_RESET"
TEMPLATE_SECURITY_ALERT = "ELMEG_SECURITY_ALERT"
def get_ses_client():
"""Get boto3 SES v2 client"""
return boto3.client('sesv2', region_name=AWS_REGION)
def is_email_configured() -> bool:
"""Check if email is properly configured"""
return bool(os.getenv("AWS_ACCESS_KEY_ID") and os.getenv("AWS_SECRET_ACCESS_KEY"))
def send_templated_email(
to: str,
template_name: str,
template_data: dict
) -> dict:
"""
Send email using SES stored template.
Returns:
dict with 'success', 'message_id' (on success), 'error' (on failure)
"""
# Dev mode - log instead of sending
if not is_email_configured():
print(f"[EMAIL DEV MODE] To: {to}, Template: {template_name}")
print(f"[EMAIL DEV MODE] Data: {json.dumps(template_data, indent=2)}")
return {"success": True, "message_id": "dev-mode", "dev_mode": True}
try:
client = get_ses_client()
response = client.send_email(
FromEmailAddress=EMAIL_FROM,
Destination={"ToAddresses": [to]},
Content={
"Template": {
"TemplateName": template_name,
"TemplateData": json.dumps(template_data)
}
}
)
message_id = response.get("MessageId", "unknown")
print(f"[Email] Sent {template_name} to {to}, MessageId: {message_id}")
return {"success": True, "message_id": message_id}
except ClientError as e:
error_msg = e.response.get('Error', {}).get('Message', str(e))
print(f"[Email] Failed to send {template_name} to {to}: {error_msg}")
return {"success": False, "error": error_msg}
# =============================================================================
# Email Functions
# =============================================================================
async def send_verification_email(email: str, token: str, user_name: Optional[str] = None) -> bool:
"""Send email verification using SES template"""
verification_link = f"{FRONTEND_URL}/verify-email?token={token}"
template_data = {
"user_name": user_name or email.split("@")[0],
"verification_link": verification_link,
"app_name": APP_NAME,
"support_email": SUPPORT_EMAIL
}
result = send_templated_email(email, TEMPLATE_VERIFICATION, template_data)
return result["success"]
async def send_password_reset_email(email: str, token: str, user_name: Optional[str] = None) -> bool:
"""Send password reset email using SES template"""
reset_link = f"{FRONTEND_URL}/reset-password?token={token}"
template_data = {
"user_name": user_name or email.split("@")[0],
"reset_link": reset_link,
"app_name": APP_NAME,
"support_email": SUPPORT_EMAIL
}
result = send_templated_email(email, TEMPLATE_PASSWORD_RESET, template_data)
return result["success"]
async def send_security_alert_email(
email: str,
security_event_description: str,
user_name: Optional[str] = None
) -> bool:
"""Send security alert email using SES template"""
template_data = {
"user_name": user_name or email.split("@")[0],
"security_event_description": security_event_description,
"app_name": APP_NAME,
"support_email": SUPPORT_EMAIL
}
result = send_templated_email(email, TEMPLATE_SECURITY_ALERT, template_data)
return result["success"]
# =============================================================================
# Token Generation & Expiry Helpers
# =============================================================================
def generate_token() -> str:
"""Generate a secure random token"""
return secrets.token_urlsafe(32)
def get_verification_expiry() -> datetime:
"""24 hour expiry for email verification"""
return datetime.utcnow() + timedelta(hours=24)
def get_reset_expiry() -> datetime:
"""1 hour expiry for password reset"""
return datetime.utcnow() + timedelta(hours=1)

View file

@ -0,0 +1,128 @@
"""
Fast Setlist Importer - Skips validation checks for speed
Run after main import if it times out
"""
import requests
from datetime import datetime
from sqlmodel import Session, select
from database import engine
from models import Show, Song, Performance
BASE_URL = "https://elgoose.net/api/v2"
def fetch_json(endpoint, params=None):
url = f"{BASE_URL}/{endpoint}.json"
try:
response = requests.get(url, params=params, timeout=30)
response.raise_for_status()
data = response.json()
if data.get('error') == 1:
return None
return data.get('data', [])
except Exception as e:
print(f"Error: {e}")
return None
def main():
print("FAST SETLIST IMPORTER")
print("=" * 40)
with Session(engine) as session:
# Build lookup maps
print("Building show map...")
shows = session.exec(select(Show)).all()
# Map API show_id to our show_id
# We need the API show_id. The 'notes' field might have showtitle but not API id.
# Problem: We don't store API show_id in our DB!
# We need to re-fetch shows and match by date+venue_id
show_map = {} # api_show_id -> our_show_id
song_map = {} # api_song_id -> our_song_id
# Fetch shows from API to build map
print("Fetching API shows to build map...")
page = 1
while True:
data = fetch_json("shows", {"artist": 1, "page": page})
if not data:
break
for s in data:
api_show_id = s['show_id']
show_date = datetime.strptime(s['showdate'], '%Y-%m-%d')
# Find matching show in our DB
our_show = session.exec(
select(Show).where(Show.date == show_date)
).first()
if our_show:
show_map[api_show_id] = our_show.id
page += 1
if page > 50:
break
print(f"Mapped {len(show_map)} shows")
# Build song map
print("Building song map...")
songs_data = fetch_json("songs")
if songs_data:
for s in songs_data:
api_song_id = s['id']
our_song = session.exec(
select(Song).where(Song.title == s['name'])
).first()
if our_song:
song_map[api_song_id] = our_song.id
print(f"Mapped {len(song_map)} songs")
# Get existing performances to skip
print("Loading existing performances...")
existing = set()
perfs = session.exec(select(Performance.show_id, Performance.song_id, Performance.position)).all()
for p in perfs:
existing.add((p[0], p[1], p[2]))
print(f"Found {len(existing)} existing performances")
# Import setlists page by page
print("\\nImporting setlists...")
page = 1
total_added = 0
while True:
data = fetch_json("setlists", {"page": page})
if not data:
print(f"No data on page {page}, done.")
break
added_this_page = 0
for perf_data in data:
our_show_id = show_map.get(perf_data.get('show_id'))
our_song_id = song_map.get(perf_data.get('song_id'))
position = perf_data.get('position', 0)
if not our_show_id or not our_song_id:
continue
key = (our_show_id, our_song_id, position)
if key in existing:
continue
perf = Performance(
show_id=our_show_id,
song_id=our_song_id,
position=position,
set_name=perf_data.get('set'),
segue=bool(perf_data.get('segue', 0)),
notes=perf_data.get('notes')
)
session.add(perf)
existing.add(key)
added_this_page += 1
total_added += 1
session.commit()
print(f"Page {page}: +{added_this_page} ({total_added} total)")
page += 1
print(f"\\n✓ Added {total_added} performances")
if __name__ == "__main__":
main()

207
backend/fetch_youtube.py Normal file
View file

@ -0,0 +1,207 @@
"""
Fetch all videos from Goose YouTube channel using YouTube Data API v3
"""
import requests
import json
import re
from datetime import datetime
API_KEY = "AIzaSyCxDpv6HM-sPD8vPJIBffwa2-skOpEJkOU"
CHANNEL_HANDLE = "@GooseTheBand"
def get_channel_id(handle: str) -> str:
"""Get channel ID from handle."""
url = "https://www.googleapis.com/youtube/v3/search"
params = {
"key": API_KEY,
"q": handle,
"type": "channel",
"part": "snippet",
"maxResults": 1
}
resp = requests.get(url, params=params)
data = resp.json()
if "items" in data and len(data["items"]) > 0:
return data["items"][0]["snippet"]["channelId"]
return None
def get_uploads_playlist_id(channel_id: str) -> str:
"""Get the uploads playlist ID for a channel."""
url = "https://www.googleapis.com/youtube/v3/channels"
params = {
"key": API_KEY,
"id": channel_id,
"part": "contentDetails"
}
resp = requests.get(url, params=params)
data = resp.json()
if "items" in data and len(data["items"]) > 0:
return data["items"][0]["contentDetails"]["relatedPlaylists"]["uploads"]
return None
def get_all_videos(playlist_id: str) -> list:
"""Fetch all videos from a playlist (handles pagination)."""
videos = []
url = "https://www.googleapis.com/youtube/v3/playlistItems"
next_page_token = None
while True:
params = {
"key": API_KEY,
"playlistId": playlist_id,
"part": "snippet,contentDetails",
"maxResults": 50
}
if next_page_token:
params["pageToken"] = next_page_token
resp = requests.get(url, params=params)
data = resp.json()
if "error" in data:
print(f"API Error: {data['error']}")
break
for item in data.get("items", []):
snippet = item["snippet"]
video = {
"videoId": snippet["resourceId"]["videoId"],
"title": snippet["title"],
"description": snippet.get("description", ""),
"publishedAt": snippet["publishedAt"],
"thumbnails": snippet.get("thumbnails", {})
}
videos.append(video)
next_page_token = data.get("nextPageToken")
print(f"Fetched {len(videos)} videos so far...")
if not next_page_token:
break
return videos
def parse_video_metadata(videos: list) -> list:
"""Parse video titles to extract show date and type."""
parsed = []
# Date patterns to look for in titles/descriptions
date_patterns = [
r'(\d{1,2})[./](\d{1,2})[./](\d{2,4})', # M/D/YY or M.D.YYYY
r'(\d{4})-(\d{2})-(\d{2})', # YYYY-MM-DD
]
for video in videos:
title = video["title"]
desc = video.get("description", "")
# Determine video type
video_type = "song" # default
title_lower = title.lower()
if "full show" in title_lower or "live at" in title_lower or "night 1" in title_lower or "night 2" in title_lower or "night 3" in title_lower:
video_type = "full_show"
elif "" in title or "->" in title:
video_type = "sequence"
elif "documentary" in title_lower or "behind" in title_lower:
video_type = "documentary"
elif "visualizer" in title_lower:
video_type = "visualizer"
elif "session" in title_lower or "studio" in title_lower:
video_type = "session"
# Try to extract date
show_date = None
# Check description first (often has date info)
combined_text = f"{title} {desc}"
for pattern in date_patterns:
match = re.search(pattern, combined_text)
if match:
groups = match.groups()
try:
if len(groups[0]) == 4: # YYYY-MM-DD
show_date = f"{groups[0]}-{groups[1]}-{groups[2]}"
else: # M/D/YY
year = groups[2]
if len(year) == 2:
year = "20" + year if int(year) < 50 else "19" + year
month = groups[0].zfill(2)
day = groups[1].zfill(2)
show_date = f"{year}-{month}-{day}"
break
except:
pass
# Extract venue from title if possible
venue = None
venue_patterns = [
r'@ (.+)$',
r'at (.+?) -',
r'Live at (.+)',
r'- (.+?, [A-Z]{2})$',
]
for pattern in venue_patterns:
match = re.search(pattern, title, re.IGNORECASE)
if match:
venue = match.group(1).strip()
break
parsed.append({
"videoId": video["videoId"],
"title": title,
"date": show_date,
"venue": venue,
"type": video_type,
"publishedAt": video["publishedAt"]
})
return parsed
def main():
print("Fetching Goose YouTube channel videos...")
# Get channel ID
print(f"Looking up channel: {CHANNEL_HANDLE}")
channel_id = get_channel_id(CHANNEL_HANDLE)
if not channel_id:
print("Could not find channel!")
return
print(f"Channel ID: {channel_id}")
# Get uploads playlist
uploads_playlist = get_uploads_playlist_id(channel_id)
if not uploads_playlist:
print("Could not find uploads playlist!")
return
print(f"Uploads playlist: {uploads_playlist}")
# Fetch all videos
videos = get_all_videos(uploads_playlist)
print(f"\nTotal videos found: {len(videos)}")
# Parse metadata
parsed = parse_video_metadata(videos)
# Save to JSON
output_file = "youtube_videos.json"
with open(output_file, 'w') as f:
json.dump(parsed, f, indent=2)
print(f"\nSaved to {output_file}")
# Show stats
types = {}
dated = 0
for v in parsed:
types[v["type"]] = types.get(v["type"], 0) + 1
if v["date"]:
dated += 1
print("\n=== Stats ===")
print(f"Total: {len(parsed)}")
print(f"With dates: {dated}")
for vtype, count in sorted(types.items()):
print(f" {vtype}: {count}")
if __name__ == "__main__":
main()

View file

@ -0,0 +1,89 @@
from sqlmodel import Session, create_engine, select
import os
from models import Show, Song, Venue, Performance, Tour
from slugify import generate_slug, generate_show_slug, generate_performance_slug
# Use environment variable or default to local sqlite for testing
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./database.db")
engine = create_engine(DATABASE_URL)
def fix_numeric_slugs():
with Session(engine) as session:
# 1. Songs
songs = session.exec(select(Song)).all()
for song in songs:
if song.slug and song.slug.isdigit():
old_slug = song.slug
new_slug = generate_slug(song.title)
# Check for collisions
base_slug = new_slug
counter = 1
while session.exec(select(Song).where(Song.slug == new_slug).where(Song.id != song.id)).first():
new_slug = f"{base_slug}-{counter}"
counter += 1
print(f"Updating Song slug: {old_slug} -> {new_slug}")
song.slug = new_slug
session.add(song)
# 2. Venues
venues = session.exec(select(Venue)).all()
for venue in venues:
if venue.slug and venue.slug.isdigit():
old_slug = venue.slug
new_slug = generate_slug(venue.name)
# Check for collisions
base_slug = new_slug
counter = 1
while session.exec(select(Venue).where(Venue.slug == new_slug).where(Venue.id != venue.id)).first():
new_slug = f"{base_slug}-{counter}"
counter += 1
print(f"Updating Venue slug: {old_slug} -> {new_slug}")
venue.slug = new_slug
session.add(venue)
# 3. Shows
shows = session.exec(select(Show)).all()
for show in shows:
if show.slug and show.slug.isdigit():
old_slug = show.slug
venue_name = show.venue.name if (show.venue) else "unknown"
new_slug = generate_show_slug(show.date.strftime("%Y-%m-%d"), venue_name)
# Check for collisions
base_slug = new_slug
counter = 1
while session.exec(select(Show).where(Show.slug == new_slug).where(Show.id != show.id)).first():
new_slug = f"{base_slug}-{counter}"
counter += 1
print(f"Updating Show slug: {old_slug} -> {new_slug}")
show.slug = new_slug
session.add(show)
# 4. Performances (checking just in case)
performances = session.exec(select(Performance)).all()
for perf in performances:
if perf.slug and perf.slug.isdigit():
old_slug = perf.slug
song_title = perf.song.title if perf.song else "unknown"
show_date = perf.show.date.strftime("%Y-%m-%d") if perf.show else "unknown"
new_slug = generate_performance_slug(song_title, show_date)
# Check for collisions
base_slug = new_slug
counter = 1
while session.exec(select(Performance).where(Performance.slug == new_slug).where(Performance.id != perf.id)).first():
new_slug = f"{base_slug}-{counter}"
counter += 1
print(f"Updating Performance slug: {old_slug} -> {new_slug}")
perf.slug = new_slug
session.add(perf)
session.commit()
print("Slug fixation complete.")
if __name__ == "__main__":
fix_numeric_slugs()

108
backend/fix_set_names.py Normal file
View file

@ -0,0 +1,108 @@
import requests
from sqlmodel import Session, select
from database import engine
from models import Performance, Show, Song
from import_elgoose import fetch_json
BASE_URL = "https://elgoose.net/api/v2"
# Disable SQL echoing for this script to reduce noise
engine.echo = False
def fix_set_names():
print("🔧 Fixing set names in database...")
with Session(engine) as session:
# Load maps (we need show_id and song_id mapping if we rely on API IDs...
# but API setlists endpoint returns show_id and song_id (El Goose IDs))
# We need to match existing performances by show/song/position.
# To avoid re-fetching ALL simple tables, let's just map on the fly or load needed.
# Actually, simpler:
# 1. Fetch setlists page.
# 2. For each item, find corresponding Performance in DB using elgoose IDs?
# Wait, Performance table doesn't store El Goose IDs directly (no external_id column).
# It links to Show and Song. Show and Song *might* not strictly store external ID either (only slug/etc).
# But `import_elgoose.py` maps them.
# We need to map El Goose Show ID -> local Show ID
# We need to map El Goose Song ID -> local Song ID
# This is tricky without storing external IDs.
# However, we can fetch all shows and map via date? No, Shows might map via...
# Wait, how does `import_elgoose.py` map?
# distinct show_id map.
print("Loading Show Map (by date + venue? No, we need external IDs)...")
# Since we didn't save external IDs on Show/Song tables, we have to rebuild the map
# the same way import_elgoose does (fetching shows to get their IDs and matching to DB).
# This is heavy.
# ALTERNATIVE:
# Just map by (Show Date, Song Title, Position)?
# Show Date is in Show table. Song Title in Song table. Performance has position.
# API setlist item has: showdate, songname, position, setnumber.
# This is sufficient!
page = 1
updated_count = 0
while True:
print(f" Fetching page {page}...", end="", flush=True)
data = fetch_json("setlists", {"page": page})
if not data:
print(" Done.")
break
print(f" Loop {len(data)} items...", end="", flush=True)
for item in data:
show_date_str = item.get('showdate')
song_name = item.get('songname')
position = item.get('position')
setnumber = item.get('setnumber', '1')
if not show_date_str or not song_name:
continue
# Find DB records
# Join Performance -> Show, Song
db_perf = session.exec(
select(Performance)
.join(Show)
.join(Song)
.where(Show.date == show_date_str)
.where(Song.title == song_name)
.where(Performance.position == position)
).first()
if db_perf:
# Logic to determine set name
set_val = str(setnumber) if setnumber is not None else '1'
new_set_name = "Set 1"
if set_val.isdigit():
new_set_name = f"Set {set_val}"
elif set_val.lower() == 'e':
new_set_name = "Encore"
elif set_val.lower() == 'e2':
new_set_name = "Encore 2"
elif set_val.lower() == 's':
new_set_name = "Soundcheck"
else:
new_set_name = f"Set {set_val}"
if db_perf.set_name != new_set_name:
db_perf.set_name = new_set_name
session.add(db_perf)
updated_count += 1
session.commit()
print(f" Committed (Total updated: {updated_count})")
page += 1
if page > 200: # Safety
break
if __name__ == "__main__":
fix_set_names()

56
backend/fix_tour_dates.py Normal file
View file

@ -0,0 +1,56 @@
#!/usr/bin/env python3
"""
Fix Tour Dates Script
Iterates through all Tours, finds their associated shows, and updates
the tour's start_date and end_date based on the range of show dates.
"""
from sqlmodel import Session, select
from database import engine
from models import Tour, Show
from datetime import datetime
def fix_tour_dates():
print("="*60)
print("FIX TOUR DATES")
print("="*60)
with Session(engine) as session:
tours = session.exec(select(Tour)).all()
print(f"Found {len(tours)} tours to process.")
updated_count = 0
for tour in tours:
# Get all shows for this tour
shows = session.exec(
select(Show).where(Show.tour_id == tour.id)
).all()
if not shows:
print(f"Skipping '{tour.name}' - No shows found.")
continue
dates = [s.date for s in shows]
min_date = min(dates)
max_date = max(dates)
# Check if update is needed
needs_update = False
if tour.start_date != min_date:
tour.start_date = min_date
needs_update = True
if tour.end_date != max_date:
tour.end_date = max_date
needs_update = True
if needs_update:
session.add(tour)
updated_count += 1
print(f"Updated '{tour.name}': {min_date.date()} - {max_date.date()}")
session.commit()
print(f"\nSuccessfully updated {updated_count} tours.")
if __name__ == "__main__":
fix_tour_dates()

29
backend/fix_tours.py Normal file
View file

@ -0,0 +1,29 @@
from sqlmodel import Session, select, func
from database import engine
from models import Tour, Show
def fix_tour_dates():
with Session(engine) as session:
tours = session.exec(select(Tour)).all()
print(f"Fixing dates for {len(tours)} tours...")
for tour in tours:
# Find min/max show date
result = session.exec(
select(func.min(Show.date), func.max(Show.date))
.where(Show.tour_id == tour.id)
).first()
if result and result[0]:
tour.start_date = result[0]
tour.end_date = result[1]
session.add(tour)
# print(f" {tour.name}: {tour.start_date.date()} - {tour.end_date.date()}")
# else:
# print(f" {tour.name}: No shows found")
session.commit()
print("Done.")
if __name__ == "__main__":
fix_tour_dates()

19
backend/helpers.py Normal file
View file

@ -0,0 +1,19 @@
from sqlmodel import Session
from models import Notification
def create_notification(session: Session, user_id: int, title: str, message: str, type: str, link: str = None):
notification = Notification(
user_id=user_id,
title=title,
message=message,
type=type,
link=link
)
session.add(notification)
# Note: caller is responsible for commit if part of larger transaction,
# but for simple notification triggers, we can commit here or let caller do it.
# To be safe and atomic, usually we add to session and let caller commit.
# But for a helper, instant commit ensures specific notification persistence.
session.commit()
session.refresh(notification)
return notification

View file

@ -0,0 +1,114 @@
"""
Bandcamp Catalog Import Script
Scrapes the Goose Bandcamp discography page to get all album URLs,
then matches them to shows by date and updates the database.
Run: python import_bandcamp_catalog.py [--save]
"""
import re
import requests
from datetime import datetime
from sqlmodel import Session, select
from database import engine
from models import Show
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36'
}
def scrape_bandcamp_catalog() -> dict:
"""
Scrape the Goose Bandcamp music page for all album URLs.
Returns dict mapping date (YYYY-MM-DD) -> URL
"""
music_url = "https://goosetheband.bandcamp.com/music"
albums = {}
try:
resp = requests.get(music_url, headers=HEADERS, timeout=30)
if resp.status_code != 200:
print(f"Failed to fetch Bandcamp catalog: {resp.status_code}")
return {}
html = resp.text
# Extract album URLs - pattern: album/YYYY-MM-DD-rest-of-slug
# The URLs appear as relative paths like: album/2025-12-13-goosemas-show-upon-time...
url_pattern = r'album/(\d{4})-(\d{2})-(\d{2})-[a-z0-9-]+'
for match in re.finditer(url_pattern, html):
album_path = match.group(0)
year, month, day = match.groups()
date_str = f"{year}-{month}-{day}"
full_url = f"https://goosetheband.bandcamp.com/{album_path}"
# Keep the first URL for each date (in case of duplicates)
if date_str not in albums:
albums[date_str] = full_url
print(f"Scraped {len(albums)} Bandcamp album URLs")
return albums
except Exception as e:
print(f"Error scraping Bandcamp: {e}")
return {}
def main(dry_run: bool = True):
print("=" * 60)
print("Bandcamp Catalog Import")
print("=" * 60)
# Scrape catalog
bandcamp_albums = scrape_bandcamp_catalog()
if not bandcamp_albums:
print("No albums found, exiting.")
return
with Session(engine) as session:
# Get all shows
shows = session.exec(select(Show)).all()
print(f"Found {len(shows)} shows in database")
updated = 0
already_had = 0
not_found = 0
for show in shows:
date_str = show.date.strftime("%Y-%m-%d")
# Check if already has a proper album link
if show.bandcamp_link and "/album/" in show.bandcamp_link:
already_had += 1
continue
# Look up in catalog
if date_str in bandcamp_albums:
new_url = bandcamp_albums[date_str]
print(f"{date_str} -> {new_url}")
updated += 1
if not dry_run:
show.bandcamp_link = new_url
session.add(show)
else:
not_found += 1
if not dry_run:
session.commit()
print("\n" + "=" * 60)
print("Summary")
print("=" * 60)
print(f"Shows with new Bandcamp link: {updated}")
print(f"Shows already had album link: {already_had}")
print(f"Shows not found in Bandcamp: {not_found}")
if dry_run:
print("\n[DRY RUN - Run with --save to commit changes]")
if __name__ == "__main__":
import sys
dry_run = "--save" not in sys.argv
main(dry_run=dry_run)

103
backend/import_by_date.py Normal file
View file

@ -0,0 +1,103 @@
"""
Direct Date-Based Setlist Importer
Matches setlists to shows by date
"""
import requests
from datetime import datetime
from sqlmodel import Session, select
from database import engine
from models import Show, Song, Performance
BASE_URL = "https://elgoose.net/api/v2"
def main():
print("DATE-BASED SETLIST IMPORTER")
print("=" * 40)
with Session(engine) as session:
# Build show map by date
shows = session.exec(select(Show)).all()
show_by_date = {}
for s in shows:
date_str = s.date.strftime('%Y-%m-%d')
show_by_date[date_str] = s.id
print(f"Mapped {len(show_by_date)} shows by date")
# Build song map by title (lowercase)
songs = session.exec(select(Song)).all()
song_map = {s.title.lower().strip(): s.id for s in songs}
print(f"Mapped {len(song_map)} songs")
# Get existing performances for dedup
existing = set()
perfs = session.exec(
select(Performance.show_id, Performance.song_id, Performance.position)
).all()
for p in perfs:
existing.add((p[0], p[1], p[2]))
print(f"Found {len(existing)} existing performances")
# Fetch setlists page by page
print("\\nImporting setlists...")
page = 1
total_added = 0
while page <= 200: # Safety limit
print(f" Page {page}...", end="", flush=True)
url = f"{BASE_URL}/setlists.json"
try:
resp = requests.get(url, params={"page": page}, timeout=60)
data = resp.json().get('data', [])
except Exception as e:
print(f" Error: {e}")
break
if not data:
print(" Done (no data)")
break
added_this_page = 0
for item in data:
# Get showdate and match to our shows
showdate = item.get('showdate')
if not showdate:
continue
our_show_id = show_by_date.get(showdate)
if not our_show_id:
continue
# Match song
song_name = (item.get('songname') or '').lower().strip()
song_id = song_map.get(song_name)
if not song_id:
continue
position = item.get('position', 0)
key = (our_show_id, song_id, position)
if key in existing:
continue
perf = Performance(
show_id=our_show_id,
song_id=song_id,
position=position,
set_name=item.get('setnumber'),
segue=(item.get('transition', ', ') != ', '),
notes=item.get('footnote')
)
session.add(perf)
existing.add(key)
added_this_page += 1
total_added += 1
session.commit()
print(f" +{added_this_page} ({total_added} total)")
page += 1
print(f"\\n✓ Added {total_added} performances")
if __name__ == "__main__":
main()

399
backend/import_elgoose.py Normal file
View file

@ -0,0 +1,399 @@
"""
Comprehensive El Goose Data Importer
Fetches ALL Goose data from El Goose API and populates demo database
"""
import requests
import time
from datetime import datetime
from sqlmodel import Session, select
from database import engine
from models import (
Vertical, Venue, Tour, Show, Song, Performance, Artist,
User, UserPreferences
)
from passlib.context import CryptContext
from slugify import generate_slug, generate_show_slug
BASE_URL = "https://elgoose.net/api/v2"
ARTIST_ID = 1 # Goose
pwd_context = CryptContext(schemes=["argon2"], deprecated="auto")
# User personas for demo
DEMO_USERS = [
{"email": "archivist@demo.com", "username": "TheArchivist", "role": "user", "wiki_mode": True},
{"email": "statnerd@demo.com", "username": "StatNerd420", "role": "user", "wiki_mode": False},
{"email": "reviewer@demo.com", "username": "CriticalListener", "role": "user", "wiki_mode": False},
{"email": "casual@demo.com", "username": "CasualFan", "role": "user", "wiki_mode": False},
{"email": "groupleader@demo.com", "username": "NortheastHonkers", "role": "user", "wiki_mode": False},
{"email": "mod@demo.com", "username": "ModGoose", "role": "moderator", "wiki_mode": False},
{"email": "admin@demo.com", "username": "AdminBird", "role": "admin", "wiki_mode": False},
{"email": "newbie@demo.com", "username": "NewToGoose", "role": "user", "wiki_mode": False},
{"email": "taper@demo.com", "username": "TaperTom", "role": "user", "wiki_mode": False},
{"email": "tourfollower@demo.com", "username": "RoadWarrior", "role": "user", "wiki_mode": False},
{"email": "lurker@demo.com", "username": "SilentHonker", "role": "user", "wiki_mode": True},
{"email": "hype@demo.com", "username": "HypeGoose", "role": "user", "wiki_mode": False},
]
def fetch_json(endpoint, params=None):
"""Fetch JSON from El Goose API (Single Page)"""
url = f"{BASE_URL}/{endpoint}.json"
try:
response = requests.get(url, params=params)
response.raise_for_status()
data = response.json()
if data.get('error') == 1:
print(f"❌ API Error: {data.get('error_message')}")
return None
return data.get('data', [])
except Exception as e:
print(f"❌ Failed to fetch {endpoint}: {e}")
return None
def fetch_all_json(endpoint, params=None):
"""Fetch ALL data from El Goose API using pagination"""
all_data = []
page = 1
params = params.copy() if params else {}
print(f" Fetching {endpoint} pages...", end="", flush=True)
while True:
params['page'] = page
data = fetch_json(endpoint, params)
if not data:
break
all_data.extend(data)
print(f" {page}", end="", flush=True)
# If less than 50 results (typical page size might be larger, but if small, likely last page)
# Actually API returns empty list [] if page out of range usually.
# So 'if not data' handles it.
# Safety break if too many pages
if page > 100:
print(" (Safety limit reached)", end="")
break
page += 1
print(" Done.")
return all_data
def create_users(session):
"""Create demo user personas"""
print("\n📝 Creating user personas...")
users = []
for user_data in DEMO_USERS:
# Check existing
existing = session.exec(
select(User).where(User.email == user_data["email"])
).first()
if existing:
users.append(existing)
continue
user = User(
email=user_data["email"],
hashed_password=pwd_context.hash("demo123"),
is_active=True,
is_superuser=(user_data["role"] == "admin"),
role=user_data["role"]
)
session.add(user)
session.commit()
session.refresh(user)
prefs = UserPreferences(
user_id=user.id,
wiki_mode=user_data["wiki_mode"],
show_ratings=not user_data["wiki_mode"],
show_comments=not user_data["wiki_mode"]
)
session.add(prefs)
users.append(user)
session.commit()
print(f"✓ Created/Found {len(users)} users")
return users
def import_venues(session):
"""Import all venues"""
print("\n🏛️ Importing venues...")
venues_data = fetch_all_json("venues")
if not venues_data:
return {}
venue_map = {}
for v in venues_data:
existing = session.exec(
select(Venue).where(Venue.name == v['venuename'])
).first()
if existing:
venue_map[v['venue_id']] = existing.id
else:
venue = Venue(
name=v['venuename'],
slug=generate_slug(v['venuename']),
city=v.get('city'),
state=v.get('state'),
country=v.get('country'),
capacity=v.get('capacity')
)
session.add(venue)
session.commit()
session.refresh(venue)
venue_map[v['venue_id']] = venue.id
print(f"✓ Imported {len(venue_map)} venues")
return venue_map
def import_songs(session, vertical_id):
"""Import all songs"""
print("\n🎵 Importing songs...")
songs_data = fetch_all_json("songs")
if not songs_data:
return {}
song_map = {}
for s in songs_data:
# Check if song exists
existing = session.exec(
select(Song).where(
Song.title == s['name'],
Song.vertical_id == vertical_id
)
).first()
if existing:
song_map[s['id']] = existing.id # API uses 'id' not 'song_id'
else:
song = Song(
title=s['name'],
slug=generate_slug(s['name']),
original_artist=s.get('original_artist'),
vertical_id=vertical_id
# API doesn't include debut_date or times_played in base response
)
session.add(song)
session.commit()
session.refresh(song)
song_map[s['id']] = song.id # API uses 'id' not 'song_id'
print(f"✓ Imported {len(song_map)} songs")
return song_map
def import_shows(session, vertical_id, venue_map):
"""Import all Goose shows"""
print("\n🎤 Importing shows...")
params = {"artist": ARTIST_ID}
shows_data = fetch_all_json("shows", params)
if not shows_data:
# Fallback: fetch all shows and filter
# Fallback: fetch all shows and filter
print(" Fetching all shows and filtering for Goose...")
shows_data = fetch_all_json("shows")
shows_data = [s for s in (shows_data or []) if s.get('artist_id') == ARTIST_ID]
if not shows_data:
print("❌ No shows found")
return {}, {}
show_map = {}
tour_map = {}
for s in shows_data:
# Handle tours
tour_id = None
if s.get('tour_id') and s['tour_id'] != 1: # 1 = "Not Part of a Tour"
if s['tour_id'] not in tour_map:
# Check if tour exists
existing_tour = session.exec(
select(Tour).where(Tour.name == s['tourname'])
).first()
if existing_tour:
tour_map[s['tour_id']] = existing_tour.id
else:
tour = Tour(
name=s['tourname'],
slug=generate_slug(s['tourname'])
)
session.add(tour)
session.commit()
session.refresh(tour)
tour_map[s['tour_id']] = tour.id
tour_id = tour_map[s['tour_id']]
# Create show
show_date = datetime.strptime(s['showdate'], '%Y-%m-%d')
# Check existing show
existing_show = session.exec(
select(Show).where(
Show.date == show_date,
Show.venue_id == venue_map.get(s['venue_id'])
)
).first()
if existing_show:
show_map[s['show_id']] = existing_show.id
else:
show = Show(
date=show_date,
slug=generate_show_slug(s['showdate'], s.get('venuename', 'unknown')),
vertical_id=vertical_id,
venue_id=venue_map.get(s['venue_id']),
tour_id=tour_id,
notes=s.get('showtitle')
)
session.add(show)
session.commit()
session.refresh(show)
show_map[s['show_id']] = show.id
if len(show_map) % 50 == 0:
print(f" Progress: {len(show_map)} shows...")
print(f"✓ Imported {len(show_map)} shows and {len(tour_map)} tours")
return show_map, tour_map
def import_setlists(session, show_map, song_map):
"""Import setlists for all shows (Paginated)"""
print("\n📋 Importing setlists...")
page = 1
total_processed = 0
performance_count = 0
new_performance_ids = [] # Track new performances for chase notifications
params = {}
while True:
params['page'] = page
print(f" Fetching setlists page {page}...", end="", flush=True)
data = fetch_json("setlists", params)
if not data:
print(" Done (No Data/End).")
break
print(f" Processing {len(data)} items...", end="", flush=True)
count_in_page = 0
for perf_data in data:
# Map to our show and song IDs
our_show_id = show_map.get(perf_data.get('show_id'))
our_song_id = song_map.get(perf_data.get('song_id'))
if not our_show_id or not our_song_id:
continue
# Check existing performance validation is expensive.
# We trust idempotency or assume clean run?
# User idempotency request requires checking.
existing_perf = session.exec(
select(Performance).where(
Performance.show_id == our_show_id,
Performance.song_id == our_song_id,
Performance.position == perf_data.get('position', 0)
)
).first()
if not existing_perf:
# Map setnumber to set_name
set_val = str(perf_data.get('setnumber', '1'))
if set_val.isdigit():
set_name = f"Set {set_val}"
elif set_val.lower() == 'e':
set_name = "Encore"
elif set_val.lower() == 'e2':
set_name = "Encore 2"
elif set_val.lower() == 's':
set_name = "Soundcheck"
else:
set_name = f"Set {set_val}"
perf = Performance(
show_id=our_show_id,
song_id=our_song_id,
position=perf_data.get('position', 0),
set_name=set_name,
segue=bool(perf_data.get('segue', 0)),
notes=perf_data.get('notes')
)
session.add(perf)
session.flush() # Get the ID
new_performance_ids.append(perf.id)
count_in_page += 1
performance_count += 1
session.commit()
# Send chase notifications for new performances
if new_performance_ids:
try:
from services.chase_notifications import check_new_performances_for_chases
check_new_performances_for_chases(session, new_performance_ids)
except Exception as e:
print(f" Warning: Chase notifications failed: {e}")
print(f" Validated/Added {count_in_page} items.")
page += 1
new_performance_ids = [] # Reset for next page
print(f"✓ Imported {performance_count} new performances")
def main():
print("="*60)
print("EL GOOSE DATA IMPORTER")
print("="*60)
with Session(engine) as session:
# 1. Get or create vertical
print("\n🦆 Creating Goose vertical...")
vertical = session.exec(
select(Vertical).where(Vertical.slug == "goose")
).first()
if not vertical:
vertical = Vertical(
name="Goose",
slug="goose",
description="Goose is a jam band from Connecticut"
)
session.add(vertical)
session.commit()
session.refresh(vertical)
print(f"✓ Created vertical (ID: {vertical.id})")
else:
print(f"✓ Using existing vertical (ID: {vertical.id})")
# 2. Create users
users = create_users(session)
# 3. Import base data
venue_map = import_venues(session)
song_map = import_songs(session, vertical.id)
# 4. Import shows
show_map, tour_map = import_shows(session, vertical.id, venue_map)
# 5. Import setlists
import_setlists(session, show_map, song_map)
print("\n" + "="*60)
print("✓ IMPORT COMPLETE!")
print("="*60)
print(f"\nImported:")
print(f"{len(venue_map)} venues")
print(f"{len(tour_map)} tours")
print(f"{len(song_map)} songs")
print(f"{len(show_map)} shows")
print(f"{len(users)} demo users")
print(f"\nAll passwords: demo123")
print(f"\nStart demo servers:")
print(f" Backend: DATABASE_URL='sqlite:///./elmeg-demo.db' uvicorn main:app --reload --port 8001")
print(f" Frontend: NEXT_PUBLIC_API_URL=http://localhost:8001 npm run dev -- -p 3001")
if __name__ == "__main__":
main()

161
backend/import_per_show.py Normal file
View file

@ -0,0 +1,161 @@
"""
Per-Show Setlist Importer
Fetches setlist for each show individually
"""
import requests
from sqlmodel import Session, select
from database import engine
from models import Show, Song, Performance
BASE_URL = "https://elgoose.net/api/v2"
def fetch_show_setlist(api_show_id):
"""Fetch setlist for a specific show"""
url = f"{BASE_URL}/setlists/showid/{api_show_id}.json"
try:
response = requests.get(url, timeout=30)
response.raise_for_status()
data = response.json()
if data.get('error') == 1:
return None
return data.get('data', [])
except Exception as e:
return None
def main():
print("PER-SHOW SETLIST IMPORTER")
print("=" * 40)
with Session(engine) as session:
# Get all shows
shows = session.exec(select(Show)).all()
print(f"Found {len(shows)} shows in database")
# Build song map by title
songs = session.exec(select(Song)).all()
song_map = {s.title.lower(): s.id for s in songs}
print(f"Mapped {len(song_map)} songs")
# Get existing performances
print("Loading existing performances...")
existing_map = {} # (show_id, song_id, position) -> Performance Object
perfs = session.exec(select(Performance)).all()
for p in perfs:
existing_map[(p.show_id, p.song_id, p.position)] = p
print(f"Found {len(existing_map)} existing performances")
# We need API show IDs. The ElGoose API shows endpoint returns show_id.
# Let's fetch and correlate by date
print("Fetching API shows to get API IDs...")
api_shows = {} # date_str -> api_show_id
page = 1
seen_ids = set()
while True:
url = f"{BASE_URL}/shows.json"
try:
resp = requests.get(url, params={"page": page}, timeout=30)
data = resp.json().get('data', [])
if not data:
break
# Loop detection
first_id = data[0].get('show_id') if data else None
if first_id in seen_ids:
print(f" Loop detected at page {page}")
break
if first_id:
seen_ids.add(first_id)
for s in data:
# CRITICAL: Only include Goose shows
if s.get('artist') != 'Goose':
continue
date_str = s['showdate']
api_shows[date_str] = s['show_id']
page += 1
except Exception as e:
print(f" Error on page {page}: {e}")
break
print(f"Got {len(api_shows)} API show IDs")
# Now import setlists for each show
total_added = 0
total_updated = 0
processed = 0
for show in shows:
date_str = show.date.strftime('%Y-%m-%d')
api_show_id = api_shows.get(date_str)
if not api_show_id:
continue
# REMOVED: Skipping logic. We verify everything.
# existing_for_show = ...
# Fetch setlist
setlist = fetch_show_setlist(api_show_id)
if not setlist:
continue
added = 0
updated = 0
for item in setlist:
song_title = item.get('songname', '').lower()
song_id = song_map.get(song_title)
if not song_id:
continue
position = item.get('position', 0)
key = (show.id, song_id, position)
# Resolve set name
set_val = str(item.get('setnumber', '1'))
if set_val.isdigit():
set_name = f"Set {set_val}"
elif set_val.lower() == 'e':
set_name = "Encore"
elif set_val.lower() == 'e2':
set_name = "Encore 2"
elif set_val.lower() == 's':
set_name = "Soundcheck"
else:
set_name = f"Set {set_val}"
if key in existing_map:
# Update Check
perf = existing_map[key]
if not perf.set_name or perf.set_name != set_name:
perf.set_name = set_name
session.add(perf)
updated += 1
total_updated += 1
continue
# Create New
perf = Performance(
show_id=show.id,
song_id=song_id,
position=position,
set_name=set_name,
segue=bool(item.get('segue', 0)),
notes=item.get('footnote')
)
session.add(perf)
existing_map[key] = perf # Add to map to prevent dupes in same run
added += 1
total_added += 1
if added > 0 or updated > 0:
session.commit()
processed += 1
print(f"Show {date_str}: +{added} new, ~{updated} updated")
print(f"\nImport Complete! Added: {total_added}, Updated: {total_updated}")
if __name__ == "__main__":
main()

View file

@ -0,0 +1,167 @@
"""
Direct setlist import - bypasses broken show_map logic
Imports setlists by matching dates directly
"""
import requests
import time
from datetime import datetime
from sqlmodel import Session, select, func
from database import engine
from models import Show, Song, Performance
from slugify import generate_slug
BASE_URL = "https://elgoose.net/api/v2"
def fetch_json(endpoint, params=None):
"""Fetch JSON from El Goose API"""
url = f"{BASE_URL}/{endpoint}.json"
try:
response = requests.get(url, params=params, timeout=30)
response.raise_for_status()
data = response.json()
if data.get('error') == 1:
return None
return data.get('data', [])
except Exception as e:
print(f"Error fetching {endpoint}: {e}")
return None
def main():
print("=" * 60)
print("DIRECT SETLIST IMPORTER")
print("=" * 60)
with Session(engine) as session:
# Build date -> show_id mapping from our database
print("\n1. Building date->show mapping from database...")
shows = session.exec(select(Show)).all()
date_to_show = {}
for show in shows:
date_str = show.date.strftime('%Y-%m-%d')
date_to_show[date_str] = show.id
print(f" Found {len(date_to_show)} shows in database")
# Build song title -> song_id mapping
print("\n2. Building song mappings from database...")
songs = session.exec(select(Song)).all()
song_title_to_id = {s.title.lower(): s.id for s in songs}
print(f" Found {len(song_title_to_id)} songs in database")
# Fetch setlists from ElGoose
print("\n3. Fetching setlists from ElGoose API...")
page = 1
total_added = 0
total_skipped = 0
while True:
print(f" Page {page}...", end="", flush=True)
data = fetch_json("setlists", {"page": page})
if not data:
print(" Done.")
break
added_this_page = 0
for perf in data:
# Get the show date from the setlist item
show_date = perf.get('showdate')
song_name = perf.get('songname', '').lower()
if not show_date or not song_name:
total_skipped += 1
continue
# Find our show by date
our_show_id = date_to_show.get(show_date)
if not our_show_id:
total_skipped += 1
continue
# Find our song by title
our_song_id = song_title_to_id.get(song_name)
if not our_song_id:
total_skipped += 1
continue
position = perf.get('position', 0)
# Check if performance already exists
existing = session.exec(
select(Performance).where(
Performance.show_id == our_show_id,
Performance.song_id == our_song_id,
Performance.position == position
)
).first()
if existing:
continue
# Map setnumber
set_val = str(perf.get('setnumber', '1'))
if set_val.isdigit():
set_name = f"Set {set_val}"
elif set_val.lower() == 'e':
set_name = "Encore"
elif set_val.lower() == 'e2':
set_name = "Encore 2"
elif set_val.lower() == 's':
set_name = "Soundcheck"
else:
set_name = f"Set {set_val}"
# Create performance
new_perf = Performance(
show_id=our_show_id,
song_id=our_song_id,
position=position,
set_name=set_name,
segue=bool(perf.get('segue', 0)),
notes=perf.get('footnote')
)
session.add(new_perf)
added_this_page += 1
total_added += 1
session.commit()
print(f" added {added_this_page} performances")
if page > 500: # Safety limit
print(" Safety limit reached")
break
page += 1
time.sleep(0.1) # Be nice to the API
# Generate slugs for all performances
print("\n4. Generating slugs for performances...")
perfs_without_slugs = session.exec(
select(Performance).where(Performance.slug == None)
).all()
for perf in perfs_without_slugs:
if perf.song and perf.show:
song_slug = perf.song.slug or generate_slug(perf.song.title)
date_str = perf.show.date.strftime('%Y-%m-%d')
perf.slug = f"{song_slug}-{date_str}"
session.commit()
print(f" Generated {len(perfs_without_slugs)} slugs")
# Final count
total_perfs = session.exec(select(func.count(Performance.id))).one()
shows_with_perfs = session.exec(
select(func.count(func.distinct(Performance.show_id)))
).one()
print("\n" + "=" * 60)
print("IMPORT COMPLETE!")
print("=" * 60)
print(f"\nStats:")
print(f" • Added: {total_added} new performances")
print(f" • Skipped: {total_skipped} (no match)")
print(f" • Total performances: {total_perfs}")
print(f" • Shows with setlists: {shows_with_perfs}")
if __name__ == "__main__":
main()

View file

@ -0,0 +1,186 @@
"""
Smart Setlist Importer (Streaming Version)
Reducing memory usage by processing data in streams instead of bulk loading.
"""
import requests
import time
import gc
from datetime import datetime
from sqlmodel import Session, select
from database import engine
from models import Show, Song, Performance
from slugify import generate_slug
BASE_URL = "https://elgoose.net/api/v2"
def fetch_json(endpoint, params=None):
"""Fetch JSON from El Goose API with retries"""
url = f"{BASE_URL}/{endpoint}.json"
for attempt in range(3):
try:
response = requests.get(url, params=params, timeout=30)
response.raise_for_status()
data = response.json()
if data.get('error') == 1:
return None
return data.get('data', [])
except Exception as e:
print(f" Error fetching {endpoint} (attempt {attempt+1}): {e}")
time.sleep(2)
return None
def main():
print("=" * 60)
print("SMART SETLIST IMPORTER (STREAMING)")
print("=" * 60)
with Session(engine) as session:
# 1. Build DB Map: Date string -> DB Show ID
print("\n1. Building DB Map (Date -> Show ID)...")
shows = session.exec(select(Show.id, Show.date)).all()
date_to_db_id = {s.date.strftime('%Y-%m-%d'): s.id for s in shows}
print(f" Mapped {len(date_to_db_id)} existing shows in DB")
if not date_to_db_id:
print(" CRITICAL: No shows in database!")
return
del shows
gc.collect()
# 2. Build API Map: ElGoose ID -> DB ID
print("\n2. Building ElGoose ID -> DB ID map (Streaming)...")
elgoose_id_to_db_id = {}
page = 1
seen_show_ids = set()
while True:
print(f" Fetching shows page {page}...", end="\r", flush=True)
data = fetch_json("shows", {"page": page})
if not data:
break
# Loop Detection (Shows)
first_id = data[0].get('show_id') if data else None
if first_id and first_id in seen_show_ids:
print(f"\n Loop detected in Shows at page {page} (ID {first_id}). Breaking.")
break
if first_id:
seen_show_ids.add(first_id)
for s in data:
s_date = s.get('showdate')
s_id = s.get('show_id')
if s_date and s_id:
db_id = date_to_db_id.get(s_date)
if db_id:
elgoose_id_to_db_id[s_id] = db_id
page += 1
if page % 10 == 0:
gc.collect()
print(f"\n Mapped {len(elgoose_id_to_db_id)} ElGoose IDs to DB IDs")
del date_to_db_id
gc.collect()
# 3. Caching Songs
print("\n3. Caching Songs...")
songs = session.exec(select(Song.id, Song.title)).all()
song_map = {s.title.lower().strip(): s.id for s in songs}
del songs
gc.collect()
print(f" Cached {len(song_map)} songs")
# 4. Importing Setlists
print("\n4. Importing Setlists...")
page = 1
total_added = 0
seen_batch_signatures = set()
# Cache existing performance keys (show_id, song_id, position)
print(" Caching existing performance keys...")
perfs = session.exec(select(Performance.show_id, Performance.song_id, Performance.position)).all()
existing_keys = set((p.show_id, p.song_id, p.position) for p in perfs)
print(f" Cached {len(existing_keys)} existing performances")
del perfs
gc.collect()
while True:
data = fetch_json("setlists", {"page": page})
if not data:
break
# Loop Detection (Setlists)
# Use signature of first item: (uniqueid or show_id+position)
if data:
first = data[0]
signature = f"{first.get('uniqueid')}-{first.get('show_id')}-{first.get('position')}"
if signature in seen_batch_signatures:
print(f"\n Loop detected in Setlists at page {page} (Sig {signature}). Breaking.")
break
seen_batch_signatures.add(signature)
batch_added = 0
new_objects = []
for perf in data:
elgoose_show_id = perf.get('show_id')
db_show_id = elgoose_id_to_db_id.get(elgoose_show_id)
if not db_show_id:
continue
song_name = perf.get('songname', '').strip()
song_id = song_map.get(song_name.lower())
if not song_id:
continue
position = perf.get('position', 0)
if (db_show_id, song_id, position) in existing_keys:
continue
set_val = str(perf.get('setnumber', '1'))
if set_val.isdigit():
set_name = f"Set {set_val}"
elif set_val.lower() == 'e':
set_name = "Encore"
elif set_val.lower() == 'e2':
set_name = "Encore 2"
elif set_val.lower() == 's':
set_name = "Soundcheck"
else:
set_name = f"Set {set_val}"
new_perf = Performance(
show_id=db_show_id,
song_id=song_id,
position=position,
set_name=set_name,
segue=bool(perf.get('segue', 0)),
notes=perf.get('footnote'),
slug=f"{generate_slug(song_name)}-{db_show_id}-{position}"
)
new_objects.append(new_perf)
existing_keys.add((db_show_id, song_id, position))
batch_added += 1
total_added += 1
if new_objects:
session.add_all(new_objects)
session.commit()
print(f" Page {page}: Added {batch_added} (Total {total_added})", end="\r", flush=True)
page += 1
if page % 20 == 0:
gc.collect()
print(f"\nImport Complete! Total Added: {total_added}")
if __name__ == "__main__":
main()

View file

@ -0,0 +1,199 @@
"""
Import ONLY songs and setlists into existing demo database
Uses correct API field mappings based on actual El Goose API response
"""
import requests
from datetime import datetime
from sqlmodel import Session, select
from database import engine
from models import Vertical, Song, Performance, Show
BASE_URL = "https://elgoose.net/api/v2"
ARTIST_ID = 1 # Goose
def fetch_json(endpoint, params=None):
"""Fetch JSON from El Goose API with error handling"""
url = f"{BASE_URL}/{endpoint}.json"
try:
response = requests.get(url, params=params)
response.raise_for_status()
data = response.json()
if data.get('error') == 1 or data.get('error') == True:
print(f"❌ API Error: {data.get('error_message')}")
return None
return data.get('data', [])
except Exception as e:
print(f"❌ Failed to fetch {endpoint}: {e}")
return None
def import_songs(session, vertical_id):
"""Import all songs using correct API field names"""
print("\n🎵 Importing songs...")
songs_data = fetch_json("songs")
if not songs_data:
print("❌ No song data received")
return {}
song_map = {}
for s in songs_data:
# Check if song exists
existing = session.exec(
select(Song).where(
Song.title == s['name'],
Song.vertical_id == vertical_id
)
).first()
if existing:
song_map[s['id']] = existing.id
else:
song = Song(
title=s['name'],
original_artist=s.get('original_artist'),
vertical_id=vertical_id
)
session.add(song)
session.commit()
session.refresh(song)
song_map[s['id']] = song.id
if len(song_map) % 100 == 0:
print(f" Progress: {len(song_map)} songs...")
print(f"✓ Imported {len(song_map)} songs")
return song_map
def import_setlists(session, vertical_id, song_map):
"""Import setlists for Goose shows only"""
print("\n📋 Importing setlists...")
# Get all our shows from the database
shows = session.exec(
select(Show).where(Show.vertical_id == vertical_id)
).all()
print(f" Found {len(shows)} shows in database")
# Fetch ALL setlists and filter for Goose
print(" Fetching setlists from API...")
setlists_data = fetch_json("setlists")
if not setlists_data:
print("❌ No setlist data found")
return
print(f" Received {len(setlists_data)} total performances")
# Create a map of El Goose show_id to our show id
show_map = {}
for show in shows:
# We need to find the matching El Goose show by date
# Since we imported shows with their original show_id stored... wait, we didn't
# We need to match by date instead
pass
# Actually, let's fetch shows again to get the mapping
shows_data = fetch_json("shows")
if shows_data:
goose_shows = [s for s in shows_data if s.get('artist_id') == ARTIST_ID]
print(f" Found {len(goose_shows)} Goose shows in API")
# Build mapping: El Goose show_id -> our database show id
for eg_show in goose_shows:
eg_date = datetime.strptime(eg_show['showdate'], '%Y-%m-%d').date()
# Find matching show in our DB by date
db_show = session.exec(
select(Show).where(
Show.vertical_id == vertical_id,
Show.date >= datetime.combine(eg_date, datetime.min.time()),
Show.date < datetime.combine(eg_date, datetime.max.time())
)
).first()
if db_show:
show_map[eg_show['show_id']] = db_show.id
print(f" Mapped {len(show_map)} shows")
# Now import performances
performance_count = 0
skipped = 0
for perf_data in setlists_data:
# Only import if this is a Goose show
our_show_id = show_map.get(perf_data.get('show_id'))
if not our_show_id:
skipped += 1
continue
our_song_id = song_map.get(perf_data.get('song_id'))
if not our_song_id:
# Song not found - might be from another artist
skipped += 1
continue
# Check if performance already exists
existing = session.exec(
select(Performance).where(
Performance.show_id == our_show_id,
Performance.song_id == our_song_id,
Performance.position == perf_data.get('position', 0)
)
).first()
if existing:
continue
perf = Performance(
show_id=our_show_id,
song_id=our_song_id,
position=perf_data.get('position', 0),
set_name=perf_data.get('set'),
segue=bool(perf_data.get('segue', 0)),
notes=perf_data.get('notes')
)
session.add(perf)
performance_count += 1
if performance_count % 100 == 0:
session.commit()
print(f" Progress: {performance_count} performances...")
session.commit()
print(f"✓ Imported {performance_count} performances (skipped {skipped} non-Goose)")
def main():
print("="*60)
print("EL GOOSE SONGS & SETLISTS IMPORTER")
print("="*60)
with Session(engine) as session:
# Get existing Goose vertical
vertical = session.exec(
select(Vertical).where(Vertical.slug == "goose")
).first()
if not vertical:
print("❌ Goose vertical not found! Run main import first.")
return
print(f"✓ Found Goose vertical (ID: {vertical.id})")
# Import songs and setlists
song_map = import_songs(session, vertical.id)
import_setlists(session, vertical.id, song_map)
print("\n" + "="*60)
print("✓ IMPORT COMPLETE!")
print("="*60)
print(f"\nImported:")
print(f"{len(song_map)} songs")
print(f"\nDemo environment is now fully populated!")
print(f"\nStart demo servers:")
print(f" Backend: DATABASE_URL='sqlite:///./elmeg-demo.db' uvicorn main:app --reload --port 8001")
print(f" Frontend: NEXT_PUBLIC_API_URL=http://localhost:8001 npm run dev -- -p 3001")
if __name__ == "__main__":
main()

255
backend/import_youtube.py Normal file
View file

@ -0,0 +1,255 @@
"""
YouTube Video Import Script v3
Improved title matching with fuzzy logic and normalization.
"""
import json
import re
from datetime import datetime
from sqlmodel import Session, select
from database import engine
from models import Performance, Show, Song
def make_youtube_url(video_id: str) -> str:
return f"https://www.youtube.com/watch?v={video_id}"
def normalize_title(title: str) -> str:
"""Normalize title for better matching."""
title = title.lower().strip()
# Remove common suffixes/prefixes
title = re.sub(r'\s*\(.*?\)', '', title) # Remove parentheticals
title = re.sub(r'\s*\[.*?\]', '', title) # Remove brackets
title = re.sub(r'\s*feat\.?\s+.*$', '', title, flags=re.IGNORECASE) # Remove feat.
title = re.sub(r'\s*ft\.?\s+.*$', '', title, flags=re.IGNORECASE) # Remove ft.
title = re.sub(r'\s*w/\s+.*$', '', title) # Remove w/ collaborators
title = re.sub(r'\s*[-–—]\s*$', '', title) # Trailing dashes
# Normalize characters
title = title.replace('&', 'and')
title = re.sub(r'[^\w\s]', '', title) # Remove punctuation
title = re.sub(r'\s+', ' ', title) # Collapse whitespace
return title.strip()
def extract_song_title(raw_title: str) -> str:
"""Extract the actual song title from YouTube video title."""
title = raw_title
# Remove common prefixes
title = re.sub(r'^Goose\s*[-–—]\s*', '', title, flags=re.IGNORECASE)
# Remove date patterns (e.g., "- 12/13/25 Providence, RI")
title = re.sub(r'\s*[-–—]\s*\d{1,2}/\d{1,2}/\d{2,4}.*$', '', title)
# Remove "Live at..." suffix
title = re.sub(r'\s*[-–—]\s*Live at.*$', '', title, flags=re.IGNORECASE)
# Remove "(Official Audio)" etc
title = re.sub(r'\s*\(Official\s*(Audio|Video|Visualizer)\)', '', title, flags=re.IGNORECASE)
# Remove "(4K HDR)" etc
title = re.sub(r'\s*\(4K\s*HDR?\)', '', title, flags=re.IGNORECASE)
# Remove "Set I/II Opener" etc
title = re.sub(r'\s*Set\s*(I|II|1|2)?\s*Opener.*$', '', title, flags=re.IGNORECASE)
# Remove "Live from..." suffix
title = re.sub(r'\s*Live from.*$', '', title, flags=re.IGNORECASE)
# Remove date at start (e.g., "9/20/2025")
title = re.sub(r'^\d{1,2}/\d{1,2}/\d{2,4}\s*', '', title)
# Remove location suffix (e.g., "Providence, RI")
title = re.sub(r'\s*[-–—]?\s*[A-Z][a-z]+,?\s*[A-Z]{2}\s*$', '', title)
return title.strip()
def find_song_match(session, song_title: str, all_songs: list) -> Song:
"""Try multiple matching strategies to find a song."""
normalized_search = normalize_title(song_title)
# Strategy 1: Exact match (case insensitive)
for song in all_songs:
if song.title.lower() == song_title.lower():
return song
# Strategy 2: Normalized exact match
for song in all_songs:
if normalize_title(song.title) == normalized_search:
return song
# Strategy 3: Starts with (for songs with suffixes in DB)
for song in all_songs:
if normalize_title(song.title).startswith(normalized_search):
return song
if normalized_search.startswith(normalize_title(song.title)):
return song
# Strategy 4: Contains (substring match)
for song in all_songs:
norm_song = normalize_title(song.title)
if len(normalized_search) >= 4: # Avoid short false positives
if normalized_search in norm_song or norm_song in normalized_search:
return song
# Strategy 5: Word overlap (for complex titles)
search_words = set(normalized_search.split())
if len(search_words) >= 2: # Only for multi-word titles
for song in all_songs:
song_words = set(normalize_title(song.title).split())
# If most words match
overlap = len(search_words & song_words)
if overlap >= len(search_words) * 0.7:
return song
return None
def import_videos():
"""Import video links into the database."""
with open("youtube_videos.json", 'r') as f:
videos = json.load(f)
stats = {
'songs_matched': 0,
'songs_not_found': 0,
'songs_not_found_titles': [],
'sequences_processed': 0,
'full_shows_matched': 0,
'no_date': 0,
'skipped': 0,
'show_not_found': 0
}
with Session(engine) as session:
# Pre-load all songs for faster matching
all_songs = session.exec(select(Song)).all()
print(f"Loaded {len(all_songs)} songs from database")
for video in videos:
video_id = video.get('videoId')
raw_title = video.get('title', '')
video_type = video.get('type', 'song')
date_str = video.get('date')
youtube_url = make_youtube_url(video_id)
# Skip non-performance content
if video_type in ('documentary', 'visualizer', 'session'):
stats['skipped'] += 1
continue
# Skip videos without dates
if not date_str:
stats['no_date'] += 1
continue
# Parse date
try:
show_date = datetime.strptime(date_str, '%Y-%m-%d')
except ValueError:
stats['no_date'] += 1
continue
# Find show by date
show = session.exec(
select(Show).where(Show.date == show_date)
).first()
if not show:
stats['show_not_found'] += 1
continue
# Handle full shows
if video_type == 'full_show':
show.youtube_link = youtube_url
session.add(show)
stats['full_shows_matched'] += 1
continue
# Extract song title
song_title = extract_song_title(raw_title)
# Handle sequences
if video_type == 'sequence' or '' in song_title or '>' in song_title:
song_titles = [s.strip() for s in re.split(r'[→>]', song_title)]
matched_any = False
for title in song_titles:
if not title or len(title) < 2:
continue
song = find_song_match(session, title, all_songs)
if song:
perf = session.exec(
select(Performance).where(
Performance.show_id == show.id,
Performance.song_id == song.id
)
).first()
if perf:
perf.youtube_link = youtube_url
session.add(perf)
matched_any = True
if matched_any:
stats['sequences_processed'] += 1
else:
stats['songs_not_found'] += 1
stats['songs_not_found_titles'].append(f"SEQ: {song_title}")
continue
# Single song matching
song = find_song_match(session, song_title, all_songs)
if song:
perf = session.exec(
select(Performance).where(
Performance.show_id == show.id,
Performance.song_id == song.id
)
).first()
if perf:
perf.youtube_link = youtube_url
session.add(perf)
stats['songs_matched'] += 1
else:
# Song exists but wasn't played at this show
stats['songs_not_found'] += 1
stats['songs_not_found_titles'].append(f"{date_str}: {song_title} (song exists, no perf)")
else:
stats['songs_not_found'] += 1
stats['songs_not_found_titles'].append(f"{date_str}: {song_title}")
session.commit()
print("\n" + "="*50)
print("IMPORT SUMMARY")
print("="*50)
print(f" songs_matched: {stats['songs_matched']}")
print(f" sequences_processed: {stats['sequences_processed']}")
print(f" full_shows_matched: {stats['full_shows_matched']}")
print(f" songs_not_found: {stats['songs_not_found']}")
print(f" no_date: {stats['no_date']}")
print(f" skipped: {stats['skipped']}")
print(f" show_not_found: {stats['show_not_found']}")
total_linked = stats['songs_matched'] + stats['sequences_processed'] + stats['full_shows_matched']
print(f"\n TOTAL LINKED: {total_linked}")
# Show some unmatched titles for debugging
if stats['songs_not_found_titles']:
print("\n" + "="*50)
print("SAMPLE UNMATCHED (first 20):")
print("="*50)
for title in stats['songs_not_found_titles'][:20]:
print(f" - {title}")
if __name__ == "__main__":
import_videos()

View file

@ -0,0 +1,4 @@
# Fediversion Data Importers
# Band-specific importers for setlist data
from .base import ImporterBase

321
backend/importers/base.py Normal file
View file

@ -0,0 +1,321 @@
"""
Fediversion Data Importer Base Class
Abstract base class providing common functionality for all band-specific importers:
- Rate limiting
- Caching
- Idempotent upsert logic
- Progress tracking
"""
import time
import requests
import hashlib
import json
from abc import ABC, abstractmethod
from datetime import datetime
from pathlib import Path
from typing import Optional, Dict, List, Any
from sqlmodel import Session, select
from database import engine
from models import Vertical, Venue, Tour, Show, Song, Performance
from slugify import generate_slug, generate_show_slug
class ImporterBase(ABC):
"""Base class for all band data importers"""
# Override in subclasses
VERTICAL_NAME: str = ""
VERTICAL_SLUG: str = ""
VERTICAL_DESCRIPTION: str = ""
# Rate limiting
REQUEST_DELAY: float = 0.5 # seconds between requests
# Cache settings
CACHE_DIR: Path = Path(__file__).parent / ".cache"
CACHE_TTL: int = 3600 # 1 hour
def __init__(self, session: Session):
self.session = session
self.vertical: Optional[Vertical] = None
self.venue_map: Dict[str, int] = {} # external_id -> our_id
self.song_map: Dict[str, int] = {}
self.show_map: Dict[str, int] = {}
self.tour_map: Dict[str, int] = {}
self.last_request_time: float = 0
# Ensure cache directory exists
self.CACHE_DIR.mkdir(exist_ok=True)
def _rate_limit(self):
"""Ensure we don't exceed rate limits"""
elapsed = time.time() - self.last_request_time
if elapsed < self.REQUEST_DELAY:
time.sleep(self.REQUEST_DELAY - elapsed)
self.last_request_time = time.time()
def _cache_key(self, url: str, params: Optional[Dict] = None) -> str:
"""Generate cache key for request"""
key_data = url + (json.dumps(params, sort_keys=True) if params else "")
return hashlib.md5(key_data.encode()).hexdigest()
def _get_cache(self, cache_key: str) -> Optional[Dict]:
"""Get cached response if valid"""
cache_file = self.CACHE_DIR / f"{cache_key}.json"
if cache_file.exists():
try:
data = json.loads(cache_file.read_text())
if time.time() - data.get("cached_at", 0) < self.CACHE_TTL:
return data.get("response")
except (json.JSONDecodeError, KeyError):
pass
return None
def _set_cache(self, cache_key: str, response: Any):
"""Store response in cache"""
cache_file = self.CACHE_DIR / f"{cache_key}.json"
cache_file.write_text(json.dumps({
"cached_at": time.time(),
"response": response
}))
def fetch_json(self, url: str, params: Optional[Dict] = None,
headers: Optional[Dict] = None, use_cache: bool = True) -> Optional[Dict]:
"""Fetch JSON with rate limiting and caching"""
cache_key = self._cache_key(url, params)
if use_cache:
cached = self._get_cache(cache_key)
if cached is not None:
return cached
self._rate_limit()
try:
response = requests.get(url, params=params, headers=headers, timeout=30)
response.raise_for_status()
data = response.json()
if use_cache:
self._set_cache(cache_key, data)
return data
except requests.RequestException as e:
print(f"❌ Request failed: {url} - {e}")
return None
def get_or_create_vertical(self) -> Vertical:
"""Get or create the vertical for this importer"""
if self.vertical:
return self.vertical
self.vertical = self.session.exec(
select(Vertical).where(Vertical.slug == self.VERTICAL_SLUG)
).first()
if not self.vertical:
self.vertical = Vertical(
name=self.VERTICAL_NAME,
slug=self.VERTICAL_SLUG,
description=self.VERTICAL_DESCRIPTION
)
self.session.add(self.vertical)
self.session.commit()
self.session.refresh(self.vertical)
print(f"✓ Created vertical: {self.VERTICAL_NAME}")
else:
print(f"✓ Using existing vertical: {self.VERTICAL_NAME}")
return self.vertical
def upsert_venue(self, name: str, city: str, state: Optional[str],
country: str, external_id: Optional[str] = None,
capacity: Optional[int] = None) -> int:
"""Insert or update a venue, return internal ID"""
# Check if we've already processed this
if external_id and external_id in self.venue_map:
return self.venue_map[external_id]
# Check database
existing = self.session.exec(
select(Venue).where(Venue.name == name, Venue.city == city)
).first()
if existing:
venue_id = existing.id
else:
venue = Venue(
name=name,
slug=generate_slug(name),
city=city,
state=state,
country=country,
capacity=capacity
)
self.session.add(venue)
self.session.commit()
self.session.refresh(venue)
venue_id = venue.id
if external_id:
self.venue_map[external_id] = venue_id
return venue_id
def upsert_song(self, title: str, original_artist: Optional[str] = None,
external_id: Optional[str] = None) -> int:
"""Insert or update a song, return internal ID"""
if external_id and external_id in self.song_map:
return self.song_map[external_id]
vertical = self.get_or_create_vertical()
existing = self.session.exec(
select(Song).where(Song.title == title, Song.vertical_id == vertical.id)
).first()
if existing:
song_id = existing.id
else:
song = Song(
title=title,
slug=generate_slug(title),
original_artist=original_artist,
vertical_id=vertical.id
)
self.session.add(song)
self.session.commit()
self.session.refresh(song)
song_id = song.id
if external_id:
self.song_map[external_id] = song_id
return song_id
def upsert_tour(self, name: str, start_date: Optional[datetime] = None,
end_date: Optional[datetime] = None,
external_id: Optional[str] = None) -> int:
"""Insert or update a tour, return internal ID"""
if external_id and external_id in self.tour_map:
return self.tour_map[external_id]
existing = self.session.exec(
select(Tour).where(Tour.name == name)
).first()
if existing:
tour_id = existing.id
else:
tour = Tour(
name=name,
slug=generate_slug(name),
start_date=start_date,
end_date=end_date
)
self.session.add(tour)
self.session.commit()
self.session.refresh(tour)
tour_id = tour.id
if external_id:
self.tour_map[external_id] = tour_id
return tour_id
def upsert_show(self, date: datetime, venue_id: int,
tour_id: Optional[int] = None, notes: Optional[str] = None,
external_id: Optional[str] = None) -> int:
"""Insert or update a show, return internal ID"""
if external_id and external_id in self.show_map:
return self.show_map[external_id]
vertical = self.get_or_create_vertical()
# Check by date + venue
existing = self.session.exec(
select(Show).where(
Show.date == date,
Show.venue_id == venue_id,
Show.vertical_id == vertical.id
)
).first()
if existing:
show_id = existing.id
else:
# Get venue name for slug
venue = self.session.get(Venue, venue_id)
venue_name = venue.name if venue else "unknown"
show = Show(
date=date,
slug=generate_show_slug(date.strftime("%Y-%m-%d"), venue_name),
vertical_id=vertical.id,
venue_id=venue_id,
tour_id=tour_id,
notes=notes
)
self.session.add(show)
self.session.commit()
self.session.refresh(show)
show_id = show.id
if external_id:
self.show_map[external_id] = show_id
return show_id
def upsert_performance(self, show_id: int, song_id: int, position: int,
set_name: Optional[str] = None, segue: bool = False,
notes: Optional[str] = None) -> int:
"""Insert or update a performance, return internal ID"""
existing = self.session.exec(
select(Performance).where(
Performance.show_id == show_id,
Performance.song_id == song_id,
Performance.position == position
)
).first()
if existing:
return existing.id
perf = Performance(
show_id=show_id,
song_id=song_id,
position=position,
set_name=set_name,
segue=segue,
notes=notes
)
self.session.add(perf)
self.session.commit()
self.session.refresh(perf)
return perf.id
@abstractmethod
def import_all(self):
"""Main entry point - implement in subclasses"""
pass
@abstractmethod
def import_songs(self) -> Dict[str, int]:
"""Import all songs, return mapping of external_id -> internal_id"""
pass
@abstractmethod
def import_venues(self) -> Dict[str, int]:
"""Import all venues, return mapping of external_id -> internal_id"""
pass
@abstractmethod
def import_shows(self) -> Dict[str, int]:
"""Import all shows, return mapping of external_id -> internal_id"""
pass
@abstractmethod
def import_setlists(self):
"""Import setlists/performances for all shows"""
pass

View file

@ -0,0 +1,245 @@
"""
Grateful Stats API Importer
Imports Grateful Dead setlist data from gratefulstats.com API.
This is the primary source for comprehensive Grateful Dead data (1965-1995).
API Documentation: https://gratefulstats.com/api
"""
import os
from datetime import datetime
from typing import Dict, Optional, List
from sqlmodel import Session
from .base import ImporterBase
class GratefulDeadImporter(ImporterBase):
"""Import Grateful Dead data from Grateful Stats API"""
VERTICAL_NAME = "Grateful Dead"
VERTICAL_SLUG = "grateful-dead"
VERTICAL_DESCRIPTION = "The Grateful Dead was an American rock band formed in 1965 in Palo Alto, California. Known for their eclectic style and live performances, they are considered one of the most influential bands of all time."
# Grateful Stats API settings
BASE_URL = "https://gratefulstats.com/api"
def __init__(self, session: Session, api_key: Optional[str] = None):
super().__init__(session)
self.api_key = api_key or os.getenv("GRATEFULSTATS_API_KEY")
# Grateful Stats may not require API key for basic access
def _api_get(self, endpoint: str, params: Optional[Dict] = None) -> Optional[Dict]:
"""Make API request"""
url = f"{self.BASE_URL}/{endpoint}"
if self.api_key:
params = params or {}
params["api_key"] = self.api_key
return self.fetch_json(url, params)
def import_all(self):
"""Run full import of all Grateful Dead data"""
print("=" * 60)
print("GRATEFUL DEAD DATA IMPORTER (via Grateful Stats)")
print("=" * 60)
# 1. Create/get vertical
self.get_or_create_vertical()
# 2. Import songs first
self.import_songs()
# 3. Import shows by year (1965-1995)
self.import_shows()
# 4. Import setlists for each show
self.import_setlists()
print("\n" + "=" * 60)
print("✓ GRATEFUL DEAD IMPORT COMPLETE!")
print("=" * 60)
print(f"{len(self.venue_map)} venues")
print(f"{len(self.song_map)} songs")
print(f"{len(self.show_map)} shows")
def import_songs(self) -> Dict[str, int]:
"""Import all Grateful Dead songs"""
print("\n🎵 Importing songs...")
data = self._api_get("songs")
if not data:
print(" ⚠️ Could not fetch songs from API, will extract from setlists")
return self.song_map
songs = data if isinstance(data, list) else data.get("songs", [])
for song_data in songs:
song_id = str(song_data.get("id", ""))
title = song_data.get("name") or song_data.get("title", "Unknown")
original_artist = song_data.get("original_artist")
if not title or title == "Unknown":
continue
self.upsert_song(
title=title,
original_artist=original_artist,
external_id=song_id if song_id else None
)
print(f"✓ Imported {len(self.song_map)} songs")
return self.song_map
def import_shows(self) -> Dict[str, int]:
"""Import all Grateful Dead shows (1965-1995)"""
print("\n🎤 Importing shows...")
# Grateful Dead active years
years = range(1965, 1996)
for year in years:
print(f" Fetching {year}...", end="", flush=True)
data = self._api_get(f"shows/{year}")
if not data:
print(" (no data)")
continue
shows = data if isinstance(data, list) else data.get("shows", [])
year_count = 0
for show_data in shows:
show_id = str(show_data.get("id", ""))
show_date_str = show_data.get("date") or show_data.get("showdate")
if not show_date_str:
continue
try:
# Try various date formats
for fmt in ["%Y-%m-%d", "%m/%d/%Y", "%d-%m-%Y"]:
try:
show_date = datetime.strptime(show_date_str, fmt)
break
except ValueError:
continue
else:
continue
except Exception:
continue
# Extract venue info
venue_name = show_data.get("venue", "Unknown Venue")
city = show_data.get("city", "Unknown")
state = show_data.get("state")
country = show_data.get("country", "USA")
venue_id = self.upsert_venue(
name=venue_name,
city=city,
state=state,
country=country,
external_id=f"gd_venue_{venue_name}_{city}"
)
# Handle tour if present
tour_id = None
tour_name = show_data.get("tour") or show_data.get("tour_name")
if tour_name:
tour_id = self.upsert_tour(
name=tour_name,
external_id=f"gd_tour_{tour_name}"
)
self.upsert_show(
date=show_date,
venue_id=venue_id,
tour_id=tour_id,
notes=show_data.get("notes"),
external_id=show_id if show_id else None
)
year_count += 1
print(f" {year_count} shows")
print(f"✓ Imported {len(self.show_map)} shows")
return self.show_map
def import_setlists(self):
"""Import setlists for all shows"""
print("\n📋 Importing setlists...")
performance_count = 0
for external_show_id, internal_show_id in self.show_map.items():
if not external_show_id:
continue
data = self._api_get(f"shows/{external_show_id}/setlist")
if not data:
continue
setlist = data if isinstance(data, list) else data.get("setlist", [])
for perf_data in setlist:
song_name = perf_data.get("song") or perf_data.get("name")
if not song_name:
continue
# Get or create song
song_id = self.upsert_song(
title=song_name,
original_artist=perf_data.get("original_artist"),
external_id=f"gd_song_{song_name}"
)
# Parse set information
set_val = perf_data.get("set", "1")
set_name = self._parse_set_name(set_val)
position = perf_data.get("position", performance_count + 1)
# Check for segue
segue = perf_data.get("segue", False) or ">" in str(perf_data.get("transition", ""))
self.upsert_performance(
show_id=internal_show_id,
song_id=song_id,
position=position,
set_name=set_name,
segue=segue,
notes=perf_data.get("notes")
)
performance_count += 1
if performance_count % 1000 == 0:
print(f" Progress: {performance_count} performances...")
print(f"✓ Imported {performance_count} performances")
def _parse_set_name(self, set_value) -> str:
"""Convert set notation to display name"""
set_str = str(set_value).lower()
set_map = {
"1": "Set 1",
"2": "Set 2",
"3": "Set 3",
"e": "Encore",
"e2": "Encore 2",
"encore": "Encore",
}
return set_map.get(set_str, f"Set {set_value}")
def main():
"""Run Grateful Dead import"""
from database import engine
with Session(engine) as session:
importer = GratefulDeadImporter(session)
importer.import_all()
if __name__ == "__main__":
main()

246
backend/importers/phish.py Normal file
View file

@ -0,0 +1,246 @@
"""
Phish.net API v5 Importer
Imports Phish setlist data from the official Phish.net API.
Requires API key from https://phish.net/api
API Documentation: https://phish.net/api/docs
"""
import os
from datetime import datetime
from typing import Dict, Optional, List
from sqlmodel import Session
from .base import ImporterBase
class PhishImporter(ImporterBase):
"""Import Phish data from Phish.net API v5"""
VERTICAL_NAME = "Phish"
VERTICAL_SLUG = "phish"
VERTICAL_DESCRIPTION = "Phish is an American rock band from Burlington, Vermont, formed in 1983."
# Phish.net API settings
BASE_URL = "https://api.phish.net/v5"
def __init__(self, session: Session, api_key: Optional[str] = None):
super().__init__(session)
self.api_key = api_key or os.getenv("PHISHNET_API_KEY")
if not self.api_key:
raise ValueError(
"Phish.net API key required. Set PHISHNET_API_KEY environment variable "
"or pass api_key parameter. Get key at https://phish.net/api"
)
def _api_get(self, endpoint: str, params: Optional[Dict] = None) -> Optional[Dict]:
"""Make API request with key"""
url = f"{self.BASE_URL}/{endpoint}.json"
params = params or {}
params["apikey"] = self.api_key
data = self.fetch_json(url, params)
if data and data.get("error") == 0:
return data.get("data", [])
elif data:
error_msg = data.get("error_message", "Unknown error")
print(f"❌ API Error: {error_msg}")
return None
def import_all(self):
"""Run full import of all Phish data"""
print("=" * 60)
print("PHISH.NET DATA IMPORTER")
print("=" * 60)
# 1. Create/get vertical
self.get_or_create_vertical()
# 2. Import venues
self.import_venues()
# 3. Import songs
self.import_songs()
# 4. Import shows
self.import_shows()
# 5. Import setlists
self.import_setlists()
print("\n" + "=" * 60)
print("✓ PHISH IMPORT COMPLETE!")
print("=" * 60)
print(f"{len(self.venue_map)} venues")
print(f"{len(self.song_map)} songs")
print(f"{len(self.show_map)} shows")
def import_venues(self) -> Dict[str, int]:
"""Import all Phish venues"""
print("\n🏛️ Importing venues...")
# Phish.net doesn't have a dedicated venues endpoint
# Venues are included with show data, so we'll extract them during show import
print(" (Venues will be extracted from show data)")
return self.venue_map
def import_songs(self) -> Dict[str, int]:
"""Import all Phish songs"""
print("\n🎵 Importing songs...")
data = self._api_get("songs")
if not data:
print("❌ Failed to fetch songs")
return self.song_map
for song_data in data:
song_id = str(song_data.get("songid"))
title = song_data.get("song", "Unknown")
original_artist = song_data.get("original_artist")
# Skip if not a real song title
if not title or title == "Unknown":
continue
self.upsert_song(
title=title,
original_artist=original_artist if original_artist != "Phish" else None,
external_id=song_id
)
print(f"✓ Imported {len(self.song_map)} songs")
return self.song_map
def import_shows(self) -> Dict[str, int]:
"""Import all Phish shows"""
print("\n🎤 Importing shows...")
data = self._api_get("shows")
if not data:
print("❌ Failed to fetch shows")
return self.show_map
for show_data in data:
show_id = str(show_data.get("showid"))
show_date_str = show_data.get("showdate")
if not show_date_str:
continue
try:
show_date = datetime.strptime(show_date_str, "%Y-%m-%d")
except ValueError:
continue
# Extract venue info
venue_name = show_data.get("venue", "Unknown Venue")
city = show_data.get("city", "Unknown")
state = show_data.get("state")
country = show_data.get("country", "USA")
venue_id = self.upsert_venue(
name=venue_name,
city=city,
state=state,
country=country,
external_id=f"phish_venue_{venue_name}_{city}"
)
# Handle tour if present
tour_id = None
tour_name = show_data.get("tour_name")
if tour_name:
tour_id = self.upsert_tour(
name=tour_name,
external_id=f"phish_tour_{tour_name}"
)
self.upsert_show(
date=show_date,
venue_id=venue_id,
tour_id=tour_id,
notes=show_data.get("setlistnotes"),
external_id=show_id
)
if len(self.show_map) % 100 == 0:
print(f" Progress: {len(self.show_map)} shows...")
print(f"✓ Imported {len(self.show_map)} shows")
return self.show_map
def import_setlists(self):
"""Import setlists for all shows"""
print("\n📋 Importing setlists...")
performance_count = 0
# Process each show
for external_show_id, internal_show_id in self.show_map.items():
# Fetch setlist for this show by showid
data = self._api_get(f"setlists/showid/{external_show_id}")
if not data:
continue
for perf_data in data:
song_id_ext = str(perf_data.get("songid"))
song_id = self.song_map.get(song_id_ext)
if not song_id:
# Song not in our map, try to add it
song_title = perf_data.get("song")
if song_title:
song_id = self.upsert_song(title=song_title, external_id=song_id_ext)
if not song_id:
continue
# Parse set information
set_name = self._parse_set_name(perf_data.get("set", "1"))
position = perf_data.get("position", 0)
# Check for segue (> symbol in transition)
trans = perf_data.get("trans", "")
segue = ">" in trans if trans else False
self.upsert_performance(
show_id=internal_show_id,
song_id=song_id,
position=position,
set_name=set_name,
segue=segue,
notes=perf_data.get("footnote")
)
performance_count += 1
if len(self.show_map) > 0 and performance_count % 500 == 0:
print(f" Progress: {performance_count} performances...")
print(f"✓ Imported {performance_count} performances")
def _parse_set_name(self, set_value: str) -> str:
"""Convert Phish.net set notation to display name"""
set_map = {
"1": "Set 1",
"2": "Set 2",
"3": "Set 3",
"e": "Encore",
"e2": "Encore 2",
"s": "Soundcheck",
}
return set_map.get(str(set_value).lower(), f"Set {set_value}")
def main():
"""Run Phish import"""
from database import engine
with Session(engine) as session:
importer = PhishImporter(session)
importer.import_all()
if __name__ == "__main__":
main()

View file

@ -0,0 +1,275 @@
"""
Setlist.fm API Importer
Universal fallback importer for bands without dedicated APIs.
Used for: Dead & Company, Billy Strings, and as backup for others.
API Documentation: https://api.setlist.fm/docs/1.0/index.html
"""
import os
from datetime import datetime
from typing import Dict, Optional, List
from sqlmodel import Session
from .base import ImporterBase
class SetlistFmImporter(ImporterBase):
"""Import data from Setlist.fm API"""
# Override these in subclasses for specific bands
ARTIST_MBID: str = "" # MusicBrainz ID
BASE_URL = "https://api.setlist.fm/rest/1.0"
def __init__(self, session: Session, api_key: Optional[str] = None):
super().__init__(session)
self.api_key = api_key or os.getenv("SETLISTFM_API_KEY")
if not self.api_key:
raise ValueError(
"Setlist.fm API key required. Set SETLISTFM_API_KEY environment variable "
"or pass api_key parameter. Get key at https://www.setlist.fm/settings/api"
)
def _api_get(self, endpoint: str, params: Optional[Dict] = None) -> Optional[Dict]:
"""Make API request with key"""
url = f"{self.BASE_URL}/{endpoint}"
headers = {
"Accept": "application/json",
"x-api-key": self.api_key
}
return self.fetch_json(url, params, headers=headers)
def _fetch_all_setlists(self) -> List[Dict]:
"""Fetch all setlists for the artist with pagination"""
all_setlists = []
page = 1
while True:
print(f" Fetching page {page}...", end="", flush=True)
data = self._api_get(
f"artist/{self.ARTIST_MBID}/setlists",
params={"p": page}
)
if not data or "setlist" not in data:
print(" Done.")
break
setlists = data.get("setlist", [])
if not setlists:
print(" Done.")
break
all_setlists.extend(setlists)
print(f" ({len(setlists)} setlists)")
# Check if we've reached the last page
items_per_page = data.get("itemsPerPage", 20)
total = data.get("total", 0)
if page * items_per_page >= total:
break
page += 1
# Safety limit
if page > 200:
print(" (Safety limit reached)")
break
return all_setlists
def import_all(self):
"""Run full import"""
print("=" * 60)
print(f"SETLIST.FM IMPORTER: {self.VERTICAL_NAME}")
print("=" * 60)
# 1. Create/get vertical
self.get_or_create_vertical()
# 2. Fetch all setlists (includes venue, show, and song data)
print("\n📋 Fetching all setlists...")
setlists = self._fetch_all_setlists()
print(f" Found {len(setlists)} setlists")
# 3. Process setlists (imports venues, shows, songs, performances)
self._process_setlists(setlists)
print("\n" + "=" * 60)
print(f"{self.VERTICAL_NAME} IMPORT COMPLETE!")
print("=" * 60)
print(f"{len(self.venue_map)} venues")
print(f"{len(self.song_map)} songs")
print(f"{len(self.show_map)} shows")
def _process_setlists(self, setlists: List[Dict]):
"""Process setlist data to extract and import all entities"""
print("\n🎤 Processing setlists...")
performance_count = 0
for setlist_data in setlists:
setlist_id = setlist_data.get("id")
event_date_str = setlist_data.get("eventDate")
if not event_date_str:
continue
try:
# Setlist.fm uses DD-MM-YYYY format
event_date = datetime.strptime(event_date_str, "%d-%m-%Y")
except ValueError:
continue
# Extract venue
venue_data = setlist_data.get("venue", {})
venue_name = venue_data.get("name", "Unknown Venue")
city_data = venue_data.get("city", {})
city = city_data.get("name", "Unknown")
state = city_data.get("stateCode")
country_data = city_data.get("country", {})
country = country_data.get("name", "Unknown")
venue_id = self.upsert_venue(
name=venue_name,
city=city,
state=state,
country=country,
external_id=venue_data.get("id")
)
# Handle tour if present
tour_id = None
tour_data = setlist_data.get("tour")
if tour_data:
tour_name = tour_data.get("name")
if tour_name:
tour_id = self.upsert_tour(
name=tour_name,
external_id=f"setlistfm_tour_{tour_name}"
)
# Create show
show_id = self.upsert_show(
date=event_date,
venue_id=venue_id,
tour_id=tour_id,
notes=setlist_data.get("info"),
external_id=setlist_id
)
# Process sets and songs
sets = setlist_data.get("sets", {}).get("set", [])
position = 0
for set_idx, set_data in enumerate(sets):
set_name = self._parse_set_name(set_data.get("name", str(set_idx + 1)), set_data.get("encore"))
songs = set_data.get("song", [])
for song_data in songs:
song_name = song_data.get("name")
if not song_name:
continue
position += 1
# Handle covers
cover_data = song_data.get("cover")
original_artist = cover_data.get("name") if cover_data else None
song_id = self.upsert_song(
title=song_name,
original_artist=original_artist,
external_id=f"setlistfm_song_{song_name}"
)
self.upsert_performance(
show_id=show_id,
song_id=song_id,
position=position,
set_name=set_name,
notes=song_data.get("info")
)
performance_count += 1
if len(self.show_map) % 50 == 0:
print(f" Progress: {len(self.show_map)} shows, {performance_count} performances...")
print(f"✓ Processed {len(self.show_map)} shows, {performance_count} performances")
def _parse_set_name(self, name: str, encore: Optional[int] = None) -> str:
"""Convert Setlist.fm set notation to display name"""
if encore:
return f"Encore {encore}" if encore > 1 else "Encore"
# Try to parse numeric set
try:
set_num = int(name)
return f"Set {set_num}"
except (ValueError, TypeError):
return name or "Set 1"
def import_venues(self) -> Dict[str, int]:
return self.venue_map
def import_songs(self) -> Dict[str, int]:
return self.song_map
def import_shows(self) -> Dict[str, int]:
return self.show_map
def import_setlists(self):
pass # Handled in import_all
class DeadAndCompanyImporter(SetlistFmImporter):
"""Import Dead & Company data from Setlist.fm"""
VERTICAL_NAME = "Dead & Company"
VERTICAL_SLUG = "dead-and-company"
VERTICAL_DESCRIPTION = "Dead & Company is a rock band formed in 2015 with Grateful Dead's Bob Weir, Mickey Hart, and Bill Kreutzmann joined by John Mayer, Oteil Burbridge, and Jeff Chimenti."
# Dead & Company MusicBrainz ID
ARTIST_MBID = "94f8947c-2d9c-4519-bcf9-6d11a24ad006"
class BillyStringsImporter(SetlistFmImporter):
"""Import Billy Strings data from Setlist.fm"""
VERTICAL_NAME = "Billy Strings"
VERTICAL_SLUG = "billy-strings"
VERTICAL_DESCRIPTION = "Billy Strings is an American bluegrass musician from Michigan, blending traditional bluegrass with progressive elements."
# Billy Strings MusicBrainz ID
ARTIST_MBID = "640db492-34c4-47df-be14-96e2cd4b9fe4"
def main_dead_and_company():
"""Run Dead & Company import"""
from database import engine
with Session(engine) as session:
importer = DeadAndCompanyImporter(session)
importer.import_all()
def main_billy_strings():
"""Run Billy Strings import"""
from database import engine
with Session(engine) as session:
importer = BillyStringsImporter(session)
importer.import_all()
if __name__ == "__main__":
import sys
if len(sys.argv) > 1:
if sys.argv[1] == "deadco":
main_dead_and_company()
elif sys.argv[1] == "bmfs":
main_billy_strings()
else:
print("Usage: python -m importers.setlistfm [deadco|bmfs]")

18
backend/inspect_api.py Normal file
View file

@ -0,0 +1,18 @@
import requests
import json
def fetch_sample_setlists():
url = "https://elgoose.net/api/v2/setlists.json"
try:
response = requests.get(url, params={"page": 1})
data = response.json()
if 'data' in data:
print(json.dumps(data['data'][:5], indent=2))
# Stats on setnumber
setnumbers = [x.get('setnumber') for x in data['data']]
print(f"\nUnique setnumbers in page 1: {set(setnumbers)}")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
fetch_sample_setlists()

62
backend/main.py Normal file
View file

@ -0,0 +1,62 @@
from fastapi import FastAPI
import os
from routers import auth, shows, venues, songs, social, tours, artists, preferences, reviews, badges, nicknames, moderation, attendance, groups, users, search, performances, notifications, feed, leaderboards, stats, admin, chase, gamification, videos, musicians, sequences
from fastapi.middleware.cors import CORSMiddleware
# Feature flags - set to False to disable features
ENABLE_BUG_TRACKER = os.getenv("ENABLE_BUG_TRACKER", "true").lower() == "true"
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # In production, set this to the frontend domain
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(auth.router)
app.include_router(shows.router)
app.include_router(venues.router)
app.include_router(songs.router)
app.include_router(social.router)
app.include_router(tours.router)
app.include_router(artists.router)
app.include_router(preferences.router)
app.include_router(reviews.router)
app.include_router(badges.router)
app.include_router(nicknames.router)
app.include_router(moderation.router)
app.include_router(attendance.router)
app.include_router(groups.router)
app.include_router(users.router)
app.include_router(search.router)
app.include_router(performances.router)
app.include_router(notifications.router)
app.include_router(feed.router)
app.include_router(leaderboards.router)
app.include_router(stats.router)
app.include_router(admin.router)
app.include_router(chase.router)
app.include_router(gamification.router)
app.include_router(videos.router)
app.include_router(musicians.router)
app.include_router(sequences.router)
# Optional features - can be disabled via env vars
if ENABLE_BUG_TRACKER:
from routers import tickets
app.include_router(tickets.router)
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/healthz")
def health_check():
"""Health check endpoint for monitoring and load balancers"""
return {"status": "healthy"}

159
backend/migrate_honking.py Normal file
View file

@ -0,0 +1,159 @@
"""
Migration script to import real Goose data from Honkingversion to Elmeg Demo
"""
import sqlite3
import sys
from datetime import datetime
from sqlmodel import Session, select
from database import engine
from models import Vertical, Venue, Tour, Show, Song, Performance
SOURCE_DB = "/Users/ten/ANTIGRAVITY/honkingversion/database.db"
def migrate_data():
print("=" * 60)
print("MIGRATING REAL GOOSE DATA")
print("=" * 60)
# Connect to source DB
try:
src_conn = sqlite3.connect(SOURCE_DB)
src_conn.row_factory = sqlite3.Row
src_cur = src_conn.cursor()
print(f"✓ Connected to source: {SOURCE_DB}")
except Exception as e:
print(f"❌ Failed to connect to source DB: {e}")
return
with Session(engine) as session:
# 1. Get or Create Goose Vertical
vertical = session.exec(select(Vertical).where(Vertical.slug == "goose")).first()
if not vertical:
vertical = Vertical(name="Goose", slug="goose", description="Jam band from CT")
session.add(vertical)
session.commit()
session.refresh(vertical)
print(f"✓ Created Goose vertical (ID: {vertical.id})")
else:
print(f"✓ Found Goose vertical (ID: {vertical.id})")
# 2. Clear existing data (except Users)
print("Clearing existing show data...")
session.exec("DELETE FROM performance")
session.exec("DELETE FROM show")
session.exec("DELETE FROM song")
session.exec("DELETE FROM tour")
session.exec("DELETE FROM venue")
session.commit()
print("✓ Cleared existing data")
# 3. Migrate Venues
print("Migrating Venues...")
src_cur.execute("SELECT * FROM venue")
venues = src_cur.fetchall()
venue_map = {} # old_id -> new_id
for v in venues:
new_venue = Venue(
name=v['name'],
city=v['city'],
state=v['state'],
country=v['country']
)
session.add(new_venue)
session.commit()
session.refresh(new_venue)
venue_map[v['id']] = new_venue.id
print(f"✓ Migrated {len(venues)} venues")
# 4. Migrate Tours
print("Migrating Tours...")
src_cur.execute("SELECT * FROM tour")
tours = src_cur.fetchall()
tour_map = {}
for t in tours:
# Handle date parsing if needed, assuming strings in sqlite
start_date = datetime.strptime(t['start_date'], '%Y-%m-%d %H:%M:%S') if t['start_date'] else None
end_date = datetime.strptime(t['end_date'], '%Y-%m-%d %H:%M:%S') if t['end_date'] else None
new_tour = Tour(
name=t['name'],
start_date=start_date,
end_date=end_date
)
session.add(new_tour)
session.commit()
session.refresh(new_tour)
tour_map[t['id']] = new_tour.id
print(f"✓ Migrated {len(tours)} tours")
# 5. Migrate Songs
print("Migrating Songs...")
src_cur.execute("SELECT * FROM song")
songs = src_cur.fetchall()
song_map = {}
for s in songs:
new_song = Song(
title=s['name'], # Map 'name' to 'title'
original_artist=s['original_artist'],
vertical_id=vertical.id
)
session.add(new_song)
session.commit()
session.refresh(new_song)
song_map[s['id']] = new_song.id
print(f"✓ Migrated {len(songs)} songs")
# 6. Migrate Shows
print("Migrating Shows...")
src_cur.execute("SELECT * FROM show")
shows = src_cur.fetchall()
show_map = {}
for s in shows:
show_date = datetime.strptime(s['date'], '%Y-%m-%d %H:%M:%S') if s['date'] else None
new_show = Show(
date=show_date,
vertical_id=vertical.id,
venue_id=venue_map.get(s['venue_id']),
tour_id=tour_map.get(s['tour_id']),
notes=s['notes']
)
session.add(new_show)
session.commit()
session.refresh(new_show)
show_map[s['id']] = new_show.id
print(f"✓ Migrated {len(shows)} shows")
# 7. Migrate Performances
print("Migrating Performances...")
src_cur.execute("SELECT * FROM songperformance")
perfs = src_cur.fetchall()
for p in perfs:
# Skip if show or song missing (data integrity)
if p['show_id'] not in show_map or p['song_id'] not in song_map:
continue
new_perf = Performance(
show_id=show_map[p['show_id']],
song_id=song_map[p['song_id']],
position=p['position'],
set_name=p['set_name'],
segue=bool(p['segue']),
notes=p['notes']
)
session.add(new_perf)
session.commit()
print(f"✓ Migrated {len(perfs)} performances")
src_conn.close()
print("=" * 60)
print("✓ MIGRATION COMPLETE")
print("=" * 60)
if __name__ == "__main__":
migrate_data()

View file

@ -0,0 +1,288 @@
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from sqlmodel import Session, select
from database import engine
from models import Venue, Song, Show, Tour, Performance
from slugify import generate_slug, generate_show_slug
import requests
import time
BASE_URL = "https://elgoose.net/api/v2"
def fetch_all_json(endpoint, params=None):
all_data = []
page = 1
params = params.copy() if params else {}
print(f"Fetching {endpoint}...")
seen_ids = set()
while True:
params['page'] = page
url = f"{BASE_URL}/{endpoint}.json"
try:
resp = requests.get(url, params=params)
if resp.status_code != 200:
print(f" Failed with status {resp.status_code}")
break
# API can return a dict with 'data' or just a list sometimes, handling both
json_resp = resp.json()
if isinstance(json_resp, dict):
items = json_resp.get('data', [])
elif isinstance(json_resp, list):
items = json_resp
else:
items = []
if not items:
print(" No more items found.")
break
# Check for cycles / infinite loop by checking if we've seen these IDs before
# Assuming items have 'id' or 'show_id' etc.
# If not, we hash the string representation.
new_items_count = 0
for item in items:
# Try to find a unique identifier
uid = item.get('id') or item.get('show_id') or str(item)
if uid not in seen_ids:
seen_ids.add(uid)
all_data.append(item)
new_items_count += 1
if new_items_count == 0:
print(f" Page {page} returned {len(items)} items but all were duplicates. Stopping.")
break
print(f" Page {page} done ({new_items_count} new items)")
page += 1
time.sleep(0.5)
# Safety break
if page > 1000:
print(" Hit 1000 pages safety limit.")
break
if page > 200: # Safety break
print(" Safety limit reached.")
break
except Exception as e:
print(f"Error fetching {endpoint}: {e}")
break
return all_data
def fix_data():
with Session(engine) as session:
# 1. Fix Venues Slugs
print("Fixing Venue Slugs...")
venues = session.exec(select(Venue)).all()
existing_venue_slugs = {v.slug for v in venues if v.slug}
for v in venues:
if not v.slug:
new_slug = generate_slug(v.name)
# Ensure unique
original_slug = new_slug
counter = 1
while new_slug in existing_venue_slugs:
counter += 1
new_slug = f"{original_slug}-{counter}"
v.slug = new_slug
existing_venue_slugs.add(new_slug)
session.add(v)
session.commit()
# 2. Fix Songs Slugs
print("Fixing Song Slugs...")
songs = session.exec(select(Song)).all()
existing_song_slugs = {s.slug for s in songs if s.slug}
for s in songs:
if not s.slug:
new_slug = generate_slug(s.title)
original_slug = new_slug
counter = 1
while new_slug in existing_song_slugs:
counter += 1
new_slug = f"{original_slug}-{counter}"
s.slug = new_slug
existing_song_slugs.add(new_slug)
session.add(s)
session.commit()
# 3. Fix Tours Slugs
print("Fixing Tour Slugs...")
tours = session.exec(select(Tour)).all()
existing_tour_slugs = {t.slug for t in tours if t.slug}
for t in tours:
if not t.slug:
new_slug = generate_slug(t.name)
original_slug = new_slug
counter = 1
while new_slug in existing_tour_slugs:
counter += 1
new_slug = f"{original_slug}-{counter}"
t.slug = new_slug
existing_tour_slugs.add(new_slug)
session.add(t)
session.commit()
# 4. Fix Shows Slugs
print("Fixing Show Slugs...")
shows = session.exec(select(Show)).all()
existing_show_slugs = {s.slug for s in shows if s.slug}
venue_map = {v.id: v for v in venues} # Cache venues for naming
for show in shows:
if not show.slug:
date_str = show.date.strftime("%Y-%m-%d") if show.date else "unknown"
venue_name = "unknown"
if show.venue_id and show.venue_id in venue_map:
venue_name = venue_map[show.venue_id].name
new_slug = generate_show_slug(date_str, venue_name)
# Ensure unique
original_slug = new_slug
counter = 1
while new_slug in existing_show_slugs:
counter += 1
new_slug = f"{original_slug}-{counter}"
show.slug = new_slug
existing_show_slugs.add(new_slug)
session.add(show)
session.commit()
# 4b. Fix Performance Slugs
print("Fixing Performance Slugs...")
from slugify import generate_performance_slug
perfs = session.exec(select(Performance)).all()
existing_perf_slugs = {p.slug for p in perfs if p.slug}
# We need song titles and show dates
# Efficient way: build maps
song_map = {s.id: s.title for s in songs}
show_map = {s.id: s.date.strftime("%Y-%m-%d") for s in shows}
for p in perfs:
if not p.slug:
song_title = song_map.get(p.song_id, "unknown")
show_date = show_map.get(p.show_id, "unknown")
new_slug = generate_performance_slug(song_title, show_date)
# Ensure unique (for reprises etc)
original_slug = new_slug
counter = 1
while new_slug in existing_perf_slugs:
counter += 1
new_slug = f"{original_slug}-{counter}"
p.slug = new_slug
existing_perf_slugs.add(new_slug)
session.add(p)
session.commit()
# 5. Fix Set Names (Fetch API)
print("Fixing Set Names (fetching setlists)...")
# We need to map El Goose show_id/song_id to our IDs to find the record.
# But we don't store El Goose IDs in our models?
# Checked models.py: we don't store ex_id.
# We match by show date/venue and song title.
# This is hard to do reliably without external IDs.
# Alternatively, we can infer set name from 'position'?
# No, position 1 could be Set 1 or Encore if short show? No.
# Wait, import_elgoose mappings are local var.
# If we re-run import logic but UPDATE instead of SKIP, we can fix it.
# But matching is tricky.
# Let's try to match by Show Date and Song Title.
# Build map: (show_id, song_id, position) -> Performance
# Refresh perfs from DB since we might have added slugs
# perfs = session.exec(select(Performance)).all() # Already have them, but maybe stale?
# Re-querying is safer but PERFS list object is updated by session.add? Yes.
perf_map = {} # (show_id, song_id, position) -> perf object
for p in perfs:
perf_map[(p.show_id, p.song_id, p.position)] = p
# We need show map: el_goose_show_id -> our_show_id
# We need song map: el_goose_song_id -> our_song_id
# We have to re-fetch shows and songs to rebuild this map.
print(" Re-building ID maps...")
# Map Shows
el_shows = fetch_all_json("shows", {"artist": 1})
if not el_shows: el_shows = fetch_all_json("shows") # fallback
el_show_map = {} # el_id -> our_id
for s in el_shows:
# Find our show
dt = s['showdate'] # YYYY-MM-DD
# We need to match precise Show.
# Simplified: match by date.
# Convert string to datetime
from datetime import datetime
s_date = datetime.strptime(dt, "%Y-%m-%d")
# Find show in our DB
# We can optimise this but for now linear search or query is fine for one-off script
found = session.exec(select(Show).where(Show.date == s_date)).first()
if found:
el_show_map[s['show_id']] = found.id
# Map Songs
el_songs = fetch_all_json("songs")
el_song_map = {} # el_id -> our_id
for s in el_songs:
found = session.exec(select(Song).where(Song.title == s['name'])).first()
if found:
el_song_map[s['id']] = found.id
# Now fetch setlists
el_setlists = fetch_all_json("setlists")
count = 0
for item in el_setlists:
our_show_id = el_show_map.get(item['show_id'])
our_song_id = el_song_map.get(item['song_id'])
position = item.get('position', 0)
if our_show_id and our_song_id:
# Find existing perf
perf = perf_map.get((our_show_id, our_song_id, position))
if perf:
# Logic to fix set_name
set_val = str(item.get('setnumber', '1'))
set_name = f"Set {set_val}"
if set_val.isdigit():
set_name = f"Set {set_val}"
elif set_val.lower() == 'e':
set_name = "Encore"
elif set_val.lower() == 'e2':
set_name = "Encore 2"
elif set_val.lower() == 's':
set_name = "Soundcheck"
if perf.set_name != set_name:
perf.set_name = set_name
session.add(perf)
count += 1
else:
# Debug only first few failures to avoid spam
if count < 5:
print(f"Match failed for el_show_id={item.get('show_id')} el_song_id={item.get('song_id')}")
if not our_show_id: print(f" -> Show ID not found in map (Map size: {len(el_show_map)})")
if not our_song_id: print(f" -> Song ID not found in map (Map size: {len(el_song_map)})")
session.commit()
print(f"Fixed {count} performance set names.")
if __name__ == "__main__":
fix_data()

View file

@ -0,0 +1,34 @@
"""
Migration to add email verification and password reset columns to user table.
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from sqlmodel import Session, create_engine, text
from database import DATABASE_URL
def add_email_verification_columns():
engine = create_engine(DATABASE_URL)
columns = [
('email_verified', 'BOOLEAN DEFAULT FALSE'),
('verification_token', 'VARCHAR'),
('verification_token_expires', 'TIMESTAMP'),
('reset_token', 'VARCHAR'),
('reset_token_expires', 'TIMESTAMP'),
]
with Session(engine) as session:
for col_name, col_type in columns:
try:
session.exec(text(f"""
ALTER TABLE "user" ADD COLUMN IF NOT EXISTS {col_name} {col_type}
"""))
session.commit()
print(f"✅ Added {col_name} to user")
except Exception as e:
print(f"⚠️ {col_name}: {e}")
if __name__ == "__main__":
add_email_verification_columns()

View file

@ -0,0 +1,35 @@
import os
from sqlmodel import create_engine, text
# Get DB URL from env or default (adjust for production)
DATABASE_URL = os.environ.get("DATABASE_URL", "postgresql://elmeg:runfoo@localhost/elmeg")
engine = create_engine(DATABASE_URL)
def run_migration():
with engine.connect() as conn:
print("Adding columns to Show table...")
try:
conn.execute(text("ALTER TABLE show ADD COLUMN bandcamp_link VARCHAR"))
print("Added bandcamp_link")
except Exception as e:
print(f"Skipping bandcamp_link (already exists?)")
try:
conn.execute(text("ALTER TABLE show ADD COLUMN nugs_link VARCHAR"))
print("Added nugs_link")
except Exception as e:
print(f"Skipping nugs_link (already exists?)")
print("Adding columns to Performance table...")
try:
conn.execute(text("ALTER TABLE performance ADD COLUMN track_url VARCHAR"))
print("Added track_url")
except Exception as e:
print(f"Skipping track_url (already exists?)")
conn.commit()
print("Migration complete.")
if __name__ == "__main__":
run_migration()

View file

@ -0,0 +1,15 @@
from sqlmodel import Session, create_engine, text
from database import DATABASE_URL
def add_column():
engine = create_engine(DATABASE_URL)
with Session(engine) as session:
try:
session.exec(text("ALTER TABLE comment ADD COLUMN parent_id INTEGER REFERENCES comment(id)"))
session.commit()
print("Successfully added parent_id column to comment table")
except Exception as e:
print(f"Error adding column (might already exist): {e}")
if __name__ == "__main__":
add_column()

View file

@ -0,0 +1,43 @@
"""Add venue_id and tour_id columns to rating table"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from database import DATABASE_URL
import psycopg2
def run():
conn = psycopg2.connect(DATABASE_URL)
cur = conn.cursor()
# Add venue_id column
try:
cur.execute("ALTER TABLE rating ADD COLUMN venue_id INTEGER REFERENCES venue(id)")
print("✅ Added venue_id to rating")
except Exception as e:
if "already exists" in str(e):
print("⚠️ venue_id column already exists")
else:
print(f"❌ Error adding venue_id: {e}")
conn.rollback()
else:
conn.commit()
# Add tour_id column
try:
cur.execute("ALTER TABLE rating ADD COLUMN tour_id INTEGER REFERENCES tour(id)")
print("✅ Added tour_id to rating")
except Exception as e:
if "already exists" in str(e):
print("⚠️ tour_id column already exists")
else:
print(f"❌ Error adding tour_id: {e}")
conn.rollback()
else:
conn.commit()
cur.close()
conn.close()
if __name__ == "__main__":
run()

View file

@ -0,0 +1,26 @@
from sqlmodel import Session, create_engine, text
from database import DATABASE_URL
def add_reaction_table():
engine = create_engine(DATABASE_URL)
with Session(engine) as session:
try:
session.exec(text("""
CREATE TABLE IF NOT EXISTS reaction (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES "user"(id),
entity_type VARCHAR NOT NULL,
entity_id INTEGER NOT NULL,
emoji VARCHAR NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
"""))
session.exec(text("CREATE INDEX IF NOT EXISTS ix_reaction_entity_type ON reaction (entity_type)"))
session.exec(text("CREATE INDEX IF NOT EXISTS ix_reaction_entity_id ON reaction (entity_id)"))
session.commit()
print("Successfully created reaction table")
except Exception as e:
print(f"Error creating table: {e}")
if __name__ == "__main__":
add_reaction_table()

View file

@ -0,0 +1,225 @@
"""
Migration script to add slug columns and generate slugs for existing data
"""
import os
import sys
# Add parent directory (backend/) to path for imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from sqlmodel import create_engine, Session, select, text
from slugify import generate_slug, generate_show_slug, generate_performance_slug
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://elmeg:elmeg@localhost/elmeg")
engine = create_engine(DATABASE_URL)
def add_slug_columns():
"""Add slug columns to tables if they don't exist"""
with engine.connect() as conn:
# Add slug to song
conn.execute(text("ALTER TABLE song ADD COLUMN IF NOT EXISTS slug VARCHAR UNIQUE"))
conn.execute(text("CREATE INDEX IF NOT EXISTS ix_song_slug ON song(slug)"))
# Add slug to venue
conn.execute(text("ALTER TABLE venue ADD COLUMN IF NOT EXISTS slug VARCHAR UNIQUE"))
conn.execute(text("CREATE INDEX IF NOT EXISTS ix_venue_slug ON venue(slug)"))
# Add slug to show
conn.execute(text("ALTER TABLE show ADD COLUMN IF NOT EXISTS slug VARCHAR UNIQUE"))
conn.execute(text("CREATE INDEX IF NOT EXISTS ix_show_slug ON show(slug)"))
# Add slug to tour
conn.execute(text("ALTER TABLE tour ADD COLUMN IF NOT EXISTS slug VARCHAR UNIQUE"))
conn.execute(text("CREATE INDEX IF NOT EXISTS ix_tour_slug ON tour(slug)"))
# Add slug to performance
conn.execute(text("ALTER TABLE performance ADD COLUMN IF NOT EXISTS slug VARCHAR UNIQUE"))
conn.execute(text("CREATE INDEX IF NOT EXISTS ix_performance_slug ON performance(slug)"))
conn.commit()
print("✓ Slug columns added")
def generate_song_slugs():
"""Generate slugs for all songs"""
with Session(engine) as session:
# Get all songs without slugs
result = session.exec(text("SELECT id, title FROM song WHERE slug IS NULL"))
songs = result.fetchall()
existing_slugs = set()
# Get existing slugs
existing = session.exec(text("SELECT slug FROM song WHERE slug IS NOT NULL"))
for row in existing.fetchall():
existing_slugs.add(row[0])
count = 0
for song_id, title in songs:
base_slug = generate_slug(title, 50)
slug = base_slug
counter = 2
while slug in existing_slugs:
slug = f"{base_slug}-{counter}"
counter += 1
existing_slugs.add(slug)
session.execute(
text("UPDATE song SET slug = :slug WHERE id = :id"),
{"slug": slug, "id": song_id}
)
count += 1
session.commit()
print(f"✓ Generated slugs for {count} songs")
def generate_venue_slugs():
"""Generate slugs for all venues"""
with Session(engine) as session:
result = session.exec(text("SELECT id, name, city FROM venue WHERE slug IS NULL"))
venues = result.fetchall()
existing_slugs = set()
existing = session.exec(text("SELECT slug FROM venue WHERE slug IS NOT NULL"))
for row in existing.fetchall():
existing_slugs.add(row[0])
count = 0
for venue_id, name, city in venues:
# Include city to help disambiguate
base_slug = generate_slug(f"{name} {city}", 60)
slug = base_slug
counter = 2
while slug in existing_slugs:
slug = f"{base_slug}-{counter}"
counter += 1
existing_slugs.add(slug)
session.execute(
text("UPDATE venue SET slug = :slug WHERE id = :id"),
{"slug": slug, "id": venue_id}
)
count += 1
session.commit()
print(f"✓ Generated slugs for {count} venues")
def generate_show_slugs():
"""Generate slugs for all shows"""
with Session(engine) as session:
result = session.exec(text("""
SELECT s.id, s.date, v.name
FROM show s
LEFT JOIN venue v ON s.venue_id = v.id
WHERE s.slug IS NULL
"""))
shows = result.fetchall()
existing_slugs = set()
existing = session.exec(text("SELECT slug FROM show WHERE slug IS NOT NULL"))
for row in existing.fetchall():
existing_slugs.add(row[0])
count = 0
for show_id, date, venue_name in shows:
date_str = date.strftime("%Y-%m-%d") if date else "unknown"
venue_slug = generate_slug(venue_name or "unknown", 25)
base_slug = f"{date_str}-{venue_slug}"
slug = base_slug
counter = 2
while slug in existing_slugs:
slug = f"{base_slug}-{counter}"
counter += 1
existing_slugs.add(slug)
session.execute(
text("UPDATE show SET slug = :slug WHERE id = :id"),
{"slug": slug, "id": show_id}
)
count += 1
session.commit()
print(f"✓ Generated slugs for {count} shows")
def generate_tour_slugs():
"""Generate slugs for all tours"""
with Session(engine) as session:
result = session.exec(text("SELECT id, name FROM tour WHERE slug IS NULL"))
tours = result.fetchall()
existing_slugs = set()
existing = session.exec(text("SELECT slug FROM tour WHERE slug IS NOT NULL"))
for row in existing.fetchall():
existing_slugs.add(row[0])
count = 0
for tour_id, name in tours:
base_slug = generate_slug(name, 50)
slug = base_slug
counter = 2
while slug in existing_slugs:
slug = f"{base_slug}-{counter}"
counter += 1
existing_slugs.add(slug)
session.execute(
text("UPDATE tour SET slug = :slug WHERE id = :id"),
{"slug": slug, "id": tour_id}
)
count += 1
session.commit()
print(f"✓ Generated slugs for {count} tours")
def generate_performance_slugs():
"""Generate slugs for all performances (songslug-date format)"""
with Session(engine) as session:
result = session.exec(text("""
SELECT p.id, s.slug as song_slug, sh.date
FROM performance p
JOIN song s ON p.song_id = s.id
JOIN show sh ON p.show_id = sh.id
WHERE p.slug IS NULL
"""))
performances = result.fetchall()
existing_slugs = set()
existing = session.exec(text("SELECT slug FROM performance WHERE slug IS NOT NULL"))
for row in existing.fetchall():
existing_slugs.add(row[0])
count = 0
for perf_id, song_slug, date in performances:
date_str = date.strftime("%Y-%m-%d") if date else "unknown"
base_slug = f"{song_slug}-{date_str}"
slug = base_slug
counter = 2
# Handle multiple performances of same song in same show
while slug in existing_slugs:
slug = f"{base_slug}-{counter}"
counter += 1
existing_slugs.add(slug)
session.execute(
text("UPDATE performance SET slug = :slug WHERE id = :id"),
{"slug": slug, "id": perf_id}
)
count += 1
session.commit()
print(f"✓ Generated slugs for {count} performances")
def run_migration():
print("=== Running Slug Migration ===")
add_slug_columns()
generate_song_slugs()
generate_venue_slugs()
generate_tour_slugs()
generate_show_slugs()
generate_performance_slugs() # Must run after song slugs
print("=== Migration Complete ===")
if __name__ == "__main__":
run_migration()

View file

@ -0,0 +1,28 @@
"""
Migration to add youtube_link column to show, song, and performance tables.
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from sqlmodel import Session, create_engine, text
from database import DATABASE_URL
def add_youtube_link_columns():
engine = create_engine(DATABASE_URL)
tables = ['show', 'song', 'performance']
with Session(engine) as session:
for table in tables:
try:
session.exec(text(f"""
ALTER TABLE "{table}" ADD COLUMN IF NOT EXISTS youtube_link VARCHAR
"""))
session.commit()
print(f"✅ Added youtube_link to {table}")
except Exception as e:
print(f"⚠️ {table}: {e}")
if __name__ == "__main__":
add_youtube_link_columns()

View file

@ -0,0 +1,85 @@
"""
Migration script to refactor Artists and link Songs.
1. Add new columns to Artist (slug, bio, image_url).
2. Add artist_id to Song.
3. Migrate 'original_artist' string to Artist records.
"""
from sqlmodel import Session, select, text
from database import engine
from models import Artist, Song
from slugify import generate_slug as slugify
def migrate_artists():
with Session(engine) as session:
print("Running Artist & Covers Migration...")
# 1. Schema Changes (Idempotent ALTER TABLE)
# Artist columns
try:
session.exec(text("ALTER TABLE artist ADD COLUMN slug VARCHAR UNIQUE"))
print("Added artist.slug")
except Exception as e:
print("artist.slug already exists or error:", e)
session.rollback()
try:
session.exec(text("ALTER TABLE artist ADD COLUMN bio VARCHAR"))
print("Added artist.bio")
except Exception as e:
session.rollback()
try:
session.exec(text("ALTER TABLE artist ADD COLUMN image_url VARCHAR"))
print("Added artist.image_url")
except Exception as e:
session.rollback()
# Song artist_id
try:
session.exec(text("ALTER TABLE song ADD COLUMN artist_id INTEGER REFERENCES artist(id)"))
print("Added song.artist_id")
except Exception as e:
print("song.artist_id already exists or error:", e)
session.rollback()
session.commit()
# 2. Data Migration
songs = session.exec(select(Song).where(Song.original_artist != None)).all()
print(f"Found {len(songs)} songs with original_artist string.")
created_count = 0
linked_count = 0
for song in songs:
if not song.original_artist or song.artist_id:
continue
artist_name = song.original_artist.strip()
if not artist_name:
continue
# Clean up name (e.g., "The Beatles" vs "Beatles")
# For now, just trust the string but ensure consistent slug
artist_slug = slugify(artist_name)
# Find or Create Artist
artist = session.exec(select(Artist).where(Artist.slug == artist_slug)).first()
if not artist:
artist = Artist(name=artist_name, slug=artist_slug)
session.add(artist)
session.commit()
session.refresh(artist)
created_count += 1
print(f"Created Artist: {artist_name} ({artist_slug})")
# Link Song
song.artist_id = artist.id
session.add(song)
linked_count += 1
session.commit()
print(f"Migration Complete: Created {created_count} artists, linked {linked_count} songs.")
if __name__ == "__main__":
migrate_artists()

View file

@ -0,0 +1,69 @@
"""
Migration script to create Musician, BandMembership, and PerformanceGuest tables.
"""
from sqlmodel import Session, text
from database import engine
def migrate_musicians():
with Session(engine) as session:
print("Running Musicians Migration...")
# Create Musician table
try:
session.exec(text("""
CREATE TABLE IF NOT EXISTS musician (
id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL,
slug VARCHAR UNIQUE NOT NULL,
bio TEXT,
image_url VARCHAR,
primary_instrument VARCHAR,
notes TEXT
)
"""))
session.exec(text("CREATE INDEX IF NOT EXISTS idx_musician_name ON musician(name)"))
session.exec(text("CREATE INDEX IF NOT EXISTS idx_musician_slug ON musician(slug)"))
print("Created musician table")
except Exception as e:
print(f"musician table error: {e}")
session.rollback()
# Create BandMembership table
try:
session.exec(text("""
CREATE TABLE IF NOT EXISTS bandmembership (
id SERIAL PRIMARY KEY,
musician_id INTEGER NOT NULL REFERENCES musician(id),
artist_id INTEGER NOT NULL REFERENCES artist(id),
role VARCHAR,
start_date TIMESTAMP,
end_date TIMESTAMP,
notes TEXT
)
"""))
print("Created bandmembership table")
except Exception as e:
print(f"bandmembership table error: {e}")
session.rollback()
# Create PerformanceGuest table
try:
session.exec(text("""
CREATE TABLE IF NOT EXISTS performanceguest (
id SERIAL PRIMARY KEY,
performance_id INTEGER NOT NULL REFERENCES performance(id),
musician_id INTEGER NOT NULL REFERENCES musician(id),
instrument VARCHAR,
notes TEXT
)
"""))
print("Created performanceguest table")
except Exception as e:
print(f"performanceguest table error: {e}")
session.rollback()
session.commit()
print("Musicians Migration Complete!")
if __name__ == "__main__":
migrate_musicians()

427
backend/models.py Normal file
View file

@ -0,0 +1,427 @@
from typing import List, Optional
from sqlmodel import Field, Relationship, SQLModel
from datetime import datetime
# --- Join Tables ---
class Performance(SQLModel, table=True):
"""Link table between Show and Song (Many-to-Many with extra data)"""
id: Optional[int] = Field(default=None, primary_key=True)
slug: Optional[str] = Field(default=None, unique=True, index=True, description="songslug-YYYY-MM-DD")
show_id: int = Field(foreign_key="show.id")
song_id: int = Field(foreign_key="song.id")
position: int = Field(description="Order in the setlist")
set_name: Optional[str] = Field(default=None, description="e.g., Set 1, Encore")
segue: bool = Field(default=False, description="Transition to next song >")
notes: Optional[str] = Field(default=None)
track_url: Optional[str] = Field(default=None, description="Deep link to track audio")
youtube_link: Optional[str] = Field(default=None, description="YouTube video URL")
bandcamp_link: Optional[str] = Field(default=None, description="Bandcamp track URL")
nugs_link: Optional[str] = Field(default=None, description="Nugs.net track URL")
nicknames: List["PerformanceNickname"] = Relationship(back_populates="performance")
show: "Show" = Relationship(back_populates="performances")
song: "Song" = Relationship()
class ShowArtist(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
show_id: int = Field(foreign_key="show.id")
artist_id: int = Field(foreign_key="artist.id")
notes: Optional[str] = Field(default=None, description="Role e.g. Guest")
class PerformanceArtist(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
performance_id: int = Field(foreign_key="performance.id")
artist_id: int = Field(foreign_key="artist.id")
notes: Optional[str] = Field(default=None, description="Role e.g. Guest")
class PerformanceNickname(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
performance_id: int = Field(foreign_key="performance.id")
nickname: str = Field(index=True)
description: Optional[str] = Field(default=None)
status: str = Field(default="pending", index=True) # pending, approved, rejected
suggested_by: int = Field(foreign_key="user.id")
created_at: datetime = Field(default_factory=datetime.utcnow)
performance: "Performance" = Relationship(back_populates="nicknames")
user: "User" = Relationship()
class EntityTag(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
tag_id: int = Field(foreign_key="tag.id")
entity_type: str = Field(index=True) # "show", "song", "venue"
entity_id: int = Field(index=True)
# --- Core Entities ---
class Vertical(SQLModel, table=True):
"""Represents a Fandom Vertical (e.g., 'Phish', 'Goose', 'Star Wars')"""
id: Optional[int] = Field(default=None, primary_key=True)
name: str = Field(index=True)
slug: str = Field(unique=True, index=True)
description: Optional[str] = Field(default=None)
shows: List["Show"] = Relationship(back_populates="vertical")
songs: List["Song"] = Relationship(back_populates="vertical")
class Venue(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
name: str = Field(index=True)
slug: Optional[str] = Field(default=None, unique=True, index=True)
city: str
state: Optional[str] = Field(default=None)
country: str
capacity: Optional[int] = Field(default=None)
notes: Optional[str] = Field(default=None)
shows: List["Show"] = Relationship(back_populates="venue")
class Tour(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
name: str = Field(index=True)
slug: Optional[str] = Field(default=None, unique=True, index=True)
start_date: Optional[datetime] = None
end_date: Optional[datetime] = None
notes: Optional[str] = Field(default=None)
shows: List["Show"] = Relationship(back_populates="tour")
class Artist(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
name: str = Field(index=True)
slug: str = Field(unique=True, index=True)
bio: Optional[str] = Field(default=None)
image_url: Optional[str] = Field(default=None)
instrument: Optional[str] = Field(default=None)
notes: Optional[str] = Field(default=None)
songs: List["Song"] = Relationship(back_populates="artist")
class Musician(SQLModel, table=True):
"""Individual human musicians (for tracking sit-ins and band membership)"""
id: Optional[int] = Field(default=None, primary_key=True)
name: str = Field(index=True)
slug: str = Field(unique=True, index=True)
bio: Optional[str] = Field(default=None)
image_url: Optional[str] = Field(default=None)
primary_instrument: Optional[str] = Field(default=None)
notes: Optional[str] = Field(default=None)
# Relationships
memberships: List["BandMembership"] = Relationship(back_populates="musician")
guest_appearances: List["PerformanceGuest"] = Relationship(back_populates="musician")
class BandMembership(SQLModel, table=True):
"""Link between Musician and Band/Artist with role and dates"""
id: Optional[int] = Field(default=None, primary_key=True)
musician_id: int = Field(foreign_key="musician.id")
artist_id: int = Field(foreign_key="artist.id", description="The band/group")
role: Optional[str] = Field(default=None, description="e.g., Keyboards, Rhythm Guitar")
start_date: Optional[datetime] = Field(default=None)
end_date: Optional[datetime] = Field(default=None, description="Null = current member")
notes: Optional[str] = Field(default=None)
musician: Musician = Relationship(back_populates="memberships")
artist: Artist = Relationship()
class PerformanceGuest(SQLModel, table=True):
"""Link between Performance and Musician for sit-ins/guest appearances"""
id: Optional[int] = Field(default=None, primary_key=True)
performance_id: int = Field(foreign_key="performance.id")
musician_id: int = Field(foreign_key="musician.id")
instrument: Optional[str] = Field(default=None, description="What they played on this track")
notes: Optional[str] = Field(default=None)
musician: Musician = Relationship(back_populates="guest_appearances")
class Show(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
date: datetime = Field(index=True)
slug: Optional[str] = Field(default=None, unique=True, index=True)
vertical_id: int = Field(foreign_key="vertical.id")
venue_id: Optional[int] = Field(default=None, foreign_key="venue.id")
tour_id: Optional[int] = Field(default=None, foreign_key="tour.id")
notes: Optional[str] = Field(default=None)
# External Links
bandcamp_link: Optional[str] = Field(default=None)
nugs_link: Optional[str] = Field(default=None)
youtube_link: Optional[str] = Field(default=None)
vertical: Vertical = Relationship(back_populates="shows")
venue: Optional[Venue] = Relationship(back_populates="shows")
tour: Optional[Tour] = Relationship(back_populates="shows")
attendances: List["Attendance"] = Relationship(back_populates="show")
performances: List["Performance"] = Relationship(back_populates="show")
class Song(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
title: str = Field(index=True)
slug: Optional[str] = Field(default=None, unique=True, index=True)
original_artist: Optional[str] = Field(default=None)
vertical_id: int = Field(foreign_key="vertical.id")
notes: Optional[str] = Field(default=None)
youtube_link: Optional[str] = Field(default=None)
# New Relation
artist_id: Optional[int] = Field(default=None, foreign_key="artist.id")
artist: Optional[Artist] = Relationship(back_populates="songs")
vertical: Vertical = Relationship(back_populates="songs")
class Sequence(SQLModel, table=True):
"""Named groupings of consecutive songs, e.g. 'Autumn Crossing' = Travelers > Elmeg the Wise"""
id: Optional[int] = Field(default=None, primary_key=True)
name: str = Field(index=True, description="Human-readable name like 'Autumn Crossing'")
slug: str = Field(unique=True, index=True)
description: Optional[str] = Field(default=None)
notes: Optional[str] = Field(default=None)
# Relationship to songs that make up this sequence
songs: List["SequenceSong"] = Relationship(back_populates="sequence")
class SequenceSong(SQLModel, table=True):
"""Join table linking songs to sequences with ordering"""
id: Optional[int] = Field(default=None, primary_key=True)
sequence_id: int = Field(foreign_key="sequence.id")
song_id: int = Field(foreign_key="song.id")
position: int = Field(description="Order in sequence, 1-indexed")
sequence: Sequence = Relationship(back_populates="songs")
class Tag(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
name: str = Field(unique=True, index=True)
slug: str = Field(unique=True, index=True)
class Attendance(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
user_id: int = Field(foreign_key="user.id")
show_id: int = Field(foreign_key="show.id")
notes: Optional[str] = Field(default=None)
created_at: datetime = Field(default_factory=datetime.utcnow)
user: "User" = Relationship(back_populates="attendances")
show: "Show" = Relationship(back_populates="attendances")
class Comment(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
user_id: int = Field(foreign_key="user.id")
content: str
created_at: datetime = Field(default_factory=datetime.utcnow)
# Polymorphic-ish associations (nullable FKs)
show_id: Optional[int] = Field(default=None, foreign_key="show.id")
venue_id: Optional[int] = Field(default=None, foreign_key="venue.id")
song_id: Optional[int] = Field(default=None, foreign_key="song.id")
parent_id: Optional[int] = Field(default=None, foreign_key="comment.id")
user: "User" = Relationship(back_populates="comments")
class Rating(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
user_id: int = Field(foreign_key="user.id")
score: float = Field(ge=1.0, le=10.0, description="Rating from 1.0 to 10.0")
created_at: datetime = Field(default_factory=datetime.utcnow)
show_id: Optional[int] = Field(default=None, foreign_key="show.id")
song_id: Optional[int] = Field(default=None, foreign_key="song.id")
performance_id: Optional[int] = Field(default=None, foreign_key="performance.id")
venue_id: Optional[int] = Field(default=None, foreign_key="venue.id")
tour_id: Optional[int] = Field(default=None, foreign_key="tour.id")
user: "User" = Relationship(back_populates="ratings")
class User(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
email: str = Field(unique=True, index=True)
hashed_password: str
is_active: bool = Field(default=True)
is_superuser: bool = Field(default=False)
role: str = Field(default="user") # user, moderator, admin
bio: Optional[str] = Field(default=None)
avatar: Optional[str] = Field(default=None)
avatar_bg_color: Optional[str] = Field(default="#3B82F6", description="Hex color for avatar background")
avatar_text: Optional[str] = Field(default=None, description="1-3 character text overlay on avatar")
# Privacy settings
profile_public: bool = Field(default=True, description="Allow others to view profile")
show_attendance_public: bool = Field(default=True, description="Show attended shows on profile")
appear_in_leaderboards: bool = Field(default=True, description="Appear in community leaderboards")
# Gamification
xp: int = Field(default=0, description="Experience points")
level: int = Field(default=1, description="User level based on XP")
streak_days: int = Field(default=0, description="Consecutive days active")
last_activity: Optional[datetime] = Field(default=None)
# Custom Titles & Flair (tracker forum style)
custom_title: Optional[str] = Field(default=None, description="Custom title chosen by user")
title_color: Optional[str] = Field(default=None, description="Hex color for username display")
flair: Optional[str] = Field(default=None, description="Small text/emoji beside name")
is_early_adopter: bool = Field(default=False, description="First 100 users get special perks")
is_supporter: bool = Field(default=False, description="Donated/supported the platform")
joined_at: datetime = Field(default_factory=datetime.utcnow)
# Email verification
email_verified: bool = Field(default=False)
verification_token: Optional[str] = Field(default=None)
verification_token_expires: Optional[datetime] = Field(default=None)
# Password reset
reset_token: Optional[str] = Field(default=None)
reset_token_expires: Optional[datetime] = Field(default=None)
# Multi-identity support: A user can have multiple Profiles
profiles: List["Profile"] = Relationship(back_populates="user")
comments: List["Comment"] = Relationship(back_populates="user")
ratings: List["Rating"] = Relationship(back_populates="user")
reviews: List["Review"] = Relationship(back_populates="user")
attendances: List["Attendance"] = Relationship(back_populates="user")
badges: List["UserBadge"] = Relationship(back_populates="user")
preferences: Optional["UserPreferences"] = Relationship(back_populates="user", sa_relationship_kwargs={"uselist": False})
reports: List["Report"] = Relationship(back_populates="user")
notifications: List["Notification"] = Relationship(back_populates="user")
class Report(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
user_id: int = Field(foreign_key="user.id")
entity_type: str = Field(index=True) # comment, review, nickname
entity_id: int = Field(index=True)
reason: str
details: str = Field(default="")
status: str = Field(default="pending", index=True) # pending, resolved, dismissed
created_at: datetime = Field(default_factory=datetime.utcnow)
user: "User" = Relationship(back_populates="reports")
class Badge(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
name: str = Field(unique=True, index=True)
description: str
icon: str = Field(description="Lucide icon name or image URL")
slug: str = Field(unique=True, index=True)
tier: str = Field(default="bronze", description="bronze, silver, gold, platinum, diamond")
category: str = Field(default="general", description="attendance, ratings, social, milestones")
xp_reward: int = Field(default=50, description="XP awarded when badge is earned")
class UserBadge(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
user_id: int = Field(foreign_key="user.id")
badge_id: int = Field(foreign_key="badge.id")
awarded_at: datetime = Field(default_factory=datetime.utcnow)
user: "User" = Relationship(back_populates="badges")
badge: "Badge" = Relationship()
class Review(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
user_id: int = Field(foreign_key="user.id")
blurb: str = Field(description="One-liner/pullquote")
content: str = Field(description="Full review text")
score: float = Field(ge=1.0, le=10.0)
show_id: Optional[int] = Field(default=None, foreign_key="show.id")
venue_id: Optional[int] = Field(default=None, foreign_key="venue.id")
song_id: Optional[int] = Field(default=None, foreign_key="song.id")
performance_id: Optional[int] = Field(default=None, foreign_key="performance.id")
tour_id: Optional[int] = Field(default=None, foreign_key="tour.id")
year: Optional[int] = Field(default=None, description="For reviewing a specific year")
created_at: datetime = Field(default_factory=datetime.utcnow)
user: "User" = Relationship(back_populates="reviews")
class UserPreferences(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
user_id: int = Field(foreign_key="user.id", unique=True)
wiki_mode: bool = Field(default=False, description="Disable social features")
show_ratings: bool = Field(default=True)
show_comments: bool = Field(default=True)
# Theme preference (synced from frontend)
theme: str = Field(default="system", description="light, dark, or system")
# Email notification preferences
email_on_reply: bool = Field(default=True, description="Email when someone replies to your review")
email_on_chase: bool = Field(default=True, description="Email when your chase song is played")
email_digest: bool = Field(default=False, description="Weekly digest email")
user: User = Relationship(back_populates="preferences")
class Profile(SQLModel, table=True):
"""A user's identity within a specific context or global"""
id: Optional[int] = Field(default=None, primary_key=True)
user_id: int = Field(foreign_key="user.id")
username: str = Field(index=True)
display_name: Optional[str] = Field(default=None)
user: User = Relationship(back_populates="profiles")
# --- Groups ---
class Group(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
name: str = Field(index=True, unique=True)
description: Optional[str] = None
privacy: str = Field(default="public") # public, private
created_by: int = Field(foreign_key="user.id")
created_at: datetime = Field(default_factory=datetime.utcnow)
members: List["GroupMember"] = Relationship(back_populates="group")
posts: List["GroupPost"] = Relationship(back_populates="group")
class GroupMember(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
group_id: int = Field(foreign_key="group.id")
user_id: int = Field(foreign_key="user.id")
role: str = Field(default="member") # member, admin
joined_at: datetime = Field(default_factory=datetime.utcnow)
group: Group = Relationship(back_populates="members")
user: User = Relationship()
class GroupPost(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
group_id: int = Field(foreign_key="group.id")
user_id: int = Field(foreign_key="user.id")
content: str
created_at: datetime = Field(default_factory=datetime.utcnow)
group: Group = Relationship(back_populates="posts")
user: User = Relationship()
class Notification(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
user_id: int = Field(foreign_key="user.id", index=True)
type: str = Field(description="reply, mention, system")
title: str
message: str
link: Optional[str] = None
is_read: bool = Field(default=False)
created_at: datetime = Field(default_factory=datetime.utcnow)
user: User = Relationship(back_populates="notifications")
class Reaction(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
user_id: int = Field(foreign_key="user.id")
entity_type: str = Field(index=True) # "review", "comment"
entity_id: int = Field(index=True)
emoji: str # "❤️", "🔥", etc.
created_at: datetime = Field(default_factory=datetime.utcnow)
user: User = Relationship()
class ChaseSong(SQLModel, table=True):
"""Songs a user wants to see live (hasn't seen performed yet or wants to see again)"""
id: Optional[int] = Field(default=None, primary_key=True)
user_id: int = Field(foreign_key="user.id", index=True)
song_id: int = Field(foreign_key="song.id", index=True)
priority: int = Field(default=1, description="1=high, 2=medium, 3=low")
notes: Optional[str] = Field(default=None)
created_at: datetime = Field(default_factory=datetime.utcnow)
caught_at: Optional[datetime] = Field(default=None, description="When they finally saw it")
caught_show_id: Optional[int] = Field(default=None, foreign_key="show.id")
user: User = Relationship()
song: "Song" = Relationship()

140
backend/models_tickets.py Normal file
View file

@ -0,0 +1,140 @@
"""
Bug Tracker Models - ISOLATED MODULE
No dependencies on main Elmeg models.
Can be removed by: deleting this file + routes file + removing router import from main.py
"""
from datetime import datetime
from typing import Optional, List
from sqlmodel import SQLModel, Field, Relationship
from enum import Enum
class TicketType(str, Enum):
BUG = "bug"
FEATURE = "feature"
QUESTION = "question"
OTHER = "other"
class TicketStatus(str, Enum):
OPEN = "open"
IN_PROGRESS = "in_progress"
RESOLVED = "resolved"
CLOSED = "closed"
class TicketPriority(str, Enum):
LOW = "low"
MEDIUM = "medium"
HIGH = "high"
CRITICAL = "critical"
class Ticket(SQLModel, table=True):
"""
Support ticket - fully decoupled from User model.
Stores reporter info as strings, not FKs.
"""
id: Optional[int] = Field(default=None, primary_key=True)
ticket_number: str = Field(unique=True, index=True) # ELM-001
type: TicketType = Field(default=TicketType.BUG)
status: TicketStatus = Field(default=TicketStatus.OPEN)
priority: TicketPriority = Field(default=TicketPriority.MEDIUM)
title: str = Field(max_length=200)
description: str = Field(default="")
# Reporter info - stored as strings, not FK
reporter_email: str = Field(index=True)
reporter_name: Optional[str] = None
reporter_user_id: Optional[int] = None # Reference only, not FK
# Assignment - stored as strings
assigned_to_email: Optional[str] = None
assigned_to_name: Optional[str] = None
is_public: bool = Field(default=False)
upvotes: int = Field(default=0)
# Environment info
browser: Optional[str] = None
os: Optional[str] = None
page_url: Optional[str] = None
created_at: datetime = Field(default_factory=datetime.utcnow)
updated_at: datetime = Field(default_factory=datetime.utcnow)
resolved_at: Optional[datetime] = None
# Relationships (within ticket system only)
comments: List["TicketComment"] = Relationship(back_populates="ticket")
class TicketComment(SQLModel, table=True):
"""Comment on a ticket - no FK to User"""
id: Optional[int] = Field(default=None, primary_key=True)
ticket_id: int = Field(foreign_key="ticket.id")
# Author info - stored as strings
author_email: str
author_name: str
author_user_id: Optional[int] = None # Reference only
content: str
is_internal: bool = Field(default=False) # Admin-only visibility
created_at: datetime = Field(default_factory=datetime.utcnow)
# Relationship
ticket: Optional[Ticket] = Relationship(back_populates="comments")
# ============ Schemas ============
class TicketCreate(SQLModel):
type: TicketType = TicketType.BUG
priority: TicketPriority = TicketPriority.MEDIUM
title: str
description: str = ""
reporter_email: Optional[str] = None
reporter_name: Optional[str] = None
browser: Optional[str] = None
os: Optional[str] = None
page_url: Optional[str] = None
class TicketUpdate(SQLModel):
status: Optional[TicketStatus] = None
priority: Optional[TicketPriority] = None
assigned_to_email: Optional[str] = None
assigned_to_name: Optional[str] = None
is_public: Optional[bool] = None
class TicketCommentCreate(SQLModel):
content: str
class TicketRead(SQLModel):
id: int
ticket_number: str
type: TicketType
status: TicketStatus
priority: TicketPriority
title: str
description: str
reporter_email: str
reporter_name: Optional[str]
is_public: bool
upvotes: int
created_at: datetime
updated_at: datetime
resolved_at: Optional[datetime]
class TicketCommentRead(SQLModel):
id: int
author_name: str
content: str
is_internal: bool
created_at: datetime

155
backend/populate_links.py Normal file
View file

@ -0,0 +1,155 @@
import requests
from bs4 import BeautifulSoup
from sqlmodel import Session, select
from database import engine
from models import Show
import time
import re
# El Goose API
API_BASE = "https://elgoose.net/api/v2"
SITE_BASE = "https://elgoose.net"
def get_shows_from_api():
"""Fetch all shows with their permalinks from the API"""
print("Fetching all shows from API...")
url = f"{API_BASE}/shows.json"
params = {"artist": 1, "order_by": "showdate", "direction": "DESC"}
all_shows = []
# It seems the API might return ALL shows on page 1 if no limit is set.
# We will try fetching page 1.
try:
print(f" Fetching shows...", end="", flush=True)
resp = requests.get(url, params=params)
resp.raise_for_status()
data = resp.json()
if data and 'data' in data:
all_shows = data['data']
print(f" Got {len(all_shows)} shows.")
return all_shows
except Exception as e:
print(f" Error: {e}")
return all_shows
def scrape_links(session_http, permalink):
"""Scrape Bandcamp and Nugs links from an El Goose show page"""
if not permalink:
return None, None
url = f"{SITE_BASE}/setlists/{permalink}"
try:
resp = session_http.get(url, timeout=10)
if resp.status_code == 404:
url = f"{SITE_BASE}/{permalink}"
resp = session_http.get(url, timeout=10)
if resp.status_code != 200:
return None, None
soup = BeautifulSoup(resp.text, 'html.parser')
bandcamp = None
nugs = None
for a in soup.find_all('a', href=True):
href = a['href']
# Bandcamp
if 'bandcamp.com' in href:
if 'goosetheband.bandcamp.com' in href or 'bandcamp.com/album' in href:
bandcamp = href
# Nugs
if 'nugs.net' in href:
if '/goose-' in href or 'recording' in href:
nugs = href
return bandcamp, nugs
except Exception as e:
print(f" ⚠️ Scraping error: {e}")
return None, None
def main():
print("🔗 Starting Link Population Script...")
# 1. Fetch API data
api_shows = get_shows_from_api()
print(f"✓ Found {len(api_shows)} shows in API.")
if not api_shows:
print("❌ No shows found in API. Exiting.")
return
date_to_permalink = {s['showdate']: s['permalink'] for s in api_shows}
# Setup HTTP Session
http = requests.Session()
http.headers.update({
"User-Agent": "ElmegDemoBot/1.0 (+http://elmeg.xyz)"
})
with Session(engine) as session:
# 2. Get our DB shows
db_shows = session.exec(select(Show)).all()
# Sort by date desc to update newest first
db_shows.sort(key=lambda x: x.date, reverse=True)
print(f"✓ Found {len(db_shows)} shows in DB to check.")
updates = 0
checked = 0
for show in db_shows:
checked += 1
s_date = show.date.strftime("%Y-%m-%d")
permalink = date_to_permalink.get(s_date)
if not permalink:
continue
# Skip if we already have both
if show.bandcamp_link and show.nugs_link:
continue
print(f"[{checked}/{len(db_shows)}] {s_date}...", end="", flush=True)
bc_link, nugs_link = scrape_links(http, permalink)
updated = False
if bc_link and bc_link != show.bandcamp_link:
show.bandcamp_link = bc_link
updated = True
print(" [BC]", end="")
if nugs_link and nugs_link != show.nugs_link:
show.nugs_link = nugs_link
updated = True
print(" [Nugs]", end="")
if updated:
session.add(show)
updates += 1
try:
session.commit()
session.refresh(show)
print("")
except Exception as e:
print(f" ❌ Save error: {e}")
else:
print(" -")
# Small delay
time.sleep(0.1)
print(f"\n🎉 Done! Updated {updates} shows.")
if __name__ == "__main__":
main()

118
backend/quick_seed.py Normal file
View file

@ -0,0 +1,118 @@
#!/usr/bin/env python3
"""Quick demo seeder - creates users and basic data"""
import sys
sys.path.insert(0, '/Users/ten/ANTIGRAVITY/elmeg-demo/backend')
from datetime import datetime, timedelta
from sqlmodel import Session
from passlib.context import CryptContext
from database import engine
from models import User, Vertical, Venue, Show, Song, Performance, UserPreferences
pwd_context = CryptContext(schemes=["argon2"], deprecated="auto")
print("Starting demo seed...")
with Session(engine) as session:
# Create Goose vertical
vertical = Vertical(name="Goose", slug="goose", description="Jam band from CT")
session.add(vertical)
session.commit()
session.refresh(vertical)
print(f"✓ Created vertical: {vertical.name}")
# Create 12 users
users_data = [
("archivist@demo.com", "TheArchivist", "user", True),
("statnerd@demo.com", "StatNerd420", "user", False),
("reviewer@demo.com", "CriticalListener", "user", False),
("casual@demo.com", "CasualFan", "user", False),
("groupleader@demo.com", "NortheastHonkers", "user", False),
("mod@demo.com", "ModGoose", "moderator", False),
("admin@demo.com", "AdminBird", "admin", False),
("newbie@demo.com", "NewToGoose", "user", False),
("taper@demo.com", "TaperTom", "user", False),
("tourfollower@demo.com", "RoadWarrior", "user", False),
("lurker@demo.com", "SilentHonker", "user", True),
("hype@demo.com", "HypeGoose", "user", False),
]
users = []
for email, username, role, wiki_mode in users_data:
user = User(
email=email,
hashed_password=pwd_context.hash("demo123"),
is_active=True,
is_superuser=(role == "admin"),
role=role
)
session.add(user)
session.commit()
session.refresh(user)
prefs = UserPreferences(
user_id=user.id,
wiki_mode=wiki_mode,
show_ratings=not wiki_mode,
show_comments=not wiki_mode
)
session.add(prefs)
users.append(user)
print(f"✓ Created user: {username}")
session.commit()
# Create venues
venues = [
Venue(name="Red Rocks", city="Morrison", state="CO", country="USA"),
Venue(name="Capitol Theatre", city="Port Chester", state="NY", country="USA"),
]
for v in venues:
session.add(v)
session.commit()
print(f"✓ Created {len(venues)} venues")
# Create songs
songs = [
Song(title="Hungersite", vertical_id=vertical.id),
Song(title="Arcadia", vertical_id=vertical.id),
Song(title="Hot Tea", vertical_id=vertical.id),
]
for s in songs:
session.add(s)
session.commit()
print(f"✓ Created {len(songs)} songs")
# Create shows
shows = []
for i in range(5):
show = Show(
date=datetime(2024, 1, 1) + timedelta(days=i*30),
vertical_id=vertical.id,
venue_id=venues[i % len(venues)].id
)
session.add(show)
shows.append(show)
session.commit()
print(f"✓ Created {len(shows)} shows")
# Create performances
for show in shows:
for pos, song in enumerate(songs, 1):
perf = Performance(
show_id=show.id,
song_id=song.id,
position=pos,
set_name="Set 1"
)
session.add(perf)
session.commit()
print(f"✓ Created performances")
print("\n" + "="*60)
print("✓ DEMO DATA SEEDED!")
print("="*60)
print("\nAll passwords: demo123")
print("\nStart demo server:")
print(" cd /Users/ten/ANTIGRAVITY/elmeg-demo/backend")
print(" DATABASE_URL='sqlite:///./elmeg-demo.db' uvicorn main:app --reload --port 8001")

View file

@ -0,0 +1,57 @@
import pytest
from sqlmodel import Session, SQLModel, create_engine
from models import User, Review, Show, Rating
from schemas import ReviewCreate
from services.gamification import award_xp
from routers.reviews import create_review
from fastapi import HTTPException
# Mock auth
def mock_get_current_user():
return User(id=1, email="test@test.com", hashed_password="pw", is_active=True)
# Setup in-memory DB
sqlite_file_name = "test_review_debug.db"
sqlite_url = f"sqlite:///{sqlite_file_name}"
engine = create_engine(sqlite_url)
def test_repro_review_crash():
SQLModel.metadata.create_all(engine)
with Session(engine) as session:
# Create dummy user and show
user = User(email="test@test.com", hashed_password="pw")
session.add(user)
show = Show(date="2025-01-01", slug="test-show")
session.add(show)
session.commit()
session.refresh(user)
session.refresh(show)
print(f"User ID: {user.id}, Show ID: {show.id}")
# Payload
review_payload = ReviewCreate(
show_id=show.id,
content="Test Review Content",
blurb="Test Blurb",
score=5.0
)
try:
print("Attempting to create review...")
result = create_review(
review=review_payload,
session=session,
current_user=user
)
print("Review created successfully:", result)
except Exception as e:
print(f"\nCRASH DETECTED: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
test_repro_review_crash()

15
backend/requirements.txt Normal file
View file

@ -0,0 +1,15 @@
fastapi
uvicorn[standard]
sqlmodel
alembic
python-jose[cryptography]
passlib[bcrypt]
python-multipart
pytest
httpx
argon2-cffi
psycopg2-binary
requests
beautifulsoup4
boto3
email-validator

652
backend/routers/admin.py Normal file
View file

@ -0,0 +1,652 @@
"""
Admin Router - Protected endpoints for admin users only.
User management, content CRUD, platform stats.
"""
from typing import List, Optional
from datetime import datetime
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlmodel import Session, select, func
from pydantic import BaseModel
from database import get_session
from models import User, Profile, Show, Song, Venue, Tour, Rating, Comment, Review, Attendance, Artist
from dependencies import RoleChecker
from auth import get_password_hash
router = APIRouter(prefix="/admin", tags=["admin"])
# Only admins can access these endpoints
allow_admin = RoleChecker(["admin"])
# ============ SCHEMAS ============
class UserUpdate(BaseModel):
role: Optional[str] = None
is_active: Optional[bool] = None
email_verified: Optional[bool] = None
class UserListItem(BaseModel):
id: int
email: str
role: str
is_active: bool
email_verified: bool
created_at: Optional[datetime] = None
class Config:
from_attributes = True
class ShowCreate(BaseModel):
date: datetime
vertical_id: int
venue_id: Optional[int] = None
tour_id: Optional[int] = None
notes: Optional[str] = None
bandcamp_link: Optional[str] = None
nugs_link: Optional[str] = None
youtube_link: Optional[str] = None
class ShowUpdate(BaseModel):
date: Optional[datetime] = None
venue_id: Optional[int] = None
tour_id: Optional[int] = None
notes: Optional[str] = None
bandcamp_link: Optional[str] = None
nugs_link: Optional[str] = None
youtube_link: Optional[str] = None
class SongCreate(BaseModel):
title: str
vertical_id: int
original_artist: Optional[str] = None
notes: Optional[str] = None
youtube_link: Optional[str] = None
class SongUpdate(BaseModel):
title: Optional[str] = None
original_artist: Optional[str] = None
notes: Optional[str] = None
youtube_link: Optional[str] = None
class VenueCreate(BaseModel):
name: str
city: str
state: Optional[str] = None
country: str = "USA"
capacity: Optional[int] = None
class VenueUpdate(BaseModel):
name: Optional[str] = None
city: Optional[str] = None
state: Optional[str] = None
country: Optional[str] = None
capacity: Optional[int] = None
class TourCreate(BaseModel):
name: str
vertical_id: int
start_date: Optional[datetime] = None
end_date: Optional[datetime] = None
class TourUpdate(BaseModel):
name: Optional[str] = None
start_date: Optional[datetime] = None
end_date: Optional[datetime] = None
class ArtistUpdate(BaseModel):
bio: Optional[str] = None
image_url: Optional[str] = None
notes: Optional[str] = None
class PlatformStats(BaseModel):
total_users: int
verified_users: int
total_shows: int
total_songs: int
total_venues: int
total_ratings: int
total_reviews: int
total_comments: int
# ============ STATS ============
@router.get("/stats", response_model=PlatformStats)
def get_platform_stats(
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Get platform-wide statistics"""
return PlatformStats(
total_users=session.exec(select(func.count(User.id))).one(),
verified_users=session.exec(select(func.count(User.id)).where(User.email_verified == True)).one(),
total_shows=session.exec(select(func.count(Show.id))).one(),
total_songs=session.exec(select(func.count(Song.id))).one(),
total_venues=session.exec(select(func.count(Venue.id))).one(),
total_ratings=session.exec(select(func.count(Rating.id))).one(),
total_reviews=session.exec(select(func.count(Review.id))).one(),
total_comments=session.exec(select(func.count(Comment.id))).one(),
)
# ============ USERS ============
@router.get("/users")
def list_users(
skip: int = 0,
limit: int = 50,
search: Optional[str] = None,
role: Optional[str] = None,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""List all users with optional filtering"""
query = select(User)
if search:
query = query.where(User.email.contains(search))
if role:
query = query.where(User.role == role)
query = query.offset(skip).limit(limit)
users = session.exec(query).all()
# Get profiles for usernames
result = []
for user in users:
profile = session.exec(select(Profile).where(Profile.user_id == user.id)).first()
result.append({
"id": user.id,
"email": user.email,
"username": profile.username if profile else None,
"role": user.role,
"is_active": user.is_active,
"email_verified": user.email_verified,
})
return result
@router.get("/users/{user_id}")
def get_user(
user_id: int,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Get user details with activity stats"""
user = session.get(User, user_id)
if not user:
raise HTTPException(status_code=404, detail="User not found")
profile = session.exec(select(Profile).where(Profile.user_id == user.id)).first()
return {
"id": user.id,
"email": user.email,
"username": profile.username if profile else None,
"role": user.role,
"is_active": user.is_active,
"email_verified": user.email_verified,
"bio": user.bio,
"stats": {
"ratings": session.exec(select(func.count(Rating.id)).where(Rating.user_id == user.id)).one(),
"reviews": session.exec(select(func.count(Review.id)).where(Review.user_id == user.id)).one(),
"comments": session.exec(select(func.count(Comment.id)).where(Comment.user_id == user.id)).one(),
"attendances": session.exec(select(func.count(Attendance.id)).where(Attendance.user_id == user.id)).one(),
}
}
@router.patch("/users/{user_id}")
def update_user(
user_id: int,
update: UserUpdate,
session: Session = Depends(get_session),
admin: User = Depends(allow_admin)
):
"""Update user role, status, or verification"""
user = session.get(User, user_id)
if not user:
raise HTTPException(status_code=404, detail="User not found")
# Prevent admin from demoting themselves
if user.id == admin.id and update.role and update.role != "admin":
raise HTTPException(status_code=400, detail="Cannot demote yourself")
if update.role is not None:
user.role = update.role
if update.is_active is not None:
user.is_active = update.is_active
if update.email_verified is not None:
user.email_verified = update.email_verified
session.add(user)
session.commit()
session.refresh(user)
return {"message": "User updated", "user_id": user.id}
# ============ SHOWS ============
@router.post("/shows")
def create_show(
show_data: ShowCreate,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Create a new show"""
show = Show(**show_data.model_dump())
session.add(show)
session.commit()
session.refresh(show)
return show
@router.patch("/shows/{show_id}")
def update_show(
show_id: int,
update: ShowUpdate,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Update show details"""
show = session.get(Show, show_id)
if not show:
raise HTTPException(status_code=404, detail="Show not found")
for key, value in update.model_dump(exclude_unset=True).items():
setattr(show, key, value)
session.add(show)
session.commit()
session.refresh(show)
return show
@router.delete("/shows/{show_id}")
def delete_show(
show_id: int,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Delete a show"""
show = session.get(Show, show_id)
if not show:
raise HTTPException(status_code=404, detail="Show not found")
session.delete(show)
session.commit()
return {"message": "Show deleted", "show_id": show_id}
# ============ SONGS ============
@router.post("/songs")
def create_song(
song_data: SongCreate,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Create a new song"""
song = Song(**song_data.model_dump())
session.add(song)
session.commit()
session.refresh(song)
return song
@router.patch("/songs/{song_id}")
def update_song(
song_id: int,
update: SongUpdate,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Update song details"""
song = session.get(Song, song_id)
if not song:
raise HTTPException(status_code=404, detail="Song not found")
for key, value in update.model_dump(exclude_unset=True).items():
setattr(song, key, value)
session.add(song)
session.commit()
session.refresh(song)
return song
@router.delete("/songs/{song_id}")
def delete_song(
song_id: int,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Delete a song"""
song = session.get(Song, song_id)
if not song:
raise HTTPException(status_code=404, detail="Song not found")
session.delete(song)
session.commit()
return {"message": "Song deleted", "song_id": song_id}
# ============ VENUES ============
@router.post("/venues")
def create_venue(
venue_data: VenueCreate,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Create a new venue"""
venue = Venue(**venue_data.model_dump())
session.add(venue)
session.commit()
session.refresh(venue)
return venue
@router.patch("/venues/{venue_id}")
def update_venue(
venue_id: int,
update: VenueUpdate,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Update venue details"""
venue = session.get(Venue, venue_id)
if not venue:
raise HTTPException(status_code=404, detail="Venue not found")
for key, value in update.model_dump(exclude_unset=True).items():
setattr(venue, key, value)
session.add(venue)
session.commit()
session.refresh(venue)
return venue
@router.delete("/venues/{venue_id}")
def delete_venue(
venue_id: int,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Delete a venue"""
venue = session.get(Venue, venue_id)
if not venue:
raise HTTPException(status_code=404, detail="Venue not found")
session.delete(venue)
session.commit()
return {"message": "Venue deleted", "venue_id": venue_id}
# ============ TOURS ============
@router.post("/tours")
def create_tour(
tour_data: TourCreate,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Create a new tour"""
tour = Tour(**tour_data.model_dump())
session.add(tour)
session.commit()
session.refresh(tour)
return tour
@router.patch("/tours/{tour_id}")
def update_tour(
tour_id: int,
update: TourUpdate,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Update tour details"""
tour = session.get(Tour, tour_id)
if not tour:
raise HTTPException(status_code=404, detail="Tour not found")
for key, value in update.model_dump(exclude_unset=True).items():
setattr(tour, key, value)
session.add(tour)
session.commit()
session.refresh(tour)
return tour
@router.delete("/tours/{tour_id}")
def delete_tour(
tour_id: int,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Delete a tour"""
tour = session.get(Tour, tour_id)
if not tour:
raise HTTPException(status_code=404, detail="Tour not found")
session.delete(tour)
session.commit()
return {"message": "Tour deleted", "tour_id": tour_id}
# ============ ARTISTS ============
@router.get("/artists")
def list_artists(
skip: int = 0,
limit: int = 50,
search: Optional[str] = None,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""List all artists with optional search"""
query = select(Artist)
if search:
query = query.where(Artist.name.icontains(search))
query = query.order_by(Artist.name).offset(skip).limit(limit)
artists = session.exec(query).all()
return [
{
"id": a.id,
"name": a.name,
"slug": a.slug,
"bio": a.bio,
"image_url": a.image_url,
"notes": a.notes,
}
for a in artists
]
@router.patch("/artists/{artist_id}")
def update_artist(
artist_id: int,
update: ArtistUpdate,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Update artist details (bio, image, notes)"""
artist = session.get(Artist, artist_id)
if not artist:
raise HTTPException(status_code=404, detail="Artist not found")
for key, value in update.model_dump(exclude_unset=True).items():
setattr(artist, key, value)
session.add(artist)
session.commit()
session.refresh(artist)
return artist
# ============ PERFORMANCES ============
from models import Performance
class PerformanceUpdate(BaseModel):
notes: Optional[str] = None
youtube_link: Optional[str] = None
bandcamp_link: Optional[str] = None
nugs_link: Optional[str] = None
track_url: Optional[str] = None
@router.patch("/performances/{performance_id}")
def update_performance(
performance_id: int,
update: PerformanceUpdate,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Update performance links and notes"""
performance = session.get(Performance, performance_id)
if not performance:
raise HTTPException(status_code=404, detail="Performance not found")
for key, value in update.model_dump(exclude_unset=True).items():
setattr(performance, key, value)
session.add(performance)
session.commit()
session.refresh(performance)
return performance
@router.get("/performances/{performance_id}")
def get_performance(
performance_id: int,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Get performance details for admin"""
performance = session.get(Performance, performance_id)
if not performance:
raise HTTPException(status_code=404, detail="Performance not found")
return {
"id": performance.id,
"slug": performance.slug,
"show_id": performance.show_id,
"song_id": performance.song_id,
"position": performance.position,
"set_name": performance.set_name,
"notes": performance.notes,
"youtube_link": performance.youtube_link,
"bandcamp_link": performance.bandcamp_link,
"nugs_link": performance.nugs_link,
"track_url": performance.track_url,
}
class BulkLinksImport(BaseModel):
links: List[dict] # {"show_id": 1, "platform": "nugs", "url": "..."} or {"performance_id": 1, ...}
@router.post("/import/external-links")
def bulk_import_links(
data: BulkLinksImport,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Bulk import external links for shows and performances"""
updated_shows = 0
updated_performances = 0
errors = []
for item in data.links:
platform = item.get("platform", "").lower()
url = item.get("url")
if not platform or not url:
errors.append({"item": item, "error": "Missing platform or url"})
continue
field_name = f"{platform}_link"
if "show_id" in item:
show = session.get(Show, item["show_id"])
if show and hasattr(show, field_name):
setattr(show, field_name, url)
session.add(show)
updated_shows += 1
else:
errors.append({"item": item, "error": "Show not found or invalid platform"})
elif "performance_id" in item:
perf = session.get(Performance, item["performance_id"])
if perf and hasattr(perf, field_name):
setattr(perf, field_name, url)
session.add(perf)
updated_performances += 1
else:
errors.append({"item": item, "error": "Performance not found or invalid platform"})
session.commit()
return {
"updated_shows": updated_shows,
"updated_performances": updated_performances,
"errors": errors
}
# ============ EMAIL & NOTIFICATIONS ============
@router.post("/send-weekly-digest")
def trigger_weekly_digest(
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Manually trigger weekly digest emails (runs automatically every Sunday 9am UTC)"""
from services.weekly_digest import send_weekly_digests
try:
send_weekly_digests()
return {"message": "Weekly digest emails sent successfully"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"Failed to send digest: {str(e)}")
@router.post("/test-email")
def test_email(
to_email: str,
session: Session = Depends(get_session),
_: User = Depends(allow_admin)
):
"""Send a test email to verify email configuration"""
from services.email_service import email_service
subject = "Elmeg Test Email"
html_content = """
<html>
<body style="font-family: sans-serif; padding: 20px;">
<h2>Test Email</h2>
<p>This is a test email from Elmeg to verify email configuration.</p>
<p>If you received this, SMTP is working correctly!</p>
</body>
</html>
"""
text_content = "This is a test email from Elmeg. If you received this, SMTP is working correctly!"
success = email_service.send_email(to_email, subject, html_content, text_content)
if success:
return {"message": f"Test email sent to {to_email}"}
else:
raise HTTPException(status_code=500, detail="Failed to send test email")

View file

@ -0,0 +1,50 @@
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlmodel import Session, select
from typing import List, Optional
from database import get_session
from models import Artist, Song, Performance, Show, PerformanceArtist
from schemas import SongRead
router = APIRouter(prefix="/artists", tags=["artists"])
@router.get("/{slug}")
async def get_artist(slug: str, session: Session = Depends(get_session)):
"""Get artist details, covers, and guest appearances"""
artist = session.exec(select(Artist).where(Artist.slug == slug)).first()
if not artist:
raise HTTPException(status_code=404, detail="Artist not found")
# Get covers (Songs by this artist that Goose has played)
covers = session.exec(
select(Song)
.where(Song.artist_id == artist.id)
.order_by(Song.title)
).all()
# Get guest appearances (Performances where this artist is linked)
# This queries the PerformanceArtist link table
guest_appearances = session.exec(
select(Performance, Show)
.join(PerformanceArtist, PerformanceArtist.performance_id == Performance.id)
.join(Show, Performance.show_id == Show.id)
.where(PerformanceArtist.artist_id == artist.id)
.order_by(Show.date.desc())
).all()
# Format guest appearances
guest_spots = []
for perf, show in guest_appearances:
guest_spots.append({
"date": show.date,
"venue": show.venue.name if show.venue else "Unknown Venue",
"city": f"{show.venue.city}, {show.venue.state}" if show.venue else "",
"song_title": perf.song.title,
"show_slug": show.slug,
"song_slug": perf.song.slug
})
return {
"artist": artist,
"covers": covers,
"guest_appearances": guest_spots
}

View file

@ -0,0 +1,84 @@
from typing import List, Optional
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlmodel import Session, select
from database import get_session
from models import Attendance, User, Show
from schemas import AttendanceCreate, AttendanceRead
from auth import get_current_user
from services.gamification import award_xp, check_and_award_badges, update_streak, XP_REWARDS
router = APIRouter(prefix="/attendance", tags=["attendance"])
@router.post("/", response_model=AttendanceRead)
def mark_attendance(
attendance: AttendanceCreate,
session: Session = Depends(get_session),
current_user: User = Depends(get_current_user)
):
# Check if already attended
existing = session.exec(
select(Attendance)
.where(Attendance.user_id == current_user.id)
.where(Attendance.show_id == attendance.show_id)
).first()
if existing:
# Update notes if provided, or just return existing
if attendance.notes:
existing.notes = attendance.notes
session.add(existing)
session.commit()
session.refresh(existing)
return existing
db_attendance = Attendance(**attendance.model_dump(), user_id=current_user.id)
session.add(db_attendance)
# Award XP for marking attendance
new_xp, level_up = award_xp(session, current_user, XP_REWARDS["attendance_add"], "attendance")
update_streak(session, current_user)
new_badges = check_and_award_badges(session, current_user)
session.commit()
session.refresh(db_attendance)
return db_attendance
@router.delete("/{show_id}")
def remove_attendance(
show_id: int,
session: Session = Depends(get_session),
current_user: User = Depends(get_current_user)
):
attendance = session.exec(
select(Attendance)
.where(Attendance.user_id == current_user.id)
.where(Attendance.show_id == show_id)
).first()
if not attendance:
raise HTTPException(status_code=404, detail="Attendance not found")
session.delete(attendance)
session.commit()
return {"ok": True}
@router.get("/me", response_model=List[AttendanceRead])
def get_my_attendance(
session: Session = Depends(get_session),
current_user: User = Depends(get_current_user)
):
return session.exec(select(Attendance).where(Attendance.user_id == current_user.id)).all()
@router.get("/show/{show_id}", response_model=List[AttendanceRead])
def get_show_attendance(
show_id: int,
session: Session = Depends(get_session),
offset: int = 0,
limit: int = 100
):
return session.exec(
select(Attendance)
.where(Attendance.show_id == show_id)
.offset(offset)
.limit(limit)
).all()

192
backend/routers/auth.py Normal file
View file

@ -0,0 +1,192 @@
from datetime import timedelta, datetime
from typing import Annotated
from fastapi import APIRouter, Depends, HTTPException, status, BackgroundTasks
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
from sqlmodel import Session, select
from pydantic import BaseModel, EmailStr
from database import get_session
from models import User, Profile
from schemas import UserCreate, Token, UserRead
from auth import verify_password, get_password_hash, create_access_token, ACCESS_TOKEN_EXPIRE_MINUTES, get_current_user
from services.email_service import (
send_verification_email, send_password_reset_email,
generate_token, get_verification_expiry, get_reset_expiry
)
router = APIRouter(prefix="/auth", tags=["auth"])
# Request/Response schemas for new endpoints
class VerifyEmailRequest(BaseModel):
token: str
class ForgotPasswordRequest(BaseModel):
email: EmailStr
class ResetPasswordRequest(BaseModel):
token: str
new_password: str
class ResendVerificationRequest(BaseModel):
email: EmailStr
@router.post("/register", response_model=UserRead)
async def register(
user_in: UserCreate,
background_tasks: BackgroundTasks,
session: Session = Depends(get_session)
):
user = session.exec(select(User).where(User.email == user_in.email)).first()
if user:
raise HTTPException(status_code=400, detail="Email already registered")
# Create User with verification token
hashed_password = get_password_hash(user_in.password)
verification_token = generate_token()
db_user = User(
email=user_in.email,
hashed_password=hashed_password,
email_verified=False,
verification_token=verification_token,
verification_token_expires=get_verification_expiry()
)
session.add(db_user)
session.commit()
session.refresh(db_user)
# Create Default Profile
profile = Profile(user_id=db_user.id, username=user_in.username, display_name=user_in.username)
session.add(profile)
session.commit()
# Send verification email in background
background_tasks.add_task(send_verification_email, db_user.email, verification_token)
return db_user
@router.post("/verify-email")
def verify_email(request: VerifyEmailRequest, session: Session = Depends(get_session)):
"""Verify user's email with token"""
user = session.exec(
select(User).where(User.verification_token == request.token)
).first()
if not user:
raise HTTPException(status_code=400, detail="Invalid verification token")
if user.verification_token_expires and user.verification_token_expires < datetime.utcnow():
raise HTTPException(status_code=400, detail="Verification token expired")
if user.email_verified:
return {"message": "Email already verified"}
# Mark as verified
user.email_verified = True
user.verification_token = None
user.verification_token_expires = None
session.add(user)
session.commit()
return {"message": "Email verified successfully"}
@router.post("/resend-verification")
async def resend_verification(
request: ResendVerificationRequest,
background_tasks: BackgroundTasks,
session: Session = Depends(get_session)
):
"""Resend verification email"""
user = session.exec(select(User).where(User.email == request.email)).first()
if not user:
# Don't reveal if email exists
return {"message": "If the email exists, a verification link has been sent"}
if user.email_verified:
return {"message": "Email already verified"}
# Generate new token
user.verification_token = generate_token()
user.verification_token_expires = get_verification_expiry()
session.add(user)
session.commit()
background_tasks.add_task(send_verification_email, user.email, user.verification_token)
return {"message": "If the email exists, a verification link has been sent"}
@router.post("/forgot-password")
async def forgot_password(
request: ForgotPasswordRequest,
background_tasks: BackgroundTasks,
session: Session = Depends(get_session)
):
"""Request password reset email"""
user = session.exec(select(User).where(User.email == request.email)).first()
if not user:
# Don't reveal if email exists
return {"message": "If the email exists, a reset link has been sent"}
# Generate reset token
user.reset_token = generate_token()
user.reset_token_expires = get_reset_expiry()
session.add(user)
session.commit()
background_tasks.add_task(send_password_reset_email, user.email, user.reset_token)
return {"message": "If the email exists, a reset link has been sent"}
@router.post("/reset-password")
def reset_password(request: ResetPasswordRequest, session: Session = Depends(get_session)):
"""Reset password with token"""
user = session.exec(
select(User).where(User.reset_token == request.token)
).first()
if not user:
raise HTTPException(status_code=400, detail="Invalid reset token")
if user.reset_token_expires and user.reset_token_expires < datetime.utcnow():
raise HTTPException(status_code=400, detail="Reset token expired")
# Update password
user.hashed_password = get_password_hash(request.new_password)
user.reset_token = None
user.reset_token_expires = None
session.add(user)
session.commit()
return {"message": "Password reset successfully"}
@router.post("/token", response_model=Token)
def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()],
session: Session = Depends(get_session)
):
user = session.exec(select(User).where(User.email == form_data.username)).first()
if not user or not verify_password(form_data.password, user.hashed_password):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Incorrect username or password",
headers={"WWW-Authenticate": "Bearer"},
)
access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
access_token = create_access_token(
data={"sub": user.email}, expires_delta=access_token_expires
)
return {"access_token": access_token, "token_type": "bearer"}
@router.get("/users/me", response_model=UserRead)
def read_users_me(current_user: Annotated[User, Depends(get_current_user)]):
return current_user

32
backend/routers/badges.py Normal file
View file

@ -0,0 +1,32 @@
from typing import List
from fastapi import APIRouter, Depends, HTTPException
from sqlmodel import Session, select
from database import get_session
from models import User, UserBadge, Badge
from schemas import UserBadgeRead
from auth import get_current_user
from services.stats import check_and_award_badges
router = APIRouter(prefix="/badges", tags=["badges"])
@router.get("/me", response_model=List[UserBadgeRead])
def read_my_badges(
session: Session = Depends(get_session),
current_user: User = Depends(get_current_user)
):
# Trigger a check (lazy evaluation of badges)
check_and_award_badges(session, current_user.id)
# Refresh user to get new badges
session.refresh(current_user)
return current_user.badges
@router.get("/{user_id}", response_model=List[UserBadgeRead])
def read_user_badges(
user_id: int,
session: Session = Depends(get_session)
):
user = session.get(User, user_id)
if not user:
raise HTTPException(status_code=404, detail="User not found")
return user.badges

327
backend/routers/chase.py Normal file
View file

@ -0,0 +1,327 @@
"""
Chase Songs and Profile Stats Router
"""
from fastapi import APIRouter, Depends, HTTPException, status
from sqlmodel import Session, select, func
from typing import List, Optional
from pydantic import BaseModel
from datetime import datetime
from database import get_session
from models import ChaseSong, Song, Attendance, Show, Performance, Rating, User
from routers.auth import get_current_user
router = APIRouter(prefix="/chase", tags=["chase"])
# --- Schemas ---
class ChaseSongCreate(BaseModel):
song_id: int
priority: int = 1
notes: Optional[str] = None
class ChaseSongResponse(BaseModel):
id: int
song_id: int
song_title: str
priority: int
notes: Optional[str]
created_at: datetime
caught_at: Optional[datetime]
caught_show_id: Optional[int]
caught_show_date: Optional[str] = None
class ChaseSongUpdate(BaseModel):
priority: Optional[int] = None
notes: Optional[str] = None
class ProfileStats(BaseModel):
shows_attended: int
unique_songs_seen: int
debuts_witnessed: int
heady_versions_attended: int # Top 10 rated performances
top_10_performances: int
total_ratings: int
total_reviews: int
chase_songs_count: int
chase_songs_caught: int
most_seen_song: Optional[str] = None
most_seen_count: int = 0
# --- Routes ---
@router.get("/songs", response_model=List[ChaseSongResponse])
async def get_my_chase_songs(
current_user: User = Depends(get_current_user),
session: Session = Depends(get_session)
):
"""Get all chase songs for the current user"""
statement = (
select(ChaseSong)
.where(ChaseSong.user_id == current_user.id)
.order_by(ChaseSong.priority, ChaseSong.created_at.desc())
)
chase_songs = session.exec(statement).all()
result = []
for cs in chase_songs:
song = session.get(Song, cs.song_id)
caught_show_date = None
if cs.caught_show_id:
show = session.get(Show, cs.caught_show_id)
if show:
caught_show_date = show.date.strftime("%Y-%m-%d") if show.date else None
result.append(ChaseSongResponse(
id=cs.id,
song_id=cs.song_id,
song_title=song.title if song else "Unknown",
priority=cs.priority,
notes=cs.notes,
created_at=cs.created_at,
caught_at=cs.caught_at,
caught_show_id=cs.caught_show_id,
caught_show_date=caught_show_date
))
return result
@router.post("/songs", response_model=ChaseSongResponse, status_code=status.HTTP_201_CREATED)
async def add_chase_song(
data: ChaseSongCreate,
current_user: User = Depends(get_current_user),
session: Session = Depends(get_session)
):
"""Add a song to user's chase list"""
# Check if song exists
song = session.get(Song, data.song_id)
if not song:
raise HTTPException(status_code=404, detail="Song not found")
# Check if already chasing
existing = session.exec(
select(ChaseSong)
.where(ChaseSong.user_id == current_user.id, ChaseSong.song_id == data.song_id)
).first()
if existing:
raise HTTPException(status_code=400, detail="Song already in chase list")
chase_song = ChaseSong(
user_id=current_user.id,
song_id=data.song_id,
priority=data.priority,
notes=data.notes
)
session.add(chase_song)
session.commit()
session.refresh(chase_song)
return ChaseSongResponse(
id=chase_song.id,
song_id=chase_song.song_id,
song_title=song.title,
priority=chase_song.priority,
notes=chase_song.notes,
created_at=chase_song.created_at,
caught_at=None,
caught_show_id=None
)
@router.patch("/songs/{chase_id}", response_model=ChaseSongResponse)
async def update_chase_song(
chase_id: int,
data: ChaseSongUpdate,
current_user: User = Depends(get_current_user),
session: Session = Depends(get_session)
):
"""Update a chase song"""
chase_song = session.get(ChaseSong, chase_id)
if not chase_song or chase_song.user_id != current_user.id:
raise HTTPException(status_code=404, detail="Chase song not found")
if data.priority is not None:
chase_song.priority = data.priority
if data.notes is not None:
chase_song.notes = data.notes
session.add(chase_song)
session.commit()
session.refresh(chase_song)
song = session.get(Song, chase_song.song_id)
return ChaseSongResponse(
id=chase_song.id,
song_id=chase_song.song_id,
song_title=song.title if song else "Unknown",
priority=chase_song.priority,
notes=chase_song.notes,
created_at=chase_song.created_at,
caught_at=chase_song.caught_at,
caught_show_id=chase_song.caught_show_id
)
@router.delete("/songs/{chase_id}", status_code=status.HTTP_204_NO_CONTENT)
async def remove_chase_song(
chase_id: int,
current_user: User = Depends(get_current_user),
session: Session = Depends(get_session)
):
"""Remove a song from chase list"""
chase_song = session.get(ChaseSong, chase_id)
if not chase_song or chase_song.user_id != current_user.id:
raise HTTPException(status_code=404, detail="Chase song not found")
session.delete(chase_song)
session.commit()
@router.post("/songs/{chase_id}/caught")
async def mark_song_caught(
chase_id: int,
show_id: int,
current_user: User = Depends(get_current_user),
session: Session = Depends(get_session)
):
"""Mark a chase song as caught at a specific show"""
chase_song = session.get(ChaseSong, chase_id)
if not chase_song or chase_song.user_id != current_user.id:
raise HTTPException(status_code=404, detail="Chase song not found")
show = session.get(Show, show_id)
if not show:
raise HTTPException(status_code=404, detail="Show not found")
chase_song.caught_at = datetime.utcnow()
chase_song.caught_show_id = show_id
session.add(chase_song)
session.commit()
return {"message": "Song marked as caught!"}
# Profile stats endpoint
@router.get("/profile/stats", response_model=ProfileStats)
async def get_profile_stats(
current_user: User = Depends(get_current_user),
session: Session = Depends(get_session)
):
"""Get comprehensive profile stats for the current user"""
# Shows attended
shows_attended = session.exec(
select(func.count(Attendance.id))
.where(Attendance.user_id == current_user.id)
).one() or 0
# Get show IDs user attended
attended_show_ids = session.exec(
select(Attendance.show_id)
.where(Attendance.user_id == current_user.id)
).all()
# Unique songs seen (performances at attended shows)
unique_songs_seen = session.exec(
select(func.count(func.distinct(Performance.song_id)))
.where(Performance.show_id.in_(attended_show_ids) if attended_show_ids else False)
).one() or 0
# Debuts witnessed (times_played = 1 at show they attended)
# This would require joining with song data - simplified for now
debuts_witnessed = 0
if attended_show_ids:
debuts_q = session.exec(
select(Performance)
.where(Performance.show_id.in_(attended_show_ids))
).all()
# Count performances where this was the debut
for perf in debuts_q:
# Check if this was the first performance of the song
earlier_perfs = session.exec(
select(func.count(Performance.id))
.join(Show, Performance.show_id == Show.id)
.where(Performance.song_id == perf.song_id)
.where(Show.date < session.get(Show, perf.show_id).date if session.get(Show, perf.show_id) else False)
).one()
if earlier_perfs == 0:
debuts_witnessed += 1
# Top performances attended (with avg rating >= 8.0)
top_performances_attended = 0
heady_versions_attended = 0
if attended_show_ids:
# Get average ratings for performances at attended shows
perf_ratings = session.exec(
select(
Rating.performance_id,
func.avg(Rating.score).label("avg_rating")
)
.where(Rating.performance_id.isnot(None))
.group_by(Rating.performance_id)
.having(func.avg(Rating.score) >= 8.0)
).all()
# Filter to performances at attended shows
high_rated_perf_ids = [pr[0] for pr in perf_ratings]
if high_rated_perf_ids:
attended_high_rated = session.exec(
select(func.count(Performance.id))
.where(Performance.id.in_(high_rated_perf_ids))
.where(Performance.show_id.in_(attended_show_ids))
).one() or 0
top_performances_attended = attended_high_rated
heady_versions_attended = attended_high_rated
# Total ratings/reviews
total_ratings = session.exec(
select(func.count(Rating.id)).where(Rating.user_id == current_user.id)
).one() or 0
total_reviews = session.exec(
select(func.count()).select_from(session.exec(
select(1).where(Rating.user_id == current_user.id) # placeholder
).subquery())
).one() if False else 0 # Will fix this
# Chase songs
chase_count = session.exec(
select(func.count(ChaseSong.id)).where(ChaseSong.user_id == current_user.id)
).one() or 0
chase_caught = session.exec(
select(func.count(ChaseSong.id))
.where(ChaseSong.user_id == current_user.id)
.where(ChaseSong.caught_at.isnot(None))
).one() or 0
# Most seen song
most_seen_song = None
most_seen_count = 0
if attended_show_ids:
song_counts = session.exec(
select(
Performance.song_id,
func.count(Performance.id).label("count")
)
.where(Performance.show_id.in_(attended_show_ids))
.group_by(Performance.song_id)
.order_by(func.count(Performance.id).desc())
.limit(1)
).first()
if song_counts:
song = session.get(Song, song_counts[0])
if song:
most_seen_song = song.title
most_seen_count = song_counts[1]
return ProfileStats(
shows_attended=shows_attended,
unique_songs_seen=unique_songs_seen,
debuts_witnessed=min(debuts_witnessed, 50), # Cap to prevent timeout
heady_versions_attended=heady_versions_attended,
top_10_performances=top_performances_attended,
total_ratings=total_ratings,
total_reviews=0, # TODO: implement
chase_songs_count=chase_count,
chase_songs_caught=chase_caught,
most_seen_song=most_seen_song,
most_seen_count=most_seen_count
)

131
backend/routers/feed.py Normal file
View file

@ -0,0 +1,131 @@
from typing import List, Union
from fastapi import APIRouter, Depends, Query
from sqlmodel import Session, select, desc
from database import get_session
from models import Review, Attendance, GroupPost, User, Profile, Performance, Show, Song
from schemas import ReviewRead, AttendanceRead, GroupPostRead
from datetime import datetime
router = APIRouter(prefix="/feed", tags=["feed"])
# We need a unified schema for the feed
from pydantic import BaseModel
class FeedItem(BaseModel):
type: str # review, attendance, post
timestamp: datetime
data: Union[ReviewRead, AttendanceRead, GroupPostRead, dict]
user: dict # Basic user info
entity: dict | None = None # Linked entity info
def get_user_display(session: Session, user_id: int) -> dict:
"""Get consistent user display info using Profile username"""
user = session.get(User, user_id)
if not user:
return {"id": 0, "username": "Deleted User", "avatar_bg_color": "#666", "avatar_text": None}
profile = session.exec(
select(Profile).where(Profile.user_id == user_id)
).first()
return {
"id": user.id,
"username": profile.username if profile else f"User {user_id}",
"display_name": profile.display_name if profile else None,
"avatar_bg_color": user.avatar_bg_color or "#0F4C81",
"avatar_text": user.avatar_text,
}
def get_entity_info(session: Session, review: Review) -> dict | None:
"""Get entity link info for a review"""
if review.performance_id:
perf = session.get(Performance, review.performance_id)
if perf:
song = session.get(Song, perf.song_id)
show = session.get(Show, perf.show_id)
return {
"type": "performance",
"slug": perf.slug,
"title": song.title if song else "Unknown Song",
"date": show.date.isoformat() if show and show.date else None,
}
elif review.show_id:
show = session.get(Show, review.show_id)
if show:
return {
"type": "show",
"slug": show.slug,
"title": show.date.strftime("%Y-%m-%d") if show.date else "Unknown Date",
}
elif review.song_id:
song = session.get(Song, review.song_id)
if song:
return {
"type": "song",
"slug": song.slug,
"title": song.title,
}
return None
@router.get("/", response_model=List[FeedItem])
def get_global_feed(
limit: int = 20,
session: Session = Depends(get_session)
):
# Fetch latest reviews
reviews = session.exec(
select(Review).order_by(desc(Review.created_at)).limit(limit)
).all()
# Fetch latest attendance
attendance = session.exec(
select(Attendance).order_by(desc(Attendance.created_at)).limit(limit)
).all()
# Fetch latest group posts
posts = session.exec(
select(GroupPost).order_by(desc(GroupPost.created_at)).limit(limit)
).all()
feed_items = []
for r in reviews:
feed_items.append(FeedItem(
type="review",
timestamp=r.created_at or datetime.utcnow(),
data=r,
user=get_user_display(session, r.user_id),
entity=get_entity_info(session, r)
))
for a in attendance:
show = session.get(Show, a.show_id) if a.show_id else None
entity_info = None
if show:
entity_info = {
"type": "show",
"slug": show.slug,
"title": show.date.strftime("%Y-%m-%d") if show.date else "Unknown",
}
feed_items.append(FeedItem(
type="attendance",
timestamp=a.created_at,
data=a,
user=get_user_display(session, a.user_id),
entity=entity_info
))
for p in posts:
feed_items.append(FeedItem(
type="post",
timestamp=p.created_at,
data=p,
user=get_user_display(session, p.user_id),
entity=None
))
# Sort by timestamp desc
feed_items.sort(key=lambda x: x.timestamp, reverse=True)
return feed_items[:limit]

Some files were not shown because too many files have changed in this diff Show more