-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
PHP Version
8.4
CodeIgniter4 Version
4.6.3
CodeIgniter4 Installation Method
Composer (using codeigniter4/appstarter)
Which operating systems have you tested for this bug?
Linux
Which server did you use?
fpm-fcgi
Database
MariaDB 10.11.14
What happened?
Running php spark make:migration --session generates a migration with invalid Database Forge array syntax.
The timestamp field uses a raw SQL string as an array key without a value:
'timestamp timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL'
This causes the migration to create an incorrectly structured ci_sessions table with timestamp as int(10) unsigned instead of TIMESTAMP type, leading to session corruption and random user logouts in Shield authentication.
Steps to Reproduce
- Run command:
php spark make:migration --session - Navigate to app/Database/Migrations/ and open the generated migration file
- Observe the malformed timestamp field syntax in the addField array
- Run:
php spark migrate - Check the ci_sessions table structure:
SHOW CREATE TABLE ci_sessions; - Confirm timestamp column is created as int(10) unsigned instead of TIMESTAMP
- Attempt to use database sessions - sessions will store corrupted timestamp values (e.g., 4294967295) causing Shield to invalidate DB sessions and log users out randomly
Expected Output
The migration template at system/Commands/Generators/Views/migration.tpl.php should use valid Database Forge array syntax for all fields. Specifically, this line:
'timestamp timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL',
Should be replaced with proper array syntax:
'timestamp' => ['type' => 'TIMESTAMP', 'null' => false],
Then after table creation in the template, add a raw query to set the default value since Forge doesn't support DEFAULT CURRENT_TIMESTAMP in field definitions:
$this->forge->createTable('', true);
$this->db->query('ALTER TABLE MODIFY timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL');
$this->db->query('ALTER TABLE ALTER COLUMN timestamp SET DEFAULT CURRENT_TIMESTAMP');
This will create the ci_sessions table with the correct structure:
- id: varchar(128) NOT NULL, PRIMARY KEY
- ip_address: varchar(45) NOT NULL
- timestamp: TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
- data: BLOB NOT NULL
- KEY on timestamp
The timestamp column will then store actual TIMESTAMP values that Shield can properly validate for session management.
Anything else?
No response