summaryrefslogtreecommitdiffstats
path: root/application/migrations/007_repurpose_invitations.php
blob: 8f83ff7c95aaa961362b91ddda1aaa4caf161db2 (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
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Migration_Repurpose_invitations extends CI_Migration {

	public function up()
	{
		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('
				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()
	{
		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`;
			');
		}

	}
}