Skip to content

Commit

Permalink
Fix for generating session table structure via migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsn committed Jun 26, 2021
1 parent f072c86 commit cd4ad9d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
9 changes: 5 additions & 4 deletions system/Commands/Generators/MigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 15 additions & 9 deletions system/Commands/Generators/Views/migration.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
<?php if ($DBDriver === 'MySQLi'): ?>
'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],
<?php elseif ($DBDriver === 'Postgre'): ?>
'ip_address inet NOT NULL',
'timestamp timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL',
"data bytea DEFAULT '' NOT NULL",
<?php endif; ?>
]);
<?php if ($matchIP) : ?>
$this->forge->addKey(['id', 'ip_address'], true);
<?php else: ?>
$this->forge->addKey('id', true);
<?php endif ?>
$this->forge->addKey('timestamp');
<?php if ($matchIP) : ?>
$this->forge->addKey(['id', 'ip_address'], true);
<?php else: ?>
$this->forge->addKey('id', true);
<?php endif ?>
$this->forge->addKey('timestamp');
$this->forge->createTable('<?= $table ?>', true);
}

Expand Down

0 comments on commit cd4ad9d

Please sign in to comment.