summaryrefslogtreecommitdiffstats
path: root/application/migrations/013_add_multipaste.php
blob: ef29effa9b4c6eef3c2cf5c9bcbb1e9702665c49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Migration_add_multipaste extends CI_Migration {

	public function up()
	{
		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" 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()
	{
		show_error("downgrade not supported");
	}
}