You can manage your feature toggles via a database. The following database vendors are currently supported:
- MySQL
- Oracle
- Microsoft SQL Server
- PostgreSQL
- SAP Sybase SQL Anywhere
- SQLite
The bundle will use the database activator.
The DatabaseActivator
is not included by default. Therefore, you must first insert this via Composer as a dependency.
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require flagception/database-activator
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Then, enable the activator in your config and set database credentials.
# config.yml
flagception:
activators:
database:
# Enable database activator (default: false)
enable: true
# Connection string
url: 'mysql://user:secret@localhost/mydb'
You can fill a connection string (url), a PDO instance, a DBAL instance or old-fashioned the individual credentials fields.
# config.yml
flagception:
activators:
database:
# Enable database activator (default: false)
enable: true
# Connection string
url: 'mysql://user:secret@localhost/mydb'
# config.yml
flagception:
activators:
database:
# Enable database activator (default: false)
enable: true
# By pdo instance
pdo: 'pdo.service.id'
# config.yml
flagception:
activators:
database:
# Enable database activator (default: false)
enable: true
# By dbal instance
dbal: 'dbal.service.id'
# config.yml
flagception:
activators:
database:
# Enable database activator (default: false)
enable: true
# By credentials field
credentials:
dbname: 'mydb',
user: 'user',
password: 'secret', # You can use env too (%env(MYSQL_DATABASE)%)
host: 'localhost',
driver: 'pdo_mysql'
The DatabaseActivator
will automatically create a table for storing the feature states if this not already exists.
By default, the table name is flagception_features
which contains the columns feature
and state
.
You can change the tables and / or column names in your option config:
# config.yml
flagception:
activators:
database:
# Enable database activator (default: false)
enable: true
# Connection string
url: 'mysql://user:secret@localhost/mydb'
# Rename table and columns
options:
db_table: 'my_table'
db_column_feature: 'my_cool_feature_name'
db_column_state: 'my_current_feature_state'
This queries status from a database, which can negatively impact performance. Therefore, you can set up a cache for this activator. Identical feature queries are then loaded from the cache instead of being retrieved from the database. All you have to do is specify a cache pool and cache interval.
By default, the cache is disabled.
Example:
# config.yml
flagception:
activators:
database:
enable: true
# ...
cache:
# Enable the cache option (default: false)
enable: true
# Set cache pool (default: cache.app)
pool: cache.app
# Set lifetime for cache in seconds (default: 3600)
lifetime: 3600