diff options
| -rw-r--r-- | Digitigrade/Model/Session.php | 2 | ||||
| -rwxr-xr-x | bin/cleandb | 3 | ||||
| -rw-r--r-- | migrations/20250119_233507_add_session_created.php | 8 |
3 files changed, 13 insertions, 0 deletions
diff --git a/Digitigrade/Model/Session.php b/Digitigrade/Model/Session.php index 07827c0..d6beb19 100644 --- a/Digitigrade/Model/Session.php +++ b/Digitigrade/Model/Session.php @@ -7,11 +7,13 @@ use Digitigrade\Model; class Session extends Model { public string $token; public UserAccount $userAccount; + public \DateTimeImmutable $created; public static function create(UserAccount $user): self { $session = new self(); $session->userAccount = $user; $session->token = random_printable_bytes(); + $session->created = new \DateTimeImmutable(); $session->save(); return $session; } diff --git a/bin/cleandb b/bin/cleandb index 4aa7b37..44f55f2 100755 --- a/bin/cleandb +++ b/bin/cleandb @@ -16,5 +16,8 @@ DELETE FROM interaction WHERE deleted = true; DELETE FROM home_timeline_item WHERE modified < (current_timestamp - interval '6 months'); DELETE FROM notification WHERE created < (current_timestamp - interval '1 month'); +-- throw away old sessions that would be too old anyway +DELETE FROM session WHERE created < (current_timestamp - interval '1 year'); + END); $db->commit();
\ No newline at end of file diff --git a/migrations/20250119_233507_add_session_created.php b/migrations/20250119_233507_add_session_created.php new file mode 100644 index 0000000..c4978cb --- /dev/null +++ b/migrations/20250119_233507_add_session_created.php @@ -0,0 +1,8 @@ +<?php + +use \Digitigrade\Db\Migrator; + +Migrator::getInstance()->register(20250119_233507, function (PDO $db) { + // track when sessions were created so they can be tidied up after some time + $db->exec('ALTER TABLE session ADD COLUMN created timestamp with time zone not null default current_timestamp'); +}); |
