This package add a new datastore with Doctrine/DBAL library through a SimpleSAMLphp module installable through Composer. Installation can be as easy as executing:
composer require sgomez/simplesamlphp-module-dbal ~1.0 # for SSP >= 1.14
composer require sgomez/simplesamlphp-module-dbal ~2.0 # for SSP >= 2.0|master
You need to specify the next store.type on your config file:
'store.type' => 'SimpleSAML\Modules\DBAL\Store\DBAL',
And copy the template config file from modules/dbal/config-templates/module_dbal.php
to your config base directory.
You must edit it with your database connection configuration.
This module supports the same engines than Doctrine/DBAL. See Doctrine DBAL configuration for the syntax.
$config = array (
'store.dbal.url' => 'mysql://user:password@localhost:3306/simplesamlphp?charset=utf8mb4&serverVersion=5.7',
// 'store.dbal.url' => 'sqlite:///simplesamlphp.sqlite',
);
If you want to clean old keys automatically, remember to enable and configure the cron module.
The schema is not created every time than Store is called (like SQL store). You need to created it manually. You need to run this every time you install or update a module than use DBAL Store:
bash$ vendor/bin/dbalschema
If you want to create your own schema to your module, you need to create a hook_dbal.php
file on your hooks directory.
This file will run every time than dbalschema is launched.
This is a template:
<?php
function modulename_hook_dbal(&$dbinfo)
{
$store = SimpleSAML_Store::getInstance();
if (! $store instanceof \SimpleSAML\Modules\DBAL\Store\DBAL ) {
throw new \SimpleSAML_Error_Exception('OAuth2 module: Only DBAL Store is supported');
}
$schema = new \Doctrine\DBAL\Schema\Schema();
$fooTable = $store->getPrefix().'_foo';
$foo = $schema->createTable($fooTable);
$foo->addColumn('id', 'string', [ 'length' => 255 ]);
$foo->addColumn('name', 'string', [ 'length' => 255 ]);
$foo->setPrimaryKey(['id']);
$barTable = $store->getPrefix().'_bar';
$bar = $schema->createTable($barTable);
$bar->addColumn('id', 'string', [ 'length' => 255 ]);
$bar->addColumn('expires_at', 'datetime');
$bar->addColumn('foo_id', 'string', [ 'length' => 255 ]);
$bar->setPrimaryKey(['id']);
$bar->addForeignKeyConstraint($foo, ['foo_id'], ['id'], ['onDelete' => 'CASCADE']);
$store->createOrUpdateSchema($schema, $store->getPrefix().'_modulename');
$dbinfo['summary'][] = 'Created ModuleName Schema';
}
Doctrine DBAL is able to update your schema in almost any case without drop it. To know all types and options see Doctrine DBAL Documentation.