Skip to content

Instantly share code, notes, and snippets.

@mcanvar
Forked from harris21/Migration Create Sessions
Last active August 22, 2016 11:17
Show Gist options
  • Save mcanvar/ee60c2899f7280180dcfb283182fdd30 to your computer and use it in GitHub Desktop.
Save mcanvar/ee60c2899f7280180dcfb283182fdd30 to your computer and use it in GitHub Desktop.
Create CodeIgniter Sessions Migration
<?php
/**
* Created by PhpStorm.
* User: mevlutcanvar@gmail.com
* Date: 22.08.2016
* Time: 04:58
*/
class Migration_Create_Sessions extends CI_Migration {
public function up()
{
// Drop table 'ci_sessions' if it exists
$this->dbforge->drop_table('ci_sessions', TRUE);
// Table structure for table 'groups'
$this->dbforge->add_field(array(
'id' => array(
'type' => 'VARCHAR',
'constraint' => '40',
'null' => FALSE
),
'ip_address' => array(
'type' => 'VARCHAR',
'constraint' => '45',
'null' => FALSE
),
'timestamp' => array(
'type' => 'INT',
'constraint' => '10',
'unsigned' => TRUE,
'default' => 0,
'null' => FALSE
),
'data' => array(
'type' => 'blob',
'null' => FALSE
)
));
$this->dbforge->create_table('ci_sessions');
$this->db->query('CREATE INDEX `ci_sessions_timestamp` ON `ci_sessions` (`timestamp`)');
$this->db->query('ALTER TABLE `ci_sessions` ADD PRIMARY KEY (`id`, `ip_address`)');
}
public function down()
{
$this->dbforge->drop_table('ci_sessions');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment