migration codeigniter spark

Created at: 2024-03-25 17:12:35 | Updated at: 2024-03-25 17:12:35

php spark make:migration create_categories_table


<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateCategoriesTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type'           => 'INT',
                'constraint'     => 11,
                'unsigned'       => true,
                'auto_increment' => true
            ],
            'name' => [
                'type'       => 'VARCHAR',
                'constraint' => '255',
            ],
            'svg' => [
                'type' => 'TEXT',
            ],
            'created_at' => [
                'type' => 'TIMESTAMP',
                'default' => 'current_timestamp()',
            ],
            'updated_at' => [
                'type' => 'TIMESTAMP',
                'default' => 'current_timestamp()',
            ]
        ]);
        $this->forge->addKey('id', true);
        $this->forge->createTable('categories');
    }

    public function down()
    {
        $this->forge->dropTable('categories');
    }
}


php spark make:migration create_etiquetas_table



<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateEtiquetasTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type'           => 'INT',
                'constraint'     => 11,
                'unsigned'       => true,
                'auto_increment' => true
            ],
            'name' => [
                'type'       => 'VARCHAR',
                'constraint' => '255',
            ],
            'svg' => [
                'type' => 'TEXT',
            ],
            'created_at' => [
                'type' => 'TIMESTAMP',
                'default' => 'current_timestamp()',
            ],
            'updated_at' => [
                'type' => 'TIMESTAMP',
                'default' => 'current_timestamp()',
            ]
        ]);
        $this->forge->addKey('id', true);
        $this->forge->createTable('etiquetas');
    }

    public function down()
    {
        $this->forge->dropTable('etiquetas');
    }
}


php spark make:migration create_post_etiquetas_table



<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreatePostEtiquetasTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'post_id' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
            ],
            'etiqueta_id' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
            ],
            'created_at' => [
                'type'    => 'TIMESTAMP',
                'default' => 'current_timestamp()',
            ],
            'updated_at' => [
                'type'    => 'TIMESTAMP',
                'default' => 'current_timestamp()',
            ]
        ]);

        $this->forge->addKey('post_id', true);
        $this->forge->addKey('etiqueta_id', true);

        // Claves Foráneas
        $this->forge->addForeignKey('post_id', 'posts', 'id', 'CASCADE', 'CASCADE');
        $this->forge->addForeignKey('etiqueta_id', 'etiquetas', 'id', 'CASCADE', 'CASCADE');

        $this->forge->createTable('post_etiquetas');
    }

    public function down()
    {
        $this->forge->dropTable('post_etiquetas');
    }
}



php spark make:migration create_posts_table



<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreatePostsTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type'           => 'INT',
                'constraint'     => 11,
                'unsigned'       => true,
                'auto_increment' => true
            ],
            'title' => [
                'type'       => 'VARCHAR',
                'constraint' => '255',
            ],
            'category_id' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
            ],
            // ... otras columnas ...
            'created_at' => [
                'type' => 'TIMESTAMP',
                'default' => 'current_timestamp()',
            ],
            'updated_at' => [
                'type' => 'TIMESTAMP',
                'default' => 'current_timestamp()',
            ]
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addForeignKey('category_id', 'categories', 'id', 'CASCADE', 'CASCADE');
        $this->forge->createTable('posts');
    }

    public function down()
    {
        $this->forge->dropTable('posts');
    }
}


  i finalment:


php spark migrate


No valid image directory found or the category is not valid for the gallery.

Back to Posts
migration codeigniter spark

Title

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.