summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorRafael Bodill <rafi@sortex.co.il>2014-09-18 21:02:26 +0200
committerRafael Bodill <rafi@sortex.co.il>2014-09-18 21:02:26 +0200
commit33f542487a89da4a8edad934b82aae7484f70ca3 (patch)
tree778650804404efa3546f71a0b49955f7eac43c57 /application
parentd2c309aee8189a5d6c2a3fcb0a05ea694d7b646e (diff)
Migrations support for PostgreSQL
Diffstat (limited to 'application')
-rw-r--r--application/migrations/001_add_files.php30
-rw-r--r--application/migrations/002_add_users.php93
-rw-r--r--application/migrations/003_add_referrers.php64
-rw-r--r--application/migrations/004_add_filesize.php35
-rw-r--r--application/migrations/005_drop_file_password.php30
-rw-r--r--application/migrations/006_add_username_index.php32
-rw-r--r--application/migrations/007_repurpose_invitations.php71
-rw-r--r--application/migrations/008_add_profiles.php60
-rw-r--r--application/migrations/009_add_apikeys.php36
-rw-r--r--application/migrations/010_files_innodb.php9
-rw-r--r--application/migrations/011_apikeys_add_access_level.php30
-rw-r--r--application/migrations/012_add_constraints.php27
-rw-r--r--application/migrations/013_add_multipaste.php77
13 files changed, 426 insertions, 168 deletions
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()
diff --git a/application/migrations/002_add_users.php b/application/migrations/002_add_users.php
index 5675c77e9..d74402263 100644
--- a/application/migrations/002_add_users.php
+++ b/application/migrations/002_add_users.php
@@ -5,42 +5,77 @@ 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;
- ");
+ 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` 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('
+ 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` INT(8) UNSIGNED NOT NULL DEFAULT '0',
- ADD INDEX (`user`)
- ");
+ $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`');
+ }
}
}
diff --git a/application/migrations/003_add_referrers.php b/application/migrations/003_add_referrers.php
index 524e92ff0..1f6b966e3 100644
--- a/application/migrations/003_add_referrers.php
+++ b/application/migrations/003_add_referrers.php
@@ -5,28 +5,56 @@ class Migration_Add_referrers extends CI_Migration {
public function up()
{
- $this->db->query("
- CREATE TABLE `invitations` (
- `user` int(8) unsigned NOT NULL,
- `key` varchar(16) CHARACTER SET ascii NOT NULL,
- `date` int(11) unsigned NOT NULL,
- PRIMARY KEY (`key`),
- KEY `user` (`user`),
- KEY `date` (`date`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
- ");
- $this->db->query("
- ALTER TABLE `users`
- ADD `referrer` INT(8) UNSIGNED NOT NULL DEFAULT '0'
- ");
+ if ($this->db->dbdriver == 'postgre')
+ {
+ $this->db->query('
+ CREATE TABLE "invitations" (
+ "user" integer NOT NULL,
+ "key" character varying(16) NOT NULL,
+ "date" integer NOT NULL,
+ PRIMARY KEY ("key")
+ );
+ CREATE INDEX "invitations_user_idx" ON "invitations" ("user");
+ CREATE INDEX "invitations_date_idx" ON "invitations" ("date");
+ ');
+ $this->db->query('
+ ALTER TABLE "users"
+ ADD "referrer" integer NOT NULL DEFAULT 0
+ ');
+ }
+ else
+ {
+ $this->db->query("
+ CREATE TABLE `invitations` (
+ `user` int(8) unsigned NOT NULL,
+ `key` varchar(16) CHARACTER SET ascii NOT NULL,
+ `date` int(11) unsigned NOT NULL,
+ PRIMARY KEY (`key`),
+ KEY `user` (`user`),
+ KEY `date` (`date`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
+ ");
+ $this->db->query("
+ ALTER TABLE `users`
+ ADD `referrer` INT(8) UNSIGNED NOT NULL DEFAULT '0'
+ ");
+ }
}
public function down()
{
- $this->db->query("
- ALTER TABLE `users`
- DROP `referrer`
- ");
+ if ($this->db->dbdriver == 'postgre')
+ {
+ $this->db->query('
+ ALTER TABLE "users" DROP "referrer"
+ ');
+ }
+ else
+ {
+ $this->db->query('
+ ALTER TABLE `users` DROP `referrer`
+ ');
+ }
$this->dbforge->drop_table('invitations');
}
diff --git a/application/migrations/004_add_filesize.php b/application/migrations/004_add_filesize.php
index d7a70223d..7e5355c14 100644
--- a/application/migrations/004_add_filesize.php
+++ b/application/migrations/004_add_filesize.php
@@ -5,18 +5,35 @@ class Migration_Add_filesize extends CI_Migration {
public function up()
{
- $this->db->query("
- ALTER TABLE `files`
- ADD `filesize` INT UNSIGNED NOT NULL
- ");
+ if ($this->db->dbdriver == 'postgre')
+ {
+ $this->db->query('
+ ALTER TABLE "files"
+ ADD "filesize" integer NOT NULL
+ ');
+ }
+ else
+ {
+ $this->db->query("
+ ALTER TABLE `files`
+ ADD `filesize` INT UNSIGNED NOT NULL
+ ");
+ }
}
public function down()
{
- $this->db->query("
- ALTER TABLE `files`
- DROP `filesize`
- ");
-
+ if ($this->db->dbdriver == 'postgre')
+ {
+ $this->db->query('
+ ALTER TABLE "files" DROP "filesize"
+ ');
+ }
+ else
+ {
+ $this->db->query('
+ ALTER TABLE `files` DROP `filesize`
+ ');
+ }
}
}
diff --git a/application/migrations/005_drop_file_password.php b/application/migrations/005_drop_file_password.php
index bf03490a8..2be20e550 100644
--- a/application/migrations/005_drop_file_password.php
+++ b/application/migrations/005_drop_file_password.php
@@ -5,17 +5,31 @@ class Migration_Drop_file_password extends CI_Migration {
public function up()
{
- $this->db->query("
- ALTER TABLE `files`
- DROP `password`;
- ");
+ if ($this->db->dbdriver == 'postgre')
+ {
+ $this->db->query('ALTER TABLE "files" DROP "password"');
+ }
+ else
+ {
+ $this->db->query("ALTER TABLE `files` DROP `password`;");
+ }
}
public function down()
{
- $this->db->query("
- ALTER TABLE `files`
- ADD `password` varchar(40) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL;
- ");
+ if ($this->db->dbdriver == 'postgre')
+ {
+ $this->db->query('
+ ALTER TABLE "files"
+ ADD "password" character varying(40) DEFAULT NULL
+ ');
+ }
+ else
+ {
+ $this->db->query("
+ ALTER TABLE `files`
+ ADD `password` varchar(40) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL;
+ ");
+ }
}
}
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`;
+ ");
+ }
}
}
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`;
+ ');
+ }
+
}
}
diff --git a/application/migrations/008_add_profiles.php b/application/migrations/008_add_profiles.php
index 3fea33c08..1e55c7d14 100644
--- a/application/migrations/008_add_profiles.php
+++ b/application/migrations/008_add_profiles.php
@@ -5,27 +5,55 @@ class Migration_Add_profiles extends CI_Migration {
public function up()
{
- $this->db->query("
- CREATE TABLE `profiles` (
- `user` int(8) unsigned NOT NULL,
- `upload_id_limits` varchar(255) COLLATE utf8_bin NOT NULL,
- PRIMARY KEY (`user`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
- ");
+ if ($this->db->dbdriver == 'postgre')
+ {
+ $this->db->query('
+ CREATE TABLE "profiles" (
+ "user" integer NOT NULL,
+ "upload_id_limits" varchar(255) NOT NULL,
+ PRIMARY KEY ("user")
+ )
+ ');
- $this->db->query("
- ALTER TABLE `files` CHANGE `id` `id` VARCHAR( 255 );
- ");
+ $this->db->query('
+ ALTER TABLE "files" ALTER COLUMN "id" TYPE varchar(255);
+ ');
+ }
+ else
+ {
+ $this->db->query("
+ CREATE TABLE `profiles` (
+ `user` int(8) unsigned NOT NULL,
+ `upload_id_limits` varchar(255) COLLATE utf8_bin NOT NULL,
+ PRIMARY KEY (`user`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
+ ");
+ $this->db->query("
+ ALTER TABLE `files` CHANGE `id` `id` VARCHAR( 255 );
+ ");
+ }
}
public function down()
{
- $this->db->query("
- DROP TABLE `profiles`;
- ");
- $this->db->query("
- ALTER TABLE `files` CHANGE `id` `id` VARCHAR( 6 );
- ");
+ if ($this->db->dbdriver == 'postgre')
+ {
+ $this->db->query('
+ DROP TABLE "profiles";
+ ');
+ $this->db->query('
+ ALTER TABLE "files" ALTER COLUMN "id" TYPE varchar(6);
+ ');
+ }
+ else
+ {
+ $this->db->query("
+ DROP TABLE `profiles`;
+ ");
+ $this->db->query("
+ ALTER TABLE `files` CHANGE `id` `id` VARCHAR( 6 );
+ ");
+ }
}
}
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()
diff --git a/application/migrations/010_files_innodb.php b/application/migrations/010_files_innodb.php
index b32f94724..f965344d2 100644
--- a/application/migrations/010_files_innodb.php
+++ b/application/migrations/010_files_innodb.php
@@ -5,9 +5,12 @@ class Migration_files_innodb extends CI_Migration {
public function up()
{
- $this->db->query("
- ALTER TABLE `files` ENGINE = InnoDB;
- ");
+ if ($this->db->dbdriver != 'postgre')
+ {
+ $this->db->query("
+ ALTER TABLE `files` ENGINE = InnoDB;
+ ");
+ }
}
public function down()
diff --git a/application/migrations/011_apikeys_add_access_level.php b/application/migrations/011_apikeys_add_access_level.php
index e0f39317b..29a2f769b 100644
--- a/application/migrations/011_apikeys_add_access_level.php
+++ b/application/migrations/011_apikeys_add_access_level.php
@@ -5,15 +5,33 @@ class Migration_apikeys_add_access_level extends CI_Migration {
public function up()
{
- $this->db->query("
- alter table `apikeys` add `access_level` varchar(255) default 'apikey';
- ");
+ if ($this->db->dbdriver == 'postgre')
+ {
+ $this->db->query('
+ alter table "apikeys" add "access_level" varchar(255) default \'apikey\'
+ ');
+ }
+ else
+ {
+ $this->db->query("
+ alter table `apikeys` add `access_level` varchar(255) default 'apikey';
+ ");
+ }
}
public function down()
{
- $this->db->query("
- alter table `apikeys` drop `access_level`;
- ");
+ if ($this->db->dbdriver == 'postgre')
+ {
+ $this->db->query('
+ alter table "apikeys" drop "access_level"
+ ');
+ }
+ else
+ {
+ $this->db->query('
+ alter table `apikeys` drop `access_level`
+ ');
+ }
}
}
diff --git a/application/migrations/012_add_constraints.php b/application/migrations/012_add_constraints.php
index 2b0764fb0..04c0fb9ca 100644
--- a/application/migrations/012_add_constraints.php
+++ b/application/migrations/012_add_constraints.php
@@ -5,12 +5,27 @@ class Migration_add_constraints extends CI_Migration {
public function up()
{
- $this->db->query("ALTER TABLE `users` ADD INDEX(`referrer`);");
- $this->db->query("ALTER TABLE `users` CHANGE `referrer` `referrer`
- INT(8) UNSIGNED NULL;");
- $this->db->query("UPDATE `users` SET `referrer` = NULL where `referrer` = 0;");
- $this->db->query("ALTER TABLE `users` ADD FOREIGN KEY (`referrer`)
- REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;");
+ if ($this->db->dbdriver == 'postgre')
+ {
+ $this->db->query('ALTER TABLE "users" ALTER COLUMN "referrer" TYPE integer');
+ $this->db->query('ALTER TABLE "users" ALTER COLUMN "referrer" DROP NOT NULL');
+ $this->db->query('CREATE INDEX "users_referrer_idx" ON "users" ("referrer")');
+ $this->db->query('UPDATE "users" SET "referrer" = NULL where "referrer" = 0');
+ $this->db->query('
+ ALTER TABLE "users"
+ ADD CONSTRAINT "referrer_user_fkey" FOREIGN KEY ("referrer")
+ REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE RESTRICT
+ ');
+ }
+ else
+ {
+ $this->db->query("ALTER TABLE `users` ADD INDEX(`referrer`);");
+ $this->db->query("ALTER TABLE `users` CHANGE `referrer` `referrer`
+ INT(8) UNSIGNED NULL;");
+ $this->db->query("UPDATE `users` SET `referrer` = NULL where `referrer` = 0;");
+ $this->db->query("ALTER TABLE `users` ADD FOREIGN KEY (`referrer`)
+ REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;");
+ }
}
public function down()
diff --git a/application/migrations/013_add_multipaste.php b/application/migrations/013_add_multipaste.php
index edb4a0748..3b97f6986 100644
--- a/application/migrations/013_add_multipaste.php
+++ b/application/migrations/013_add_multipaste.php
@@ -5,28 +5,63 @@ class Migration_add_multipaste extends CI_Migration {
public function up()
{
- $this->db->query('
- CREATE TABLE `multipaste` (
- `url_id` varchar(255) NOT NULL,
- `multipaste_id` int(11) NOT NULL AUTO_INCREMENT,
- `user_id` int(11) NOT NULL,
- `date` int(11) NOT NULL,
- PRIMARY KEY (`url_id`),
- UNIQUE KEY `multipaste_id` (`multipaste_id`),
- KEY `user_id` (`user_id`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
+ if ($this->db->dbdriver == 'postgre')
+ {
+ $this->db->query('
+ CREATE TABLE "multipaste" (
+ "url_id" varchar(255) NOT NULL,
+ "multipaste_id" serial,
+ "user_id" integer NOT NULL,
+ "date" integer NOT NULL,
+ PRIMARY KEY ("url_id")
+ );
+ CREATE INDEX "multipaste_user_idx" ON "multipaste" ("user_id");
+ CREATE UNIQUE INDEX "multipaste_id_idx" ON "multipaste" ("multipaste_id");
+ ');
- $this->db->query('
- CREATE TABLE `multipaste_file_map` (
- `multipaste_id` int(11) NOT NULL,
- `file_url_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
- `sort_order` int(10) unsigned NOT NULL AUTO_INCREMENT,
- PRIMARY KEY (`sort_order`),
- UNIQUE KEY `multipaste_id` (`multipaste_id`,`file_url_id`),
- KEY `multipaste_file_map_ibfk_2` (`file_url_id`),
- CONSTRAINT `multipaste_file_map_ibfk_1` FOREIGN KEY (`multipaste_id`) REFERENCES `multipaste` (`multipaste_id`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `multipaste_file_map_ibfk_2` FOREIGN KEY (`file_url_id`) REFERENCES `files` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;');
+ $this->db->query('
+ CREATE TABLE "multipaste_file_map" (
+ "multipaste_id" integer NOT NULL,
+ "file_url_id" varchar(255) NOT NULL,
+ "sort_order" serial,
+ PRIMARY KEY ("sort_order")
+ );
+ CREATE UNIQUE INDEX "multipaste_file_map_idx"
+ ON "multipaste_file_map" ("multipaste_id", "file_url_id");
+ CREATE INDEX "multipaste_file_map_file_idx" ON "multipaste_file_map" ("file_url_id");
+ ALTER TABLE "multipaste_file_map"
+ ADD CONSTRAINT "multipaste_file_map_id_fkey" FOREIGN KEY ("multipaste_id")
+ REFERENCES "multipaste"("multipaste_id") ON DELETE CASCADE ON UPDATE CASCADE;
+ ALTER TABLE "multipaste_file_map"
+ ADD CONSTRAINT "multipaste_file_map_file_id_fkey" FOREIGN KEY ("file_url_id")
+ REFERENCES "files"("id") ON DELETE CASCADE ON UPDATE CASCADE
+ ');
+ }
+ else
+ {
+ $this->db->query('
+ CREATE TABLE `multipaste` (
+ `url_id` varchar(255) NOT NULL,
+ `multipaste_id` int(11) NOT NULL AUTO_INCREMENT,
+ `user_id` int(11) NOT NULL,
+ `date` int(11) NOT NULL,
+ PRIMARY KEY (`url_id`),
+ UNIQUE KEY `multipaste_id` (`multipaste_id`),
+ KEY `user_id` (`user_id`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
+
+ $this->db->query('
+ CREATE TABLE `multipaste_file_map` (
+ `multipaste_id` int(11) NOT NULL,
+ `file_url_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
+ `sort_order` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ PRIMARY KEY (`sort_order`),
+ UNIQUE KEY `multipaste_id` (`multipaste_id`,`file_url_id`),
+ KEY `multipaste_file_map_ibfk_2` (`file_url_id`),
+ CONSTRAINT `multipaste_file_map_ibfk_1` FOREIGN KEY (`multipaste_id`) REFERENCES `multipaste` (`multipaste_id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `multipaste_file_map_ibfk_2` FOREIGN KEY (`file_url_id`) REFERENCES `files` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;');
+ }
}
public function down()