Files
trfgo/db/migrations/20260615102103_create_user_dashboard_layouts_table.php
T
2026-06-15 16:10:44 +02:00

40 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class CreateUserDashboardLayoutsTable extends AbstractMigration
{
public function up(): void
{
if (!$this->hasTable('user_dashboard_layouts')) {
$this->execute("
CREATE TABLE `user_dashboard_layouts` (
`idlayout` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`iduser` INT(10) UNSIGNED NOT NULL,
`page` VARCHAR(100) NOT NULL DEFAULT 'dashboard',
`layout_json` LONGTEXT NOT NULL,
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`idlayout`),
UNIQUE KEY `uq_user_dashboard_page` (`iduser`, `page`),
KEY `idx_dashboard_page` (`page`),
CONSTRAINT `fk_dashboard_layout_user`
FOREIGN KEY (`iduser`)
REFERENCES `auth_users` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
");
}
}
public function down(): void
{
if ($this->hasTable('user_dashboard_layouts')) {
$this->table('user_dashboard_layouts')->drop()->save();
}
}
}