Skip to content

[Refactor] Feature flag store uses in-memory Map — resets to seed data on every server restart #773

Description

@RUKAYAT-CODER

Overview

src/lib/feature-flags/store.ts stores all feature flags in a module-level Map and seeds it with hard-coded values on startup. Any flags created or modified via the admin UI are lost when the server restarts, making the feature flag system unreliable for production use.

Specifications

Features:

  • Feature flags are stored in the database and loaded on startup
  • Flag mutations are immediately persisted
  • The admin UI reflects the true persisted state after a restart

Tasks:

  • Create a feature_flags table with columns for id, name, description, enabled, strategy, percentage, rules (JSONB), tags, created_at, updated_at, created_by
  • Implement getFlagById(), getAllFlags(), createFlag(), updateFlag(), deleteFlag() as SQL-backed functions
  • Seed the table via a database migration instead of runtime code
  • Update the route handlers to use the database functions

Impacted Files:

  • src/lib/feature-flags/store.ts
  • src/app/api/admin/feature-flags/route.ts
  • src/lib/db/ (new migration)

Acceptance Criteria

  • Feature flags survive server restarts
  • Creating a flag via the API persists it to the database
  • Seed flags are applied via migration, not runtime code

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions