SiteWeaver_CMS/database/migrations/20260906050000_pages_add_is_home.php

44 lines
1.4 KiB
PHP
Raw Normal View History

<?php
/**
* 20260906050000_pages_add_is_home.php
*
* Author: Funky Waddle
* Date: 2026-09-06
*
* Purpose: Additive migration allowing a Page to be marked as the site's
* "home page" - when a request comes in for the URL root
* (`https://domain.tld/`), that Page is rendered instead of a 404. Only one
* Page may be the home page at a time; that invariant is enforced in
* `PageService`, not at the schema level, since portable partial-unique
* constraints aren't supported consistently across the multi-database
* targets in `tech_stack` (SQLite/MySQL-MariaDB/PostgreSQL). Does not alter
* any existing column on `pages`.
*/
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class PagesAddIsHome extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change(): void
{
$table = $this->table('pages');
$table->addColumn('is_home', 'boolean', ['null' => false, 'default' => false, 'comment' => 'Rendered at the URL root (/) when true; only one Page may have this set'])
->addIndex(['is_home'])
->update();
}
}