summaryrefslogtreecommitdiffstats
path: root/application/migrations/006_add_username_index.php
blob: a7ad236f33c77673a151b5bb6245a5eaf92bec47 (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
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Migration_Add_username_index extends CI_Migration {

	public function up()
	{
		if ($this->db->dbdriver == 'postgre')
		{
			$this->db->query('
				CREATE UNIQUE INDEX "users_username_idx" ON "users" ("username")
			');
		}
		else
		{
			$this->db->query("
				ALTER TABLE `users`
				ADD UNIQUE `username` (`username`);
			");
		}
	}

	public function down()
	{
		if ($this->db->dbdriver == 'postgre')
		{
			$this->db->query('DROP INDEX "users_username_idx"');
		}
		else
		{
			$this->db->query("
				ALTER TABLE `users`
				DROP INDEX `username`;
			");
		}
	}
}