Skip to content
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

[maintenance] - Store sessions in database instead of files #863

Open
wants to merge 3 commits into
base: 1.12
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ parameters:

doctrine:
dbal:
schema_filter: '~^(?!messenger_messages|sessions)~'
url: '%env(resolve:DATABASE_URL)%'

orm:
auto_generate_proxy_classes: '%kernel.debug%'
entity_managers:
Expand Down
2 changes: 1 addition & 1 deletion config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ framework:
legacy_error_messages: false
csrf_protection: true
session:
handler_id: ~
handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
serializer:
mapping:
paths: [ '%kernel.project_dir%/config/serialization' ]
Expand Down
4 changes: 4 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ services:
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']

Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler:
arguments:
$pdoOrDsn: '%env(DATABASE_URL)%'
2 changes: 0 additions & 2 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ services:
SYLIUS_MESSENGER_TRANSPORT_CATALOG_PROMOTION_REMOVAL_FAILED_DSN: doctrine://default?queue_name=catalog_promotion_removal_failed
PHP_DATE_TIMEZONE: ${PHP_DATE_TIMEZONE:-UTC}
volumes:
# use a bind-mounted host directory, as we want to keep the sessions
- ./var/sessions:/srv/sylius/var/sessions:rw
# use a bind-mounted host directory, as we want to keep the media
- ./public/media:/srv/sylius/public/media:rw
networks:
Expand Down
2 changes: 1 addition & 1 deletion docker/php/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [ "${1#-}" != "$1" ]; then
fi

if [ "$1" = 'php-fpm' ] || [ "$1" = 'bin/console' ]; then
mkdir -p var/cache var/log var/sessions public/media
mkdir -p var/cache var/log public/media
setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var public/media
setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var public/media

Expand Down
33 changes: 33 additions & 0 deletions src/Migrations/Version20221101193636.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace App\Migrations;

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

final class Version20221101193636 extends AbstractMigration
{
public function up(Schema $schema): void
{
$sql = <<<SQL
CREATE TABLE sessions (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we need some config like this?

doctrine:
    dbal:
        connections:
            default:
                schema_filter: ~^(?! 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;
$this->addSql($sql);
}

public function down(Schema $schema): void
{
$sql = <<<SQL
DROP TABLE sessions;
SQL;
$this->addSql($sql);
}
}
Loading