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 --- .../migrations/007_repurpose_invitations.php | 71 +++++++++++++++------- 1 file changed, 50 insertions(+), 21 deletions(-) (limited to 'application/migrations/007_repurpose_invitations.php') diff --git a/application/migrations/007_repurpose_invitations.php b/application/migrations/007_repurpose_invitations.php index d586c2829..8f83ff7c9 100644 --- a/application/migrations/007_repurpose_invitations.php +++ b/application/migrations/007_repurpose_invitations.php @@ -5,33 +5,62 @@ class Migration_Repurpose_invitations extends CI_Migration { public function up() { - $this->db->query(" - ALTER TABLE `invitations` - ADD `action` VARCHAR(255) NOT NULL, - ADD `data` TEXT NULL, - ADD INDEX `action` (`action`); - "); + if ($this->db->dbdriver == 'postgre') + { + $this->db->query(' + ALTER TABLE "invitations" + ADD "action" character varying(255) NOT NULL, + ADD "data" TEXT NULL; + CREATE INDEX "invitations_action_idx" ON invitations ("action"); + '); - $this->db->query(" - UPDATE `invitations` SET `action` = 'invitation' WHERE `action` = ''; - "); + $this->db->query(' + UPDATE "invitations" SET "action" = \'invitation\' WHERE "action" = \'\' + '); - $this->db->query(" - ALTER TABLE `invitations` RENAME `actions`; - "); + $this->db->query(' + ALTER TABLE "invitations" RENAME TO "actions"; + '); + } + else + { + $this->db->query(" + ALTER TABLE `invitations` + ADD `action` VARCHAR(255) NOT NULL, + ADD `data` TEXT NULL, + ADD INDEX `action` (`action`); + "); + $this->db->query(" + UPDATE `invitations` SET `action` = 'invitation' WHERE `action` = ''; + "); + + $this->db->query(" + ALTER TABLE `invitations` RENAME `actions`; + "); + } } public function down() { - $this->db->query(" - ALTER TABLE `actions` RENAME `invitations`; - "); - - $this->db->query(" - ALTER TABLE `invitations` - DROP `action`, - DROP `data`; - "); + if ($this->db->dbdriver == 'postgre') + { + $this->db->query('ALTER TABLE "actions" RENAME TO "invitations"'); + $this->db->query(' + ALTER TABLE "invitations" + DROP "action", + DROP "data"; + '); + } + else + { + $this->db->query('ALTER TABLE `actions` RENAME `invitations`'); + $this->db->query(' + ALTER TABLE `invitations` + DROP `action`, + DROP `data`; + '); + } + } } -- 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/007_repurpose_invitations.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'application/migrations/007_repurpose_invitations.php') diff --git a/application/migrations/007_repurpose_invitations.php b/application/migrations/007_repurpose_invitations.php index 8f83ff7c9..024b62984 100644 --- a/application/migrations/007_repurpose_invitations.php +++ b/application/migrations/007_repurpose_invitations.php @@ -5,8 +5,7 @@ class Migration_Repurpose_invitations extends CI_Migration { public function up() { - if ($this->db->dbdriver == 'postgre') - { + if ($this->db->dbdriver == 'postgre') { $this->db->query(' ALTER TABLE "invitations" ADD "action" character varying(255) NOT NULL, @@ -21,9 +20,9 @@ class Migration_Repurpose_invitations extends CI_Migration { $this->db->query(' ALTER TABLE "invitations" RENAME TO "actions"; '); - } - else - { + + } else { + $this->db->query(" ALTER TABLE `invitations` ADD `action` VARCHAR(255) NOT NULL, @@ -51,9 +50,9 @@ class Migration_Repurpose_invitations extends CI_Migration { DROP "action", DROP "data"; '); - } - else - { + + } else { + $this->db->query('ALTER TABLE `actions` RENAME `invitations`'); $this->db->query(' ALTER TABLE `invitations` -- cgit v1.2.3-24-g4f1b From 1abe7372404a9d65f3b59eda2d83e628267b366d Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 19 Oct 2014 23:01:51 +0200 Subject: Clean up the postgres changes Style cleanup and some regression fixes Signed-off-by: Florian Pritz --- application/migrations/007_repurpose_invitations.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'application/migrations/007_repurpose_invitations.php') diff --git a/application/migrations/007_repurpose_invitations.php b/application/migrations/007_repurpose_invitations.php index 024b62984..fb40e8179 100644 --- a/application/migrations/007_repurpose_invitations.php +++ b/application/migrations/007_repurpose_invitations.php @@ -42,8 +42,7 @@ class Migration_Repurpose_invitations extends CI_Migration { public function down() { - if ($this->db->dbdriver == 'postgre') - { + if ($this->db->dbdriver == 'postgre') { $this->db->query('ALTER TABLE "actions" RENAME TO "invitations"'); $this->db->query(' ALTER TABLE "invitations" -- cgit v1.2.3-24-g4f1b