summaryrefslogtreecommitdiffstats
path: root/application/migrations/002_add_users.php
diff options
context:
space:
mode:
authorRafael Bodill <rafi@sortex.co.il>2014-09-19 17:47:01 +0200
committerRafael Bodill <rafi@sortex.co.il>2014-09-19 17:47:01 +0200
commit0b62a117ca8d34331406a07dc52aa937ff76ace1 (patch)
tree318a5c84cdb11d27017d1cadd1dd517618682fd9 /application/migrations/002_add_users.php
parentd2c309aee8189a5d6c2a3fcb0a05ea694d7b646e (diff)
parent75b0a939c7ce24014a8db95a3355d2a7ffdfe3a9 (diff)
Merge branch 'pgsql_migrations'
* pgsql_migrations: Optimizing multipaste tables apikeys.created should be timestamp with default now() No column based encoding. Reverting dbforge migration Correcting bracket style for 'if' Migrations support for PostgreSQL
Diffstat (limited to 'application/migrations/002_add_users.php')
-rw-r--r--application/migrations/002_add_users.php93
1 files changed, 62 insertions, 31 deletions
diff --git a/application/migrations/002_add_users.php b/application/migrations/002_add_users.php
index 5675c77e9..322415d9b 100644
--- a/application/migrations/002_add_users.php
+++ b/application/migrations/002_add_users.php
@@ -5,42 +5,73 @@ class Migration_Add_users extends CI_Migration {
public function up()
{
- $this->db->query("
- CREATE TABLE IF NOT EXISTS `users` (
- `id` int(8) UNSIGNED NOT NULL AUTO_INCREMENT,
- `username` varchar(32) COLLATE ascii_general_ci NOT NULL,
- `password` varchar(60) COLLATE ascii_general_ci NOT NULL,
- `email` varchar(255) COLLATE ascii_general_ci NOT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
- ");
-
- $this->db->query("
- CREATE TABLE IF NOT EXISTS `ci_sessions` (
- `session_id` varchar(40) NOT NULL DEFAULT '0',
- `ip_address` varchar(16) NOT NULL DEFAULT '0',
- `user_agent` varchar(120) NOT NULL,
- `last_activity` int(10) unsigned NOT NULL DEFAULT '0',
- `user_data` text NOT NULL,
- PRIMARY KEY (`session_id`),
- KEY `last_activity_idx` (`last_activity`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- ");
-
- $this->db->query("
- ALTER TABLE `files`
- ADD `user` INT(8) UNSIGNED NOT NULL DEFAULT '0',
- ADD INDEX (`user`)
- ");
+ if ($this->db->dbdriver == 'postgre') {
+ $this->db->query('
+ CREATE TABLE IF NOT EXISTS "users" (
+ "id" serial PRIMARY KEY,
+ "username" character varying(32) NOT NULL,
+ "password" character varying(60) NOT NULL,
+ "email" character varying(255) NOT NULL
+ )
+ ');
+
+ $this->db->query('
+ CREATE TABLE IF NOT EXISTS "ci_sessions" (
+ "session_id" character varying(40) NOT NULL DEFAULT 0,
+ "ip_address" character varying(16) NOT NULL DEFAULT 0,
+ "user_agent" character varying(120) NOT NULL,
+ "last_activity" integer NOT NULL DEFAULT 0,
+ "user_data" text NOT NULL,
+ PRIMARY KEY ("session_id")
+ );
+ CREATE INDEX "ci_sessions_last_activity_idx" ON "ci_sessions" ("last_activity");
+ ');
+
+ $this->db->query('
+ ALTER TABLE "files" ADD "user" integer NOT NULL DEFAULT 0;
+ CREATE INDEX "user_idx" ON "files" ("user");
+ ');
+
+ } else {
+
+ $this->db->query("
+ CREATE TABLE IF NOT EXISTS `users` (
+ `id` int(8) UNSIGNED NOT NULL AUTO_INCREMENT,
+ `username` varchar(32) COLLATE ascii_general_ci NOT NULL,
+ `password` varchar(60) COLLATE ascii_general_ci NOT NULL,
+ `email` varchar(255) COLLATE ascii_general_ci NOT NULL,
+ PRIMARY KEY (`id`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+ ");
+
+ $this->db->query("
+ CREATE TABLE IF NOT EXISTS `ci_sessions` (
+ `session_id` varchar(40) NOT NULL DEFAULT '0',
+ `ip_address` varchar(16) NOT NULL DEFAULT '0',
+ `user_agent` varchar(120) NOT NULL,
+ `last_activity` int(10) unsigned NOT NULL DEFAULT '0',
+ `user_data` text NOT NULL,
+ PRIMARY KEY (`session_id`),
+ KEY `last_activity_idx` (`last_activity`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+ ");
+
+ $this->db->query("
+ ALTER TABLE `files`
+ ADD `user` INT(8) UNSIGNED NOT NULL DEFAULT '0',
+ ADD INDEX (`user`)
+ ");
+ }
}
public function down()
{
$this->dbforge->drop_table('users');
$this->dbforge->drop_table('ci_sessions');
- $this->db->query("
- ALTER TABLE `files`
- DROP `user`
- ");
+ if ($this->db->dbdriver == 'postgre') {
+ $this->db->query('ALTER TABLE "files" DROP "user"');
+ } else {
+ $this->db->query('ALTER TABLE `files` DROP `user`');
+ }
}
}