Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Database Activator Laravel Package

flagception/database-activator

Doctrine DBAL-backed activator for Flagception feature flags. Stores flag state in a SQL database (MySQL/Postgres/SQLite), auto-creates the table, and supports connection arrays, DSNs, or an existing DBAL instance, with customizable table/column names.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Feature Flag Persistence: Perfectly aligns with Flagception SDK’s need for a database-backed activator, eliminating reliance on in-memory or file-based storage. Ideal for distributed systems where state consistency is critical.
  • Decoupled Design: The activator abstracts persistence logic, allowing FeatureManager to remain storage-agnostic. Enables future swaps (e.g., Redis caching layer) without core logic changes.
  • Extensibility: Customizable table/column names support schema alignment with existing databases (e.g., shared schemas in microservices) or multi-tenant setups with tenant-aware configurations.
  • Laravel Synergy: Leverages Doctrine DBAL, a first-class citizen in Laravel’s ecosystem, reducing friction for teams already using Laravel’s database tools.

Integration Feasibility

  • Low Coupling: Requires only Flagception SDK (v2.0+) and DBAL (v4.0+), both mature and widely adopted in PHP/Laravel stacks.
  • Schema Automation: Auto-creates the flagception_features table (or custom schema), minimizing manual setup. Reduces deployment complexity for CI/CD pipelines.
  • Connection Flexibility: Supports DSN strings, array configs, or pre-initialized DBAL instances, accommodating:
    • CI/CD environments (test DBs with ephemeral connections).
    • Production setups (connection pooling, failover).
    • Hybrid architectures (e.g., serverless with RDS proxies).

Technical Risk

Risk Area Severity Mitigation Strategy
DBAL Version Lock Medium Pin doctrine/dbal:^4.0 in composer.json to avoid breaking changes.
PHP 7.4+ Dependency Low Most modern Laravel apps (8+) already meet this; upgrade path is straightforward.
PostgreSQL Quirks Low Parametrized queries (v1.1.1+) mitigate SQL injection risks; test with your dialect.
Schema Conflicts Medium Validate table/column names pre-deployment (e.g., via Laravel migrations).
Connection Resilience High Implement retry logic (e.g., exponential backoff) for DB failures. Use DBAL’s built-in connection pooling.
Flagception SDK Drift Medium Monitor Flagception’s changelog for activator interface changes; test upgrades early.

Key Questions

  1. Database Schema Strategy:

    • Should the flagception_features table be shared across services (monolith) or service-specific (microservices)?
      • Impact: Shared tables may need row-level security or namespace prefixes (e.g., service1_feature).
    • Should the schema include additional metadata (e.g., description, environment, created_at)?
      • Example: Extend the table for auditability or multi-environment support.
  2. Performance at Scale:

    • How will read/write latency scale with 100K+ flags?
      • Optimizations:
        • Index the feature column.
        • Add a Redis caching layer for frequent flags (e.g., flagception:flags).
        • Use DBAL’s connection pooling for high-throughput apps.
    • Benchmark: Test with load tests (e.g., 10K RPS) to validate thresholds.
  3. Disaster Recovery:

    • What’s the RTO/RPO for flag data?
      • Requirements:
        • Database backups (e.g., daily snapshots).
        • Replication (e.g., PostgreSQL streaming replication, MySQL binlog).
        • Failover testing (e.g., simulate DB outages).
    • Tooling: Leverage DBAL’s connection failover for HA setups.
  4. Flagception SDK Compatibility:

    • Will future Flagception SDK updates break compatibility with this activator?
      • Mitigation:
        • Subscribe to Flagception’s release notes.
        • Test activator changes in a staging environment pre-upgrade.
    • Can this activator support Flagception’s advanced features (e.g., user segments, gradual rollouts)?
      • Note: The activator handles persistence only; evaluation logic remains in the SDK.
  5. Auditability and Compliance:

    • Are flag changes logged (e.g., updated_at, updated_by)?
      • Solution: Extend the schema or add a separate audit table (e.g., feature_flag_audit).
    • Does this meet compliance requirements (e.g., GDPR, SOC2) for flag management?
      • Consider: Add data retention policies (e.g., soft delete flags after 1 year).
  6. Multi-Environment Management:

    • How will flags be environment-specific (e.g., prod, staging)?
      • Options:
        • Single table with environment column (simplest).
        • Separate tables per environment (e.g., feature_flags_prod).
        • Flagception’s built-in environment variables (e.g., FEATURE_ENV=prod).

Integration Approach

Stack Fit

  • Laravel Native Integration:

    • Service Provider: Register the activator in config/flagception.php:
      'activator' => \Flagception\DatabaseActivator::class,
      'activator_config' => [
          'connection' => env('DB_CONNECTION', 'mysql'),
          'table' => 'feature_flags',
          'options' => [
              'db_column_state' => 'is_enabled',
          ],
      ],
      
    • Eloquent Alternative: For Laravel-heavy apps, consider Eloquent-based activators (e.g., spatie/laravel-feature-flags) if you prefer ORM over DBAL.
    • Query Builder: Use Laravel’s DB facade for custom queries:
      $flags = DB::table('feature_flags')->where('environment', 'prod')->get();
      
  • Microservices:

    • Shared Database: Use a dedicated schema (e.g., feature_flags) to avoid collisions. Add a service_name column for multi-service support.
    • Service-Specific: Prefix flags (e.g., auth_* for auth service) or use multi-tenancy (e.g., tenant_id column).
    • Event-Driven: Publish flag change events (e.g., flag.updated) for downstream services to react.
  • Serverless:

    • Connection Management: Use RDS proxies or environment variables for DB connections.
    • Cold Starts: Cache flags in Lambda layers or API Gateway responses to reduce DB calls.

Migration Path

  1. Pilot Phase (Low Risk):

    • Migrate non-critical features (e.g., experimental flags) first.
    • Use Flagception’s fallback activator for graceful degradation:
      $manager = new FeatureManager(
          new DatabaseActivator($dbal),
          new InMemoryActivator(['default' => false]) // Fallback to false
      );
      
    • Validation: Compare flag states between old and new systems.
  2. Schema Migration:

    • Option A: Auto-Create Tables (Simplest):
      • Let the activator handle schema creation. Test in staging first.
    • Option B: Custom Schema (More Control):
      • Pre-create the table with additional columns:
        CREATE TABLE feature_flags (
            feature VARCHAR(255) PRIMARY KEY,
            state BOOLEAN NOT NULL,
            environment ENUM('prod', 'staging', 'dev') DEFAULT 'prod',
            description TEXT,
            created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
            updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
        );
        
      • Use Laravel migrations for version control:
        Schema::create('feature_flags', function (Blueprint $table) {
            $table->string('feature')->primary();
            $table->boolean('state')->default(false);
            $table->enum('environment', ['prod', 'staging', 'dev'])->default('prod');
            $table->text('description')->nullable();
            $table->timestamps();
        });
        
  3. Data Migration:

    • Export existing flags (e.g., from JSON/YAML/environment variables) into the database:
      $activator = new DatabaseActivator($dbal);
      $flags = json_decode(file_get_contents('flags.json'), true);
      foreach ($flags as $feature => $state) {
          $activator->setFeature($feature, $state);
      }
      
    • Validation Script: Compare old vs. new flag states:
      $oldFlags = include 'old_flags.php';
      $newFlags = collect(
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity