Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
27.78% covered (danger)
27.78%
10 / 36
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Migration323
27.78% covered (danger)
27.78%
10 / 36
75.00% covered (warning)
75.00%
3 / 4
32.11
0.00% covered (danger)
0.00%
0 / 1
 getVersion
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDependencies
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDescription
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 up
21.21% covered (danger)
21.21%
7 / 33
0.00% covered (danger)
0.00%
0 / 1
17.23
1<?php
2
3/**
4 * Migration for phpMyFAQ 3.2.3.
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License,
7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
8 * obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * @package   phpMyFAQ
11 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
12 * @copyright 2023-2026 phpMyFAQ Team
13 * @license   https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14 * @link      https://www.phpmyfaq.de
15 * @since     2026-01-25
16 */
17
18declare(strict_types=1);
19
20namespace phpMyFAQ\Setup\Migration\Versions;
21
22use phpMyFAQ\Setup\Migration\AbstractMigration;
23use phpMyFAQ\Setup\Migration\Operations\OperationRecorder;
24
25readonly class Migration323 extends AbstractMigration
26{
27    public function getVersion(): string
28    {
29        return '3.2.3';
30    }
31
32    public function getDependencies(): array
33    {
34        return ['3.2.0-RC'];
35    }
36
37    public function getDescription(): string
38    {
39        return 'Increase IP column size for IPv6 support';
40    }
41
42    public function up(OperationRecorder $recorder): void
43    {
44        if ($this->isMySql()) {
45            $recorder->addSql(
46                sprintf('ALTER TABLE %sfaquser CHANGE ip ip VARCHAR(64) NULL DEFAULT NULL', $this->tablePrefix),
47                'Increase faquser.ip column size (MySQL)',
48            );
49            return;
50        }
51
52        if ($this->isPostgreSql()) {
53            $recorder->addSql(
54                sprintf('ALTER TABLE %sfaquser ALTER COLUMN ip TYPE VARCHAR(64)', $this->tablePrefix),
55                'Increase faquser.ip column size (PostgreSQL)',
56            );
57            return;
58        }
59
60        if ($this->isSqlite()) {
61            // SQLite requires table rebuild
62            $recorder->addSql(sprintf(
63                'CREATE TABLE %sfaquser_new (
64                    user_id INTEGER NOT NULL,
65                    login VARCHAR(128) NOT NULL,
66                    session_id VARCHAR(150) NULL,
67                    session_timestamp INTEGER NULL,
68                    ip VARCHAR(64) NULL,
69                    account_status VARCHAR(50) NULL,
70                    last_login VARCHAR(14) NULL,
71                    auth_source VARCHAR(100) NULL,
72                    member_since VARCHAR(14) NULL,
73                    remember_me VARCHAR(150) NULL,
74                    success INTEGER NULL DEFAULT 1,
75                    is_superadmin INTEGER NULL DEFAULT 0,
76                    login_attempts INTEGER NULL DEFAULT 0,
77                    refresh_token TEXT NULL DEFAULT NULL,
78                    access_token TEXT NULL DEFAULT NULL,
79                    code_verifier VARCHAR(255) NULL DEFAULT NULL,
80                    jwt TEXT NULL DEFAULT NULL,
81                    PRIMARY KEY (user_id))',
82                $this->tablePrefix,
83            ), 'Create new faquser table with larger IP column (SQLite)');
84
85            $recorder->addSql(
86                sprintf('INSERT INTO %sfaquser_new SELECT * FROM %sfaquser', $this->tablePrefix, $this->tablePrefix),
87                'Copy data to new faquser table (SQLite)',
88            );
89
90            $recorder->addSql(sprintf('DROP TABLE %sfaquser', $this->tablePrefix), 'Drop old faquser table (SQLite)');
91
92            $recorder->addSql(
93                sprintf('ALTER TABLE %sfaquser_new RENAME TO %sfaquser', $this->tablePrefix, $this->tablePrefix),
94                'Rename new faquser table (SQLite)',
95            );
96            return;
97        }
98
99        if ($this->isSqlServer()) {
100            $recorder->addSql(
101                sprintf('ALTER TABLE %sfaquser ALTER COLUMN ip VARCHAR(64)', $this->tablePrefix),
102                'Increase faquser.ip column size (SQL Server)',
103            );
104        }
105    }
106}