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/009_add_apikeys.php | 36 +++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'application/migrations/009_add_apikeys.php') diff --git a/application/migrations/009_add_apikeys.php b/application/migrations/009_add_apikeys.php index 8e88260a8..7b1b5aa58 100644 --- a/application/migrations/009_add_apikeys.php +++ b/application/migrations/009_add_apikeys.php @@ -5,16 +5,32 @@ class Migration_Add_apikeys extends CI_Migration { public function up() { - $this->db->query(" - CREATE TABLE `apikeys` ( - `key` varchar(64) COLLATE utf8_bin NOT NULL, - `user` int(8) unsigned NOT NULL, - `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `comment` varchar(255) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, - PRIMARY KEY (`key`), - KEY `user` (`user`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin - "); + if ($this->db->dbdriver == 'postgre') + { + $this->db->query(' + CREATE TABLE "apikeys" ( + "key" varchar(64) NOT NULL, + "user" integer NOT NULL, + "created" integer NOT NULL, + "comment" varchar(255) NOT NULL, + PRIMARY KEY ("key") + ); + CREATE INDEX "apikeys_user_idx" ON "apikeys" ("user"); + '); + } + else + { + $this->db->query(" + CREATE TABLE `apikeys` ( + `key` varchar(64) COLLATE utf8_bin NOT NULL, + `user` int(8) unsigned NOT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `comment` varchar(255) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, + PRIMARY KEY (`key`), + KEY `user` (`user`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin + "); + } } public function down() -- 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/009_add_apikeys.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'application/migrations/009_add_apikeys.php') diff --git a/application/migrations/009_add_apikeys.php b/application/migrations/009_add_apikeys.php index 7b1b5aa58..bdc4dd07d 100644 --- a/application/migrations/009_add_apikeys.php +++ b/application/migrations/009_add_apikeys.php @@ -5,8 +5,7 @@ class Migration_Add_apikeys extends CI_Migration { public function up() { - if ($this->db->dbdriver == 'postgre') - { + if ($this->db->dbdriver == 'postgre') { $this->db->query(' CREATE TABLE "apikeys" ( "key" varchar(64) NOT NULL, @@ -17,9 +16,9 @@ class Migration_Add_apikeys extends CI_Migration { ); CREATE INDEX "apikeys_user_idx" ON "apikeys" ("user"); '); - } - else - { + + } else { + $this->db->query(" CREATE TABLE `apikeys` ( `key` varchar(64) COLLATE utf8_bin NOT NULL, -- cgit v1.2.3-24-g4f1b From 5170adf992ba84fcced8bc271e603d1440f29509 Mon Sep 17 00:00:00 2001 From: Rafael Bodill Date: Fri, 19 Sep 2014 16:06:47 +0300 Subject: apikeys.created should be timestamp with default now() --- application/migrations/009_add_apikeys.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'application/migrations/009_add_apikeys.php') diff --git a/application/migrations/009_add_apikeys.php b/application/migrations/009_add_apikeys.php index bdc4dd07d..8f2882e49 100644 --- a/application/migrations/009_add_apikeys.php +++ b/application/migrations/009_add_apikeys.php @@ -10,7 +10,7 @@ class Migration_Add_apikeys extends CI_Migration { CREATE TABLE "apikeys" ( "key" varchar(64) NOT NULL, "user" integer NOT NULL, - "created" integer NOT NULL, + "created" timestamp WITH TIME ZONE NOT NULL DEFAULT NOW(), "comment" varchar(255) NOT NULL, PRIMARY KEY ("key") ); -- cgit v1.2.3-24-g4f1b