Skip to content

Store sessions in database, allowing to load balance web servers. #1654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions webapp/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ doctrine:
judge_task_type: App\Doctrine\DBAL\Types\JudgeTaskType
mapping_types:
enum: string
schema_filter: ~^(?!sessions)~
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
Expand Down
2 changes: 1 addition & 1 deletion webapp/config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ framework:
fragments: ~

session:
handler_id: ~
handler_id: "%env(DATABASE_URL)%"
cookie_secure: auto
cookie_samesite: lax
storage_factory_id: session.storage.factory.native
Expand Down
45 changes: 45 additions & 0 deletions webapp/migrations/Version20220816125435.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*
* Source: https://symfony.com/doc/current/session/database.html#store-sessions-in-a-relational-database-mariadb-mysql-postgresql
*/
final class Version20220816125435 extends AbstractMigration
{
public function getDescription(): string
{
return 'Create a table to store sessions';
}

public function up(Schema $schema): void
{
$this->addSql(<<<SQL
CREATE TABLE `sessions` (
`sess_id` VARBINARY(128) NOT NULL PRIMARY KEY,
`sess_data` BLOB NOT NULL,
`sess_lifetime` INTEGER UNSIGNED NOT NULL,
`sess_time` INTEGER UNSIGNED NOT NULL,
INDEX `sessions_sess_lifetime_idx` (`sess_lifetime`)
) COLLATE utf8mb4_bin, ENGINE = InnoDB
SQL
);
}

public function down(Schema $schema): void
{
$this->addSql('DROP TABLE `sessions`');
}

public function isTransactional(): bool
{
return false;
}
}