summaryrefslogtreecommitdiffstats
path: root/application/migrations/020_update_session_table.php
blob: 9052071e067188abcc7f53f2282b584e2cd04f62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Migration_update_session_table extends CI_Migration {

	public function up()
	{
		$prefix = $this->db->dbprefix;

		if ($this->db->dbdriver == 'postgre') {
			$this->db->query('
				ALTER TABLE "'.$prefix.'ci_sessions"
					DROP COLUMN "user_agent";
				');
			$this->db->query('
				ALTER TABLE "'.$prefix.'ci_sessions"
					RENAME COLUMN "session_id" TO "id";
				');
			$this->db->query('
				ALTER TABLE "'.$prefix.'ci_sessions"
					RENAME COLUMN "last_activity" TO "timestamp";
				');
			$this->db->query('
				ALTER TABLE "'.$prefix.'ci_sessions"
					RENAME COLUMN "user_data" TO "data";
				');
		} else {
			$this->db->query('
				ALTER TABLE `'.$prefix.'ci_sessions`
					DROP `user_agent`,
					CHANGE `session_id` `id` VARCHAR(40) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 0,
					CHANGE `last_activity` `timestamp` INT(10) UNSIGNED NOT NULL DEFAULT 0,
					CHANGE `user_data` `data` BLOB NOT NULL;
				');
		}
	}

	public function down()
	{
		throw new \exceptions\ApiException("migration/downgrade-not-supported", "downgrade not supported");
	}
}