slovocast/app/db/migrations/20240627230956_create_episodes_table.php

67 lines
2.1 KiB
PHP
Raw Normal View History

2024-06-27 23:24:56 +00:00
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
/*
CREATE TABLE episodes (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
link VARCHAR(255) NOT NULL,
duration VARCHAR(127) NOT NULL COMMENT "HH:MM:SS representation",
length INT(11) UNSIGNED NOT NULL COMMENT "Length in seconds",
description TEXT NOT NULL,
explicit BOOLEAN NOT NULL DEFAULT true,
channel_id INT(11) UNSIGNED NOT NULL,
image_id INT(11) UNSIGNED NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
2024-06-27 23:24:56 +00:00
PRIMARY KEY(`id`),
FOREIGN KEY(`channel_id`) REFERENCES channels(`id`),
FOREIGN KEY(`image_id`) REFERENCES images(`id`)
);
*/
final class CreateEpisodesTable 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('episodes')->addTimestamps();
$table->addColumn('title', 'string', [ 'null' => false ])
->addColumn('link', 'string')
->addColumn('duration', 'string')
2024-11-08 03:49:59 +00:00
->addColumn('length', 'integer', [ 'signed' => false ])
2024-06-27 23:24:56 +00:00
->addColumn('description', 'text')
->addColumn('explicit', 'boolean', [ 'default' => false ])
2024-11-08 03:49:59 +00:00
->addColumn('channel_id', 'integer', [
'signed' => false,
'null' => false
])
->addColumn('image_id', 'integer', [
2024-11-08 03:49:59 +00:00
'signed' => false,
'null' => true
])
2024-06-27 23:24:56 +00:00
->addForeignKey('channel_id', 'channels')
->addForeignKey('image_id', 'images');
$table->create();
}
}