Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions docs/PRISMA_MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Prisma Migration Guide — Lucky

This document covers running Prisma migrations on the Lucky homelab database.

## Setup

Lucky uses **Prisma 7** with a PostgreSQL database. Schema lives at `prisma/schema.prisma`. Migrations are in `prisma/migrations/`.

Environment variable required:

```
DATABASE_URL=postgresql://user:password@host:5432/lucky
```

On the homelab this is set in the bot/backend Docker Compose env files or `.env`.

## Running migrations

```bash
# Apply all pending migrations
npx prisma migrate deploy

# Check migration status
npx prisma migrate status

# Generate Prisma client after schema changes
npx prisma generate
```

`migrate deploy` is the correct command for production/homelab — it applies pending migrations without prompting and never creates new ones.

## v2.8.0 — GlobalFeatureToggle table

Migration: `20260504000000_add_global_feature_toggles`

```sql
CREATE TABLE "global_feature_toggles" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"enabled" BOOLEAN NOT NULL,
CONSTRAINT "global_feature_toggles_pkey" PRIMARY KEY ("id")
);

CREATE UNIQUE INDEX "global_feature_toggles_name_key" ON "global_feature_toggles"("name");
```

**Purpose:** Stores per-flag DB overrides for the feature toggle system. The `FeatureToggleService` resolution order is: DB override → Vercel Flags → env fallback. When a row exists for a flag name, it takes precedence over Vercel/env values.

**Populated by:** The admin panel (`POST /api/toggles/global/:name`) or directly via Prisma upsert. Table starts empty — all flags fall through to Vercel/env until explicitly overridden.

**Flags:** 19 flags defined in `packages/shared/src/config/featureToggles.ts` (AUTOPLAY, LYRICS, MUSIC_RECOMMENDATIONS, ARTIST_COMMAND, ALBUM_COMMAND, etc.).

## Applying the v2.8.0 migration on homelab

```bash
# On the homelab server (or via SSH)
cd /path/to/Lucky
DATABASE_URL="postgresql://..." npx prisma migrate deploy
```

Expected output:
```
Applying migration `20260504000000_add_global_feature_toggles`
The following migration(s) have been applied:
migrations/
└─ 20260504000000_add_global_feature_toggles/
└─ migration.sql
```

After applying, restart the backend service so the new table is available.

## Baseline migration note

The project uses a baseline migration (`20250101000000_baseline`) that captures the pre-Prisma schema state. If setting up a new database from scratch, Prisma will apply all migrations in order, including the baseline. For an existing database that predates Prisma migration tracking, mark the baseline as applied first:

```bash
npx prisma migrate resolve --applied 20250101000000_baseline
```

Then run `migrate deploy` to apply only the subsequent migrations.
18 changes: 16 additions & 2 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
# Roadmap — Lucky

_Auto-regenerated 2026-04-15 from `docs/specs/`._
_Refreshed 2026-05-04. Version: v2.8.0._

## Now (active)

_(none)_
- **Admin panel global toggles** — PR [#801](https://github.com/LucasSantana-Dev/Lucky/pull/801) in review. Self-serve guild feature flag management via web dashboard. Backend complete (`GlobalFeatureToggle` table, `requireAdmin` guard). Frontend form done.

## Next (proposed)

- **queueManipulation.ts modularisation** — Split 953-LOC hotspot into `candidateSelection.ts`, `queueOrchestration.ts`, `queueEditOps.ts`. Unblocks multiple downstream refactors.
- **autoplay.ts split** — 1,074-LOC command file → `autoplaySettings.ts`, `autoplayDiversity.ts`, `autoplaySeeding.ts`.
- **Prisma homelab migration guide** — Document `GlobalFeatureToggle` table migration for homelab DB (Phase 3 prerequisite).
- **2026-04-15-autoplay-diversity** _(proposed)_ `autoplay,music,quality`
- **2026-04-24-autoplay-genre-locale** _(proposed)_ `autoplay,music,i18n`

## Deferred

- **Phase 3: Stripe premium service** — Feature toggle placeholder active (`premiumService.isPremium`). DB schema staged. Deferred pending Phase 2 revenue validation.
- **GuildAutomationExecutionService event-driven refactor** — 1,238-LOC service. Candidate for event emitter pattern. Post-v2.9.
- **AutoMod.tsx decompose** — 984-LOC React component → 3-way split. Low priority.

## Recently shipped

- **v2.8.0: /artist and /album commands** — Last.fm-powered artist/album browsing with feature toggle gates. PR [#800](https://github.com/LucasSantana-Dev/Lucky/pull/800), [#799](https://github.com/LucasSantana-Dev/Lucky/pull/799).
- **v2.7.0: Vercel feature flags migration** — Replaced Unleash with Vercel FeatureFlags. 19 flags live. PR [#796](https://github.com/LucasSantana-Dev/Lucky/pull/796).
- **Autoplay Phase 1+2** — `/artist`, `/album`, diversity scaling, Last.fm tag scoring, autoplay seed/diversity subcommands.
- **RBAC + guild access controls** — Role-based per-module permissions with `requireGuildModuleAccess` middleware.
- **2026-04-15-internal-notify-endpoint** _(shipped)_ `rag,backend,homelab` → PR: https://github.com/LucasSantana-Dev/Lucky/pull/625
Loading