Skip to content

Conversation

msmakouz
Copy link
Member

@msmakouz msmakouz commented Jan 23, 2024

What was changed

The ability to render column attributes as options in migrations has been added. This fixes the issue with MySQL unsigned and zerofill.

Related to: https://github.com/orgs/cycle/discussions/456

Example of generated code:

$this->table('test')
    ->addColumn('id', 'primary', [
        'nullable' => false,
        'defaultValue' => null,
        'size' => 11,
        'autoIncrement' => true,
        'unsigned' => false,
        'zerofill' => false,
    ])
    ->addColumn('unsigned', 'tinyInteger', [
        'nullable' => false,
        'defaultValue' => null,
        'size' => 4,
        'autoIncrement' => false,
        'unsigned' => true,
        'zerofill' => false,
    ])
    ->addColumn('zerofill', 'tinyInteger', [
        'nullable' => false,
        'defaultValue' => null,
        'size' => 4,
        'autoIncrement' => false,
        'unsigned' => false,
        'zerofill' => true,
    ])
    ->addColumn('int_size_attr', 'integer', [
        'nullable' => false,
        'defaultValue' => null,
        'size' => 4,
        'autoIncrement' => false,
        'unsigned' => false,
        'zerofill' => false,
    ])
    ->addColumn('int_size', 'integer', [
        'nullable' => false,
        'defaultValue' => null,
        'size' => 11,
        'autoIncrement' => false,
        'unsigned' => false,
        'zerofill' => false,
    ])
    ->addColumn('decimal_size_scale_attr', 'decimal', [
        'nullable' => false,
        'defaultValue' => null,
        'size' => 4,
        'precision' => 6,
        'scale' => 2,
    ])
    ->addColumn('decimal_size_scale_precision_attr', 'decimal', [
        'nullable' => false,
        'defaultValue' => null,
        'size' => 4,
        'precision' => 8,
        'scale' => 2,
    ])
    ->addColumn('decimal_size_scale', 'decimal', [
        'nullable' => false,
        'defaultValue' => null,
        'precision' => 4,
        'scale' => 2,
    ])
    ->addColumn('timestamp_size', 'timestamp', ['nullable' => false, 'defaultValue' => null, 'size' => 6])
    ->addColumn('timestamp_with_default', 'timestamp', [
        'nullable' => false,
        'defaultValue' => 'CURRENT_TIMESTAMP',
        'size' => 0,
   ])
   ->addColumn('string_size', 'string', ['nullable' => false, 'defaultValue' => 'foo', 'size' => 255])
   ->addColumn('username', 'string', ['nullable' => false, 'defaultValue' => null, 'size' => 255])
   ->addColumn('email', 'string', ['nullable' => false, 'defaultValue' => null, 'size' => 255])
   ->setPrimaryKeys(['id'])
   ->create();

@msmakouz msmakouz added type:bug Bug type:feature New feature. labels Jan 23, 2024
@msmakouz msmakouz requested a review from roxblnfk January 23, 2024 12:06
@msmakouz msmakouz self-assigned this Jan 23, 2024
@codecov
Copy link

codecov bot commented Jan 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d12f436) 95.34% compared to head (74c78d6) 95.34%.

Additional details and impacted files
@@            Coverage Diff            @@
##                4.x      #58   +/-   ##
=========================================
  Coverage     95.34%   95.34%           
- Complexity      245      246    +1     
=========================================
  Files            30       30           
  Lines           773      774    +1     
=========================================
+ Hits            737      738    +1     
  Misses           36       36           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@roxblnfk roxblnfk merged commit 519609a into 4.x Jan 25, 2024
@roxblnfk roxblnfk deleted the bugfix/mysql-attributes branch January 25, 2024 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Bug type:feature New feature.

Projects

Status: Released

Development

Successfully merging this pull request may close these issues.

3 participants