From 33f542487a89da4a8edad934b82aae7484f70ca3 Mon Sep 17 00:00:00 2001 From: Rafael Bodill Date: Thu, 18 Sep 2014 22:02:26 +0300 Subject: Migrations support for PostgreSQL --- application/migrations/006_add_username_index.php | 32 +++++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'application/migrations/006_add_username_index.php') diff --git a/application/migrations/006_add_username_index.php b/application/migrations/006_add_username_index.php index ea5e3ebc0..a7ad236f3 100644 --- a/application/migrations/006_add_username_index.php +++ b/application/migrations/006_add_username_index.php @@ -5,17 +5,33 @@ class Migration_Add_username_index extends CI_Migration { public function up() { - $this->db->query(" - ALTER TABLE `users` - ADD UNIQUE `username` (`username`); - "); + 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() { - $this->db->query(" - ALTER TABLE `users` - DROP INDEX `username`; - "); + if ($this->db->dbdriver == 'postgre') + { + $this->db->query('DROP INDEX "users_username_idx"'); + } + else + { + $this->db->query(" + ALTER TABLE `users` + DROP INDEX `username`; + "); + } } } -- cgit v1.2.3-24-g4f1b From fe7f15dbfb8020daf96110e86e359ec01558fcb8 Mon Sep 17 00:00:00 2001 From: Rafael Bodill Date: Thu, 18 Sep 2014 22:47:21 +0300 Subject: Correcting bracket style for 'if' --- application/migrations/006_add_username_index.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'application/migrations/006_add_username_index.php') diff --git a/application/migrations/006_add_username_index.php b/application/migrations/006_add_username_index.php index a7ad236f3..5b8c3584f 100644 --- a/application/migrations/006_add_username_index.php +++ b/application/migrations/006_add_username_index.php @@ -5,14 +5,11 @@ class Migration_Add_username_index extends CI_Migration { public function up() { - if ($this->db->dbdriver == 'postgre') - { + if ($this->db->dbdriver == 'postgre') { $this->db->query(' CREATE UNIQUE INDEX "users_username_idx" ON "users" ("username") '); - } - else - { + } else { $this->db->query(" ALTER TABLE `users` ADD UNIQUE `username` (`username`); @@ -22,12 +19,9 @@ class Migration_Add_username_index extends CI_Migration { public function down() { - if ($this->db->dbdriver == 'postgre') - { + if ($this->db->dbdriver == 'postgre') { $this->db->query('DROP INDEX "users_username_idx"'); - } - else - { + } else { $this->db->query(" ALTER TABLE `users` DROP INDEX `username`; -- cgit v1.2.3-24-g4f1b