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/001_add_files.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'application/migrations/001_add_files.php') diff --git a/application/migrations/001_add_files.php b/application/migrations/001_add_files.php index f1f16ea3a..c5e4e7dfe 100644 --- a/application/migrations/001_add_files.php +++ b/application/migrations/001_add_files.php @@ -5,19 +5,23 @@ class Migration_Add_files extends CI_Migration { public function up() { - $this->db->query(" - CREATE TABLE IF NOT EXISTS `files` ( - `hash` varchar(32) CHARACTER SET ascii NOT NULL, - `id` varchar(6) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, - `filename` varchar(256) COLLATE utf8_bin NOT NULL, - `password` varchar(40) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL, - `date` int(11) unsigned NOT NULL, - `mimetype` varchar(255) CHARACTER SET ascii NOT NULL, - PRIMARY KEY (`id`), - KEY `date` (`date`), - KEY `hash` (`hash`,`id`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; - "); + // Set database engine for MySQL drivers + if (strpos($this->db->dbdriver, 'mysql') !== FALSE) + { + $this->db->query('SET storage_engine=MYISAM'); + } + + $this->dbforge->add_field([ + 'hash' => [ 'type' => 'varchar', 'constraint' => 32, 'null' => FALSE ], + 'id' => [ 'type' => 'varchar', 'constraint' => 6, 'null' => FALSE ], + 'filename' => [ 'type' => 'varchar', 'constraint' => 256, 'null' => FALSE ], + 'password' => [ 'type' => 'varchar', 'constraint' => 40, 'null' => TRUE ], + 'date' => [ 'type' => 'integer', 'unsigned' => TRUE, 'null' => FALSE ], + 'mimetype' => [ 'type' => 'varchar', 'constraint' => 255, 'null' => FALSE ], + ]); + $this->dbforge->add_key('id', TRUE); + $this->dbforge->add_key([ 'hash', 'id' ]); + $this->dbforge->create_table('files', TRUE); } 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/001_add_files.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'application/migrations/001_add_files.php') diff --git a/application/migrations/001_add_files.php b/application/migrations/001_add_files.php index c5e4e7dfe..8af202285 100644 --- a/application/migrations/001_add_files.php +++ b/application/migrations/001_add_files.php @@ -6,8 +6,7 @@ class Migration_Add_files extends CI_Migration { public function up() { // Set database engine for MySQL drivers - if (strpos($this->db->dbdriver, 'mysql') !== FALSE) - { + if (strpos($this->db->dbdriver, 'mysql') !== FALSE) { $this->db->query('SET storage_engine=MYISAM'); } -- cgit v1.2.3-24-g4f1b From b8fa66e0d874bc5aa6ee719f6067b5365661833a Mon Sep 17 00:00:00 2001 From: Rafael Bodill Date: Fri, 19 Sep 2014 15:43:51 +0300 Subject: No column based encoding. Reverting dbforge migration --- application/migrations/001_add_files.php | 46 +++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'application/migrations/001_add_files.php') diff --git a/application/migrations/001_add_files.php b/application/migrations/001_add_files.php index 8af202285..70efbb520 100644 --- a/application/migrations/001_add_files.php +++ b/application/migrations/001_add_files.php @@ -5,22 +5,38 @@ class Migration_Add_files extends CI_Migration { public function up() { - // Set database engine for MySQL drivers - if (strpos($this->db->dbdriver, 'mysql') !== FALSE) { - $this->db->query('SET storage_engine=MYISAM'); + if ($this->db->dbdriver == 'postgre') + { + $this->db->query(' + CREATE TABLE IF NOT EXISTS "files" ( + "hash" varchar(32) NOT NULL, + "id" varchar(6) NOT NULL, + "filename" varchar(256) NOT NULL, + "password" varchar(40) DEFAULT NULL, + "date" integer NOT NULL, + "mimetype" varchar(255) NOT NULL, + PRIMARY KEY ("id") + ); + CREATE INDEX "files_date_idx" ON files ("date"); + CREATE INDEX "files_hash_id_idx" ON files ("hash", "id"); + '); + } + else + { + $this->db->query(" + CREATE TABLE IF NOT EXISTS `files` ( + `hash` varchar(32) CHARACTER SET ascii NOT NULL, + `id` varchar(6) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, + `filename` varchar(256) COLLATE utf8_bin NOT NULL, + `password` varchar(40) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL, + `date` int(11) unsigned NOT NULL, + `mimetype` varchar(255) CHARACTER SET ascii NOT NULL, + PRIMARY KEY (`id`), + KEY `date` (`date`), + KEY `hash` (`hash`,`id`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + "); } - - $this->dbforge->add_field([ - 'hash' => [ 'type' => 'varchar', 'constraint' => 32, 'null' => FALSE ], - 'id' => [ 'type' => 'varchar', 'constraint' => 6, 'null' => FALSE ], - 'filename' => [ 'type' => 'varchar', 'constraint' => 256, 'null' => FALSE ], - 'password' => [ 'type' => 'varchar', 'constraint' => 40, 'null' => TRUE ], - 'date' => [ 'type' => 'integer', 'unsigned' => TRUE, 'null' => FALSE ], - 'mimetype' => [ 'type' => 'varchar', 'constraint' => 255, 'null' => FALSE ], - ]); - $this->dbforge->add_key('id', TRUE); - $this->dbforge->add_key([ 'hash', 'id' ]); - $this->dbforge->create_table('files', TRUE); } public function down() -- cgit v1.2.3-24-g4f1b