migration codeigniter spark

migration codeigniter spark

  • migration codeigniter spark

    migration codeigniter spark

    migration codeigniter spark...

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


6 posts relacionats

  • Author
    Joan Puig

    posts Array Pdo

    Una manera adequada de nomenar aquesta consulta PDO podria ser "ObtenirPàginesPerCategoriaIEtiqueta... READ MORE
  • Author
    Joan Puig

    Quina és la diferència entre PDO i MySQLi?

    El que no està tan definit és quina és la millor manera de connectar-se a MySQL fent servir PHP. ... READ MORE
  • Author
    Joan Puig

    tailwind 5 filtres i paginacio a postslar11

    tailwind 5 filtres i paginacio a postslar11... READ MORE
  • Author
    Joan Puig

    optimitzar imatges en php

    optimitzar imatges en php... READ MORE
  • Author
    Joan Puig

    migrations

    la migracio crea i administra les taules a la base de dades de laravel... READ MORE
  • Author
    Joan Puig

    paginació en Laravel

    📌 Resum de la paginació en Laravel Laravel proporciona diferents maneres d’implementar la pagi... READ MORE