cakephp / cakephp/phinx

Precision and Scale bug mysql

Open
#1,481 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When I create table with column decimal, for example:

->addColumn(
                'id_usuario_inclusao', 
                'decimal', [
                    'default' => null,
                    'null' => false,
                    'precision' => 30,
                    'scale' => 0
                ])

the method protected function getColumnSqlDefinition() in Phinx\Db\Adapter\MysqlAdapter, no set precision and scale because the verification if ($column->getPrecision() && $column->getScale()) { not works.

If I set scale how true, 1 and more it works, for example:

->addColumn(
                'id_usuario_inclusao', 
                'decimal', [
                    'default' => null,
                    'null' => false,
                    'precision' => 30,
                    'scale' => true
                ])

My suggest is change the verification if to:

 if ($column->getPrecision() && $column->getScale()) {
            $def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')';
        } elseif ($column->getScale()) {
            $def .= '(' . 10 . ',' . $column->getScale() . ')';
        } elseif ($column->getPrecision()) {
            $def .= '(' . $column->getPrecision() . ',' . 0 . ')';
        }

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 in Phinx\Db\Adapter\MysqlAdapter, in protected getColumnSqlDefinition(), and reproduce the decimal-column case with precision 30 and scale 0. Check the generated MySQL column definition for zero-valued scale or precision, then verify that the resulting SQL preserves the requested decimal precision and scale.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, php
Domain
database
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.