feat(store): fist stepts for implement ContributionStore for managing contributions in SQLite

This commit is contained in:
2026-07-08 06:50:56 +02:00
parent cb89a1c6b9
commit 3d2c0487b7
2 changed files with 37 additions and 1 deletions
+2 -1
View File
@@ -121,7 +121,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
* }
* @psalm-type ServicesConfig = array{
* _defaults?: DefaultsType,
* _instanceof?: InstanceofType,
* _instanceof?: array<class-string, InstanceofType>,
* ...<string, DefinitionType|AliasType|PrototypeType|StackType|ArgumentsType|null>
* }
* @psalm-type ExtensionType = array<string, mixed>
@@ -857,6 +857,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
* http_errors?: bool|Param,
* expect?: mixed,
* ssl_key?: mixed,
* force_ip_resolve?: mixed, // Default: null
* stream?: bool|Param,
* synchronous?: bool|Param,
* read_timeout?: scalar|Param|null,
+35
View File
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace App\Service;
use PDO;
class ContributionStore {
private PDO $pdo;
public function __construct(
private readonly string $dbPath = "%kernel.project_dir%/var/data/contributions.db",
private readonly ?int $retentionDays = null,
){
if(!is_dir(\dirname($this->dbPath))){
mkdir(\dirname($this->dbPath), 0755, recursive: true);
}
$this->pdo = new PDO('sqlite:' . $this->dbPath);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$this->prepareSchema();
}
private function prepareSchema():void{
$this->pdo->exec('
CREATE TABLE IF NOT EXISTS contributions (
provider TEXT NOT NULL,
date TEXT NOT NULL,
count INTEGER NOT NULL CHECK (count >= 0),
PRIMARY KEY (provider, date)
) WITHOUT ROWID, STRICT
');
}
}