Add some migrations for the CodeIgniter application.

This commit is contained in:
Dave Smith-Hayes 2024-05-13 19:52:05 -04:00
parent 0152db25e9
commit 06c1d292bb
8 changed files with 132 additions and 4 deletions

View File

@ -0,0 +1,39 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class AddUsers extends Migration
{
public function up(): void
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'unsigned' => true,
'auto_increment' => true,
],
'email' => [
'type' => 'VARCHAR',
'constraint' => 255
],
'password' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
'name' => [
'type' => 'VARCHARD',
'constraint' => 255,
]
]);
$this->forge->addKey('id', true);
$this->forge->createTable('users');
}
public function down(): void
{
$this->forge->dropTable('users');
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
/**
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,
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,
PRIMARY KEY(`id`),
FOREIGN KEY(`owner_id`) REFERENCES users(`id`),
FOREIGN KEY(`image_id`) REFERENCES images(`id`),
UNIQUE KEY(`name`)
*/
class CreateChannels extends Migration
{
public function up(): void
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'unsigned' => true,
'auto_increment' => true,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
'description' => [
'type' => 'TEXT',
],
'link' => [
'type' => 'TEXT'
],
'language' => [
'type' => 'VARCHAR',
'constraint' => 2,
],
'copyright' => [
'type' => 'VARCHAR',
'constraint', 255,
],
]
]);
$this->forge->createTable('channels');
}
public function down(): void
{
$this->forge->dropTable('channels');
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateEpisodes extends Migration
{
public function up()
{
//
}
public function down()
{
//
}
}

View File

@ -9,4 +9,4 @@ CREATE TABLE users (
PRIMARY KEY(`id`),
UNIQUE KEY(`email`)
) Engine=InnoDb;
);

View File

@ -7,4 +7,4 @@ CREATE TABLE images (
PRIMARY KEY(`id`),
UNIQUE KEY(`url`)
) Engine=InnoDb;
);

View File

@ -18,4 +18,4 @@ CREATE TABLE channels (
FOREIGN KEY(`owner_id`) REFERENCES users(`id`),
FOREIGN KEY(`image_id`) REFERENCES images(`id`),
UNIQUE KEY(`name`)
) Engine=InnoDb;
);

View File

@ -17,4 +17,4 @@ CREATE TABLE episodes (
PRIMARY KEY(`id`),
FOREIGN KEY(`channel_id`) REFERENCES channels(`id`),
FOREIGN KEY(`image_id`) REFERENCES images(`id`)
) Engine=InnoDb;
);

3
sql/05-transactions.sql Normal file
View File

@ -0,0 +1,3 @@
CREATE TABLE `transactions` (
);