aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Update/_1214.php
blob: 06e5d96ed8b8c1df9039222ea7ef59a5bc81dcbe (plain) (blame)
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
<?php

namespace Zotlabs\Update;

class _1214 {

	function run() {
		if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
			q("START TRANSACTION");

			$r1 = q("ALTER TABLE oauth_clients ALTER COLUMN user_id TYPE bigint USING user_id::bigint");
			$r2 = q("ALTER TABLE oauth_clients ALTER COLUMN user_id SET NOT NULL");
			$r3 = q("ALTER TABLE oauth_clients ALTER COLUMN user_id SET DEFAULT 0");

			$r4 = q("ALTER TABLE oauth_access_tokens ALTER COLUMN user_id TYPE bigint USING user_id::bigint");
			$r5 = q("ALTER TABLE oauth_access_tokens ALTER COLUMN user_id SET NOT NULL");
			$r6 = q("ALTER TABLE oauth_access_tokens ALTER COLUMN user_id SET DEFAULT 0");

			$r7 = q("ALTER TABLE oauth_authorization_codes ALTER COLUMN user_id TYPE bigint USING user_id::bigint");
			$r8 = q("ALTER TABLE oauth_authorization_codes ALTER COLUMN user_id SET NOT NULL");
			$r9 = q("ALTER TABLE oauth_authorization_codes ALTER COLUMN user_id SET DEFAULT 0");

			$r10 = q("ALTER TABLE oauth_refresh_tokens ALTER COLUMN user_id TYPE bigint USING user_id::bigint");
			$r11 = q("ALTER TABLE oauth_refresh_tokens ALTER COLUMN user_id SET NOT NULL");
			$r12 = q("ALTER TABLE oauth_refresh_tokens ALTER COLUMN user_id SET DEFAULT 0");


			if($r1 && $r2 && $r3 && $r4 && $r5 && $r6 && $r7 && $r8 && $r9 && $r10 && $r11 && $r12) {
				q("COMMIT");
				return UPDATE_SUCCESS;
			}
			else {        
				q("ROLLBACK");
				return UPDATE_FAILED;
			}
		}
		else {
			q("START TRANSACTION");

			$r1 = q("ALTER TABLE oauth_clients MODIFY COLUMN user_id int(10) unsigned NOT NULL DEFAULT 0");
			$r2 = q("ALTER TABLE oauth_access_tokens MODIFY COLUMN user_id int(10) unsigned NOT NULL DEFAULT 0");
			$r3 = q("ALTER TABLE oauth_authorization_codes MODIFY COLUMN user_id int(10) unsigned NOT NULL DEFAULT 0");
			$r4 = q("ALTER TABLE oauth_refresh_tokens MODIFY COLUMN user_id int(10) unsigned NOT NULL DEFAULT 0");

			if($r1 && $r2 && $r3 && $r4) {
				q("COMMIT");
				return UPDATE_SUCCESS;
			}
			else {        
				q("ROLLBACK");
				return UPDATE_FAILED;
			}

		}
	}

}