Commit f73b042c authored by Yassine Doghri's avatar Yassine Doghri
Browse files

feat(categories): create model, entity, migrations and seeds

parent 69e72667
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -10,3 +10,5 @@ WORKDIR /castopod
RUN apt-get update && apt-get install -y \
    libicu-dev \
    && docker-php-ext-install intl

RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
+17 −0
Original line number Diff line number Diff line
@@ -82,6 +82,23 @@ docker ps -a
>
> _NB._ `./mariadb`, `./phpmyadmin` folders will be mounted in the project's root directory to persist data and logs.


### Initialize and populate database

Build the database with the migrate command:

```bash
# loads the database schema during first migration
docker-compose run --rm app php spark migrate
```

Populate the database with the required data:

```bash
# Populates all categories
docker-compose run --rm app php spark db:seed CategorySeeder
```

### Start hacking

You're all set! Start working your magic by updating the project's files! Help yourself to the [CodeIgniter4 User Guide](https://codeigniter.com/user_guide/index.html) for more insights.
+6 −2
Original line number Diff line number Diff line
<?php namespace Config;
<?php

namespace Config;

require_once SYSTEMPATH . 'Config/AutoloadConfig.php';

@@ -11,7 +13,9 @@ require_once SYSTEMPATH . 'Config/AutoloadConfig.php';
 */
class Autoload extends \CodeIgniter\Config\AutoloadConfig
{
	public $psr4 = [];
	public $psr4 = [
		'App'       => APPPATH,
	];

	public $classmap = [];

+20 −0
Original line number Diff line number Diff line
<?php

namespace App\Controllers;

use \CodeIgniter\Controller;

class Migrate extends Controller
{

    public function index()
    {
        $migrate = \Config\Services::migrations();

        try {
            $migrate->latest();
        } catch (\Exception $e) {
            // Do something with the error here...
        }
    }
}
+41 −0
Original line number Diff line number Diff line
<?php

namespace App\Database\Migrations;

use \CodeIgniter\Database\Migration;

class AddCategories extends Migration
{

    public function up()
    {
        $this->forge->addField([
            'id'          => [
                'type'           => 'INT',
                'constraint'     => 10,
                'unsigned'       => TRUE,
            ],
            'parent_id'          => [
                'type'           => 'INT',
                'constraint'     => 10,
                'unsigned'       => TRUE
            ],
            'apple_category'       => [
                'type'           => 'VARCHAR',
                'constraint'     => '1024',
            ],
            'google_category' => [
                'type'           => 'VARCHAR',
                'constraint'           => '1024',
            ],
        ]);
        $this->forge->addKey('id', TRUE);
        $this->forge->addForeignKey('parent_id', 'categories', 'id');
        $this->forge->createTable('categories');
    }

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