Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent table encoding? #2071

Open
tbelknapsgs opened this issue Feb 15, 2022 · 1 comment
Open

Inconsistent table encoding? #2071

tbelknapsgs opened this issue Feb 15, 2022 · 1 comment

Comments

@tbelknapsgs
Copy link

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?

@MasterOdin
Copy link
Member

You could try the --dry-run flag to see a print of all create commands that get run to see if any are missing the encoding / collation arguments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants