Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Migration409
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 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
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3/**
4 * Migration for phpMyFAQ 4.0.9.
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 Migration409 extends AbstractMigration
26{
27    public function getVersion(): string
28    {
29        return '4.0.9';
30    }
31
32    public function getDependencies(): array
33    {
34        return ['4.0.7'];
35    }
36
37    public function getDescription(): string
38    {
39        return 'PostgreSQL sequence for faqseo table';
40    }
41
42    public function up(OperationRecorder $recorder): void
43    {
44        // PostgreSQL-only migration for faqseo sequence
45        if ($this->isPostgreSql()) {
46            $sequenceName = $this->tablePrefix . 'faqseo_id_seq';
47
48            $recorder->addSql(
49                sprintf('CREATE SEQUENCE %s', $sequenceName),
50                'Create sequence for faqseo table (PostgreSQL)',
51            );
52
53            $recorder->addSql(
54                sprintf(
55                    "ALTER TABLE %sfaqseo ALTER COLUMN id SET DEFAULT nextval('%s')",
56                    $this->tablePrefix,
57                    $sequenceName,
58                ),
59                'Set default for faqseo.id using sequence (PostgreSQL)',
60            );
61
62            $recorder->addSql(
63                sprintf(
64                    "SELECT setval('%s', COALESCE((SELECT MAX(id) FROM %sfaqseo), 0))",
65                    $sequenceName,
66                    $this->tablePrefix,
67                ),
68                'Set sequence value to max id (PostgreSQL)',
69            );
70
71            $recorder->addSql(
72                sprintf('ALTER TABLE %sfaqseo ALTER COLUMN id SET NOT NULL', $this->tablePrefix),
73                'Set faqseo.id as NOT NULL (PostgreSQL)',
74            );
75        }
76    }
77}