72 lines
2.2 KiB
PHP
72 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Phinx\Migration\AbstractMigration;
|
|
|
|
/*
|
|
CREATE TABLE channels (
|
|
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
name VARCHAR(255) NOT NULL,
|
|
description TEXT NOT NULL,
|
|
link VARCHAR(255) NULL,
|
|
language VARCHAR(2) NOT NULL,
|
|
copyright VARCHAR(255) NULL,
|
|
explicit BOOLEAN DEFAULT false,
|
|
category VARCHAR(255),
|
|
|
|
owner_id INT(11) UNSIGNED NOT NULL,
|
|
|
|
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
|
|
PRIMARY KEY(`id`),
|
|
FOREIGN KEY(`owner_id`) REFERENCES users(`id`),
|
|
FOREIGN KEY(`image_id`) REFERENCES images(`id`),
|
|
UNIQUE KEY(`name`)
|
|
);
|
|
*/
|
|
|
|
final class CreateChannelsTable 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('channels')->addTimestamps();
|
|
|
|
$table->addColumn('name', 'string')
|
|
->addColumn('slug', 'string')
|
|
->addColumn('description', 'string', [ 'null' => false ])
|
|
->addColumn('link', 'string')
|
|
->addColumn('language', 'string', [
|
|
'default' => 'en',
|
|
'limit' => 2
|
|
])
|
|
->addColumn('copyright', 'string')
|
|
->addColumn('explicit', 'boolean', [ 'default' => false ])
|
|
->addColumn('owner_id', 'integer', [
|
|
'null' => false,
|
|
'signed' => false,
|
|
])
|
|
->addColumn('image_id', 'integer', [
|
|
'null' => true,
|
|
'signed' => false,
|
|
])
|
|
->addIndex([ 'name' ], [ 'unique' => true ])
|
|
->addForeignKey('owner_id', 'users')
|
|
->addForeignKey('image_id', 'images')
|
|
->create();
|
|
}
|
|
}
|