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

Apply default collation on tables as per documentation (new #1165) #1169

Merged
merged 1 commit into from
Dec 9, 2017

Conversation

nebez
Copy link
Contributor

@nebez nebez commented Sep 5, 2017

Closed and re-opened from #1165 as I put new commits into my own master branch - use this one instead please

As per the documentation on environment configuration, there should be an option named collation. This configuration option doesn't do anything when you set it.

This change will set the default collation of newly created tables in this order:

  1. The collation option provided in the array of options
  2. The collation option provided in the environment configuration
  3. utf8_general_ci

@@ -300,6 +300,32 @@ public function testCreateTableWithMyISAMEngine()
$this->assertEquals('MyISAM', $row['Engine']);
}

public function testCreateTableAndInheritDefaultCollation()
{
$options = array(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short array syntax must be used to define arrays

$adapter->createDatabase($options['name']);
$adapter->disconnect();

$table = new \Phinx\Db\Table('table_with_default_collation', array(), $adapter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short array syntax must be used to define arrays

@nebez
Copy link
Contributor Author

nebez commented Oct 25, 2017

Any chance this gets merged? Just fixed the merge conflicts and new stickler-ci linter errors.

@codecov-io
Copy link

Codecov Report

Merging #1169 into master will increase coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1169      +/-   ##
==========================================
+ Coverage   72.19%   72.24%   +0.05%     
==========================================
  Files          35       35              
  Lines        5549     5553       +4     
==========================================
+ Hits         4006     4012       +6     
+ Misses       1543     1541       -2
Impacted Files Coverage Δ
src/Phinx/Db/Adapter/MysqlAdapter.php 98.13% <100%> (+0.32%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 02e1888...0ab243d. Read the comment docs.

@nebez
Copy link
Contributor Author

nebez commented Dec 6, 2017

Any news on getting this merged?

$defaultOptions,
array_intersect_key($this->getOptions(), $defaultOptions),
$table->getOptions()
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are those assoc arrays? then we should merge with + Operator IMO

Copy link
Member

@dereuromark dereuromark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for looking into this.

@chinpei215
Copy link
Contributor

What if we remove the hardcoded default settings instead? I think we should not overwrite default settings on the database.

@nebez
Copy link
Contributor Author

nebez commented Dec 7, 2017

@chinpei215 - I totally agree that Phinx setting its own default to override the DB's default is a bit odd. But would that be considered backwards incompatible? Phinx has always been doing it, I think if we changed it now that would break a lot of setups if people relied on that default collation.

@chinpei215
Copy link
Contributor

@nebez Fair points. OK, I will confirm your patch on my local environment, as I have a little concern about charset/collation mismatch between database settings and configurations (I may be wrong though). And if there are no problems, I will also approve your pull request.

@nebez
Copy link
Contributor Author

nebez commented Dec 7, 2017

@chinpei215 Does a second PR make sense to remove the default entirely?
It'd be very beneficial to my team so we can stop specifying collation everywhere, but it would need to be communicated to everyone or included in a major version bump.

@chinpei215
Copy link
Contributor

@nebez Personally, I would like to remove the default entirely. I think it would confuse users. And if someone wants some default collation and/or engine, I think they should change DEFAULT CHARACTER SET on the database, and/or the default_storage_engine variable. But yes, probably we would need to communicate with others.

@chinpei215
Copy link
Contributor

OK. First I thought we should merge not only collation, but also charset. But now I know the option is not used when creating tables. CHARACTER SET seems to be determined by collation:

if (isset($options['collation'])) {
$charset = explode('_', $options['collation']);
$optionsStr .= sprintf(' CHARACTER SET %s', $charset[0]);
$optionsStr .= sprintf(' COLLATE %s', $options['collation']);
}

So there is no need to merge the option at this point. If no one argues, I will merge this PR.

@nebez
Copy link
Contributor Author

nebez commented Dec 7, 2017

Sounds good @chinpei215 - thanks for taking this on!

@chinpei215 chinpei215 self-assigned this Dec 8, 2017
@chinpei215 chinpei215 merged commit 45c68d2 into cakephp:master Dec 9, 2017
@chinpei215
Copy link
Contributor

Merged. Thank you for your contribution.

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

Successfully merging this pull request may close these issues.

6 participants