Completed
Pull Request — master (#3)
by Matt
02:43
created

install_schema::update_schema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 1
Metric Value
c 5
b 1
f 1
dl 0
loc 21
rs 9.3142
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
/**
3
 *
4
 * Topic Prefixes extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2016 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\topicprefixes\migrations;
12
13
/**
14
 * Class install_schema
15
 */
16
class install_schema extends \phpbb\db\migration\migration
17
{
18
	/**
19
	 * @inheritdoc
20
	 */
21
	public function effectively_installed()
22
	{
23
		return $this->db_tools->sql_table_exists($this->table_prefix . 'topic_prefixes');
24
	}
25
26
	/**
27
	 * @inheritdoc
28
	 */
29
	public static function depends_on()
30
	{
31
		return ['\phpbb\db\migration\data\v31x\v314'];
32
	}
33
34
	/**
35
	 * Add the topic prefixes schema to the database:
36
	 *    topic_prefixes:
37
	 *        prefix_id       Prefix identifier
38
	 *        prefix_tag      Prefix tag
39
	 *        prefix_enabled  Prefix enabled/disabled state
40
	 *        forum_id        The forum identifier associated with the prefix
41
	 *    topics:
42
	 *        topic_prefix_id The prefix identifier associated with the topic
43
	 *
44
	 * @return array Array of table schema
45
	 */
46
	public function update_schema()
47
	{
48
		return [
49
			'add_columns'	=> [
50
				$this->table_prefix . 'topics'			=> [
51
					'topic_prefix_id' => ['UINT', 0],
52
				],
53
			],
54
			'add_tables'	=> [
55
				$this->table_prefix . 'topic_prefixes'	=> [
56
					'COLUMNS'     => [
57
						'prefix_id'			=> ['UINT', null, 'auto_increment'],
58
						'prefix_tag'		=> ['VCHAR_UNI', ''],
59
						'prefix_enabled'	=> ['BOOL', 1],
60
						'forum_id'			=> ['UINT', 0],
61
					],
62
					'PRIMARY_KEY'			=> 'prefix_id',
63
				],
64
			],
65
		];
66
	}
67
68
	/**
69
	 * Drop the topic prefixes schema from the database
70
	 *
71
	 * @return array Array of table schema
72
	 */
73
	public function revert_schema()
74
	{
75
		return [
76
			'drop_columns'	=> [
77
				$this->table_prefix . 'topics' => [
78
					'topic_prefix_id',
79
				],
80
			],
81
			'drop_tables'	=> [
82
				$this->table_prefix . 'topic_prefixes',
83
			],
84
		];
85
	}
86
}
87