Commit Graph

11 Commits

Author SHA1 Message Date
Oleg Proskurin 88cb1f2c61 fix: upload 2025-11-24 00:14:46 +07:00
Oleg Proskurin 6235736f4f fix: flow creation 2025-11-23 14:34:54 +07:00
Oleg Proskurin 1ad5b483ef feat: phase 3 part 1 - live scopes database schema and service
Implement foundation for live URL system with database schema, relations,
and comprehensive service layer for live scope management.

**Database Schema (Section 8.4):**
- **liveScopes table** with fields:
  - id (UUID primary key)
  - projectId (foreign key to projects, cascade delete)
  - slug (text, unique within project)
  - allowNewGenerations (boolean, default: true)
  - newGenerationsLimit (integer, default: 30)
  - meta (JSONB for flexible metadata)
  - createdAt, updatedAt timestamps

- **Constraints & Indexes:**
  - Unique constraint on (projectId, slug) combination
  - Index for project lookups
  - Index for project+slug lookups

- **Relations:**
  - projects → liveScopes (one-to-many)
  - liveScopes → project (many-to-one)

**Type Definitions:**
- Added LiveScope, NewLiveScope types from database schema
- Added LiveScopeWithStats interface with computed fields:
  - currentGenerations: number (count of images in scope)
  - lastGeneratedAt: Date | null (latest generation timestamp)
  - images?: Image[] (optional images array)
- Added LiveScopeFilters interface for query filtering

**LiveScopeService:**
- **Core CRUD operations:**
  - create() - Create new scope
  - getById() - Get scope by UUID
  - getBySlug() - Get scope by slug within project
  - getByIdOrThrow() / getBySlugOrThrow() - With error handling
  - update() - Update scope settings
  - delete() - Hard delete scope (images preserved)

- **Statistics & Computed Fields:**
  - getByIdWithStats() - Scope with generation count and last generated date
  - getBySlugWithStats() - Same but lookup by slug
  - list() - Paginated list with stats for each scope

- **Business Logic:**
  - canGenerateNew() - Check if scope allows new generations
  - createOrGet() - Lazy creation with project defaults
  - Uses images.meta field for scope tracking (scope, isLiveUrl)

**Technical Notes:**
- Images track scope via meta.scope field (no schema changes to images table)
- Scope statistics computed from images where meta.scope = slug and meta.isLiveUrl = true
- Project settings (allowNewLiveScopes, newLiveScopesGenerationLimit) already added in Phase 2
- All code compiles with zero new TypeScript errors

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 22:50:20 +07:00
Oleg Proskurin 9b9c47e2bf feat: phase 2 part 1 - schema changes, regeneration, and lazy flows
**Database Schema Changes (Section 2.1):**
- Rename generations.enhancedPrompt → generations.prompt (prompt used for generation)
- Rename generations.originalPrompt semantics → user's original (only if enhanced)
- Reverse semantics: prompt = what was used, originalPrompt = preserved user input
- Add projects.allowNewLiveScopes (BOOLEAN, default: true)
- Add projects.newLiveScopesGenerationLimit (INTEGER, default: 30)

**Prompt Semantics Update:**
- If autoEnhance=false: prompt=user input, originalPrompt=null
- If autoEnhance=true: prompt=enhanced, originalPrompt=user input
- Updated GenerationService.create() to implement new logic
- Updated retry() and update() methods to use new prompt field

**Regeneration Refactoring (Section 3):**
- Add POST /api/v1/generations/:id/regenerate endpoint
- Remove status checks (allow regeneration for any status)
- Remove retry count logic (no longer tracked)
- Remove parameter overrides (uses exact same params as original)
- Updates existing image (same imageId, storageKey, storageUrl)
- Keep /retry endpoint for backward compatibility (delegates to regenerate)
- GenerationService.regenerate() method created
- Physical file in MinIO overwritten by ImageGenService

**Flow Regeneration (Section 3.6):**
- Add POST /api/v1/flows/:id/regenerate endpoint
- Regenerates most recent generation in flow
- Returns FLOW_HAS_NO_GENERATIONS error if flow is empty
- Uses parameters from last generation

**Lazy Flow Creation (Section 4.3):**
- Remove POST /api/v1/flows endpoint (commented out with explanation)
- Flows now created automatically when:
  - Generation/upload specifies a flowId
  - Generation/upload provides flowAlias (eager creation)
- Eager creation logic already implemented in Phase 1

**Technical Notes:**
- All Phase 2 Part 1 changes maintain data integrity
- No migration needed (dev mode per user confirmation)
- Regeneration preserves image metadata (alias, createdAt, etc.)
- Processing time tracked for regeneration

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 01:43:49 +07:00
Oleg Proskurin 047c924193 fix: update schemes 2025-10-26 23:14:05 +07:00
Oleg Proskurin dbf82d2801 feat: update DB schemas 2025-10-26 23:00:10 +07:00
Oleg Proskurin dd48d4e1a1 feat: update setup 2025-10-12 21:12:58 +07:00
Oleg Proskurin df6596d53c chore: prettier 2025-10-09 23:16:42 +07:00
Oleg Proskurin bfff9b49ec fix: org project and apikey creating 2025-10-05 18:45:15 +07:00
Oleg Proskurin bd0cf2d70a feat: add keys pages 2025-10-03 00:14:02 +07:00
Oleg Proskurin 298898f79d feat: implement apikey auth 2025-10-01 00:14:14 +07:00