40 lines
1.4 KiB
PHP
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();
|
|
}
|
|
}
|
|
}
|