cakephp / cakephp/phinx

Inconsistent table encoding?

Open
#2,071 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
4.5k
Forks
884
PR merge metrics
No merged PRs in 30d

Description

I've got a database that I've developed over time using Phinx. One issue I discovered along the way was that the tables were formatted using the latin1 character set and cp1252 West European encoding. So while consolidating Phinx migrations, I started explicitly setting the encoding as seen below:

<?php
declare(strict_types=1);

use Migrations\AbstractMigration;

class CreateCarts extends AbstractMigration
{
    /**
     * Change Method.
     *
     * More information on this method is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     * @return void
     */
    public function change()
    {
        $table = $this->table('carts', [
            'encoding' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            ])
            ->addColumn('user_id', 'integer', [
                'default' => null,
                'null' => false,
                ])
            ->addColumn('cart_status', 'string', [
                'default' => 'active',
                'null' => false,
                ])
            ->addColumn('created', 'datetime', [
                'default' => null,
                'null' => false,
            ])
            ->addColumn('modified', 'datetime', [
                'default' => null,
                'null' => false,
            ])
            ->addColumn('cart_total', 'float', [
                'default' => null,
            ]);
        $table->create();
    }
}

However, when reviewing the tables, I discovered that not all of the tables are properly encoded despite explicitly being set in the options array shown here? Some do indeed take the UTF-8 multibyte encoding and some do not.

There are no other, altering migrations any longer because I consolidated them: only one migration creates a database and it does not get altered futher in the migration process. Any idea why this would be?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the CreateCarts migration and its change() method, especially the table() encoding and collation options. Compare the resulting tables with the migration definitions and determine why some do not use utf8mb4. Done means the cause is reproducible and the expected encoding behavior is clearly established.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.