Browse code

fixed non-null column issue

DoubleBastionAdmin authored on 21/05/2024 06:07:25
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,129 @@
1
+<?php
2
+/**
3
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
4
+ *
5
+ * @author Double Bastion LLC
6
+ *
7
+ * @license GNU AGPL version 3 or any later version
8
+ *
9
+ * This program is free software; you can redistribute it and/or
10
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
11
+ * License as published by the Free Software Foundation; either
12
+ * version 3 of the License, or any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
18
+ *
19
+ * You should have received a copy of the GNU Affero General Public
20
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+ *
22
+ */
23
+
24
+declare(strict_types=1);
25
+
26
+namespace OCA\SIPTripPhone\Migration;
27
+
28
+use Closure;
29
+use OCP\DB\Types;
30
+use OCP\DB\ISchemaWrapper;
31
+use OCP\Migration\IOutput;
32
+use OCP\Migration\SimpleMigrationStep;
33
+
34
+
35
+class Version115Date20240521091835 extends SimpleMigrationStep {
36
+	/**
37
+	 * @param IOutput $output
38
+	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
39
+	 * @param array $options
40
+	 * @return null|ISchemaWrapper
41
+	 */
42
+	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
43
+		/** @var ISchemaWrapper $schema */
44
+		$schema = $schemaClosure();
45
+
46
+		if (!$schema->hasTable('sip_trip_phone')) {
47
+			$table = $schema->createTable('sip_trip_phone');
48
+			$table->addColumn('id', Types::BIGINT, [
49
+				'autoincrement' => true,
50
+				'notnull' => true,
51
+                                'length' => 11,
52
+                                'unsigned' => true,
53
+			]);
54
+			$table->addColumn('user_id', Types::STRING, [
55
+				'notnull' => true,
56
+				'length' => 64,
57
+				'default' => '',
58
+			]);
59
+			$table->addColumn('pdisplayname', Types::STRING, [
60
+				'notnull' => false,
61
+				'length' => 128,
62
+				'default' => '',
63
+			]);
64
+			$table->addColumn('sipusername', Types::STRING, [
65
+				'notnull' => false,
66
+				'length' => 128,
67
+				'default' => '',
68
+			]);
69
+			$table->addColumn('sipuserpassword', Types::STRING, [
70
+				'notnull' => false,
71
+				'length' => 2048,
72
+				'default' => '',
73
+			]);
74
+			$table->addColumn('stphwssurl', Types::STRING, [
75
+				'notnull' => false,
76
+				'length' => 128,
77
+				'default' => '',
78
+			]);
79
+			$table->addColumn('siprealm', Types::STRING, [
80
+				'notnull' => false,
81
+				'length' => 64,
82
+				'default' => '',
83
+			]);
84
+			$table->addColumn('stunserver', Types::STRING, [
85
+				'notnull' => false,
86
+				'length' => 256,
87
+				'default' => '',
88
+			]);
89
+			$table->addColumn('tracesipmsg', Types::SMALLINT, [
90
+				'notnull' => false,
91
+				'length' => 1,
92
+			]);
93
+			$table->addColumn('voicenumbers', Types::STRING, [
94
+				'notnull' => false,
95
+				'length' => 2048,
96
+				'default' => '',
97
+			]);
98
+			$table->addColumn('defaultvoicenumber', Types::STRING, [
99
+				'notnull' => false,
100
+				'length' => 48,
101
+				'default' => '',
102
+			]);
103
+                        $table->setPrimaryKey(['id']);
104
+                        $table->addUniqueIndex(['id']);
105
+
106
+		} else {
107
+
108
+                        $table = $schema->getTable('sip_trip_phone');
109
+
110
+			$table->changeColumn('pdisplayname', [
111
+				'notnull' => false,
112
+			]);
113
+			$table->changeColumn('sipusername', [
114
+				'notnull' => false,
115
+			]);
116
+			$table->changeColumn('sipuserpassword', [
117
+				'notnull' => false,
118
+			]);
119
+			$table->changeColumn('stphwssurl', [
120
+				'notnull' => false,
121
+			]);
122
+			$table->changeColumn('siprealm', [
123
+				'notnull' => false,
124
+			]);
125
+                }
126
+
127
+		return $schema;
128
+	}
129
+}