aboutsummaryrefslogtreecommitdiffstats
path: root/apps/webhooks/lib/Migration/Version1000Date20240527153425.php
blob: 1b0641435338244106e1f7244338ff52c9b2d11e (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
71
72
73
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace OCA\Webhooks\Migration;

use Closure;
use OCA\Webhooks\Db\WebhookListenerMapper;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version1000Date20240527153425 extends SimpleMigrationStep {
	/**
	 * @param Closure(): ISchemaWrapper $schemaClosure
	 */
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
		/** @var ISchemaWrapper $schema */
		$schema = $schemaClosure();

		if (!$schema->hasTable(WebhookListenerMapper::TABLE_NAME)) {
			$table = $schema->createTable(WebhookListenerMapper::TABLE_NAME);
			$table->addColumn('id', Types::INTEGER, [
				'autoincrement' => true,
				'notnull' => true,
				'length' => 4,
			]);
			$table->addColumn('app_id', Types::STRING, [
				'notnull' => false,
				'length' => 64,
			]);
			$table->addColumn('user_id', Types::STRING, [
				'notnull' => true,
				'length' => 64,
			]);
			$table->addColumn('http_method', Types::STRING, [
				'notnull' => true,
				'length' => 32,
			]);
			$table->addColumn('uri', Types::STRING, [
				'notnull' => true,
				'length' => 256,
			]);
			$table->addColumn('event', Types::TEXT, [
				'notnull' => true,
			]);
			$table->addColumn('event_filter', Types::TEXT, [
				'notnull' => false,
			]);
			$table->addColumn('headers', Types::TEXT, [
				'notnull' => false,
			]);
			// TODO decide if string or int with an Enum
			$table->addColumn('auth_method', Types::STRING, [
				'notnull' => true,
				'length' => 16,
				'default' => '',
			]);
			$table->addColumn('auth_data', Types::TEXT, [
				'notnull' => false,
			]);
			$table->setPrimaryKey(['id']);
			return $schema;
		}
		return null;
	}
}