From cd4ad9d836b08e85b0dfa68a417026d85aef10e2 Mon Sep 17 00:00:00 2001 From: michalsn Date: Sat, 26 Jun 2021 11:14:18 +0200 Subject: [PATCH] Fix for generating session table structure via migrations --- .../Generators/MigrationGenerator.php | 9 +++---- .../Generators/Views/migration.tpl.php | 24 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/system/Commands/Generators/MigrationGenerator.php b/system/Commands/Generators/MigrationGenerator.php index 23cdf7f62725..96c12d17f0a6 100644 --- a/system/Commands/Generators/MigrationGenerator.php +++ b/system/Commands/Generators/MigrationGenerator.php @@ -107,10 +107,11 @@ protected function prepare(string $class): string $table = $this->getOption('table'); $DBGroup = $this->getOption('dbgroup'); - $data['session'] = true; - $data['table'] = is_string($table) ? $table : 'ci_sessions'; - $data['DBGroup'] = is_string($DBGroup) ? $DBGroup : 'default'; - $data['matchIP'] = config('App')->sessionMatchIP; + $data['session'] = true; + $data['table'] = is_string($table) ? $table : 'ci_sessions'; + $data['DBGroup'] = is_string($DBGroup) ? $DBGroup : 'default'; + $data['DBDriver'] = config('Database')->{$data['DBGroup']}['DBDriver']; + $data['matchIP'] = config('App')->sessionMatchIP; } return $this->parseTemplate($class, [], [], $data); diff --git a/system/Commands/Generators/Views/migration.tpl.php b/system/Commands/Generators/Views/migration.tpl.php index 436ee85e04cc..321895e670c2 100644 --- a/system/Commands/Generators/Views/migration.tpl.php +++ b/system/Commands/Generators/Views/migration.tpl.php @@ -12,17 +12,23 @@ class {class} extends Migration public function up() { $this->forge->addField([ - 'id' => ['type' => 'VARCHAR', 'constraint' => 128, 'null' => false], + 'id' => ['type' => 'VARCHAR', 'constraint' => 128, 'null' => false], + 'ip_address' => ['type' => 'VARCHAR', 'constraint' => 45, 'null' => false], - 'timestamp' => ['type' => 'INT', 'unsigned' => true, 'null' => false, 'default' => 0], - 'data' => ['type' => 'TEXT', 'null' => false, 'default' => ''], + 'timestamp timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL', + 'data' => ['type' => 'BLOB', 'null' => false], + + 'ip_address inet NOT NULL', + 'timestamp timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL', + "data bytea DEFAULT '' NOT NULL", + ]); - - $this->forge->addKey(['id', 'ip_address'], true); - - $this->forge->addKey('id', true); - - $this->forge->addKey('timestamp'); + + $this->forge->addKey(['id', 'ip_address'], true); + + $this->forge->addKey('id', true); + + $this->forge->addKey('timestamp'); $this->forge->createTable('', true); }