8000 Enable MySQL Driver by hanhan1978 · Pull Request #168 · owl/owl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Enable MySQL Driver #168

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

Merged
merged 2 commits into from
Oct 23, 2016
Merged

Enable MySQL Driver #168

merged 2 commits into from
Oct 23, 2016

Conversation

hanhan1978
Copy link
Contributor
@hanhan1978 hanhan1978 commented Oct 2, 2016

Change mysql setting [strict] false => true
=> avoid migration error for creatd_at default value(0)

Change migration files for MySQL

  1. remove query builder method [after]
    => caused mysql error (may be fixed in Laravel 5.1~)
  2. change token column data type from text to varchar(512)
    => cannot set unique index for blob data type in MySQL

Add setting in .env.example
=> default sqlite

Sync .env setting int .env.behat
=> add database config

Add MySQL specific repository for fulltext search
=> MySQL/ItemFtsRepository
=> MySQL/TagFtsRepository

@hanhan1978 hanhan1978 changed the title Enable MySQL Driver #38 8000 Enable MySQL Driver Oct 2, 2016
@sota1235
Copy link
Member
sota1235 commented Oct 3, 2016

Related #38

$res = $this->searchService->itemMatchCount($q);
$pagination = new Paginator($results, $res[0]->count, $this->perPage, null, array('path' => '/search'));
$count = $this->searchService->itemMatchCount($q);
$pagination = new Paginator($results, $count, $this->perPage, null, array('path' => '/search'));
Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -127,6 +127,7 @@ public function matchCount($str)
WHERE
fts.words MATCH :match
__SQL__;
return \DB::select(\DB::raw($query), array( 'match' => FtsUtils::createMatchWord($str)));
$res = \DB::select(\DB::raw($query), array( 'match' => FtsUtils::createMatchWord($str)));
return $res[0]->count;
Copy link
Member

Choose a reason for hiding this comment

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

お手数ですがphpdocの@returnの方も修正していただけますか…!

$table->integer('tag_id')->unsigned();
$table->foreign('tag_id')->references('id')->on('tags');
$table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade');
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

対応ダン!

Copy link
Member
@fortkle fortkle Oct 8, 2016

Choose a reason for hiding this comment

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

既存マイグレーションを修正してしまうと既にこのマイグレーションを実行済みの場合に変更を適用できなくなってしまうので、新しいマイグレーションファイルで modify columnしてもらいたいです...

参考
http://stackoverflow.com/questions/26820788/add-on-delete-cascade-to-existing-column-in-laravel

hanhan1978 added a commit to hanhan1978/owl that referenced this pull request Oct 3, 2016
*
* @param int $tag_id
* @param string $words
* @return stdClass
Copy link
Member

Choose a reason for hiding this comment

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

arrayにしましょ! そして申し訳ないんですが、 app/Repositories/Fluent/TagFtsRepository.php の同じ箇所も arrayに変えていただけると... 🙏

->references('id')->on('users')
->onDelete('cascade')->onUpdate('cascade');
$table->text('token')->unique();
$table->string('token', 512)->unique();
Copy link
Member
@fortkle fortkle Oct 8, 2016

Choose a reason for hiding this comment

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

mysql都合の変更なので、 if (env('DB_DRIVER') === 'mysql') していただけると..

(unsignedをsqlite側に適用するなら ここと同じ理由 で別マイグレーションファイルにしたいです...。別ファイルが面倒だと思うのでmysql側だけunsignedでもいいかなと思います)

@@ -17,7 +17,7 @@ public function up()
$table->integer('user_id')
->references('id')->on('users')
->onDelete('cascade')->onUpdate('cascade');
10000 $table->text('token')->unique();
$table->string('token', 512)->unique();
Copy link
Member

Choose a reason for hiding this comment

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

@@ -15,7 +15,7 @@ public function up()
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('username')->after('id')->unique();
$table->string('username')->unique();
Copy link
Member

Choose a reason for hiding this comment

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

ここはcreateですし実質変更ないので大丈夫ですかね。

@@ -15,7 +15,7 @@ public function up()
Schema::create('user_roles', function(Blueprint $table)
{
$table->increments('id');
$table->string('name')->after('id')->unique();
Copy link
Member

Choose a reason for hiding this comment

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

ここもcreateですし実質変更ないので大丈夫ですかね。

@@ -17,7 +17,7 @@ public function up()
{
Schema::table('users', function($table)
{
$table->string('role')->after('password')->default(self::ROLE_ID_MEMBER);
$table->string('role')->default(self::ROLE_ID_MEMBER);
Copy link
Member
@fortkle fortkle Oct 8, 2016

Choose a reason for hiding this comment

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

あれ、そもそもここで after()削除してるのって何か理由ありますか?
(MySQL onlyな指定なのでこれまでのsqliteでは効いてないのでちょっとアレですが、mysqlなら消さなくてもいいのでは?と。そして消さなくていいなら余分なdiffは作らない方がいいかなと!)

remove query builder method [after] => caused mysql error (may be fixed in Laravel 5.1~)

これでしたね。。 🙇
消してOKです!

@fortkle
Copy link
Member
fortkle commented Oct 8, 2016

@hanhan1978
thanks for your PR.
please check some of my comments 🙏

@fortkle
Copy link
Member
fortkle commented Oct 9, 2016

あー、、あと何よりPRの出し先がmasterではなくdevelop・・・・

@hanhan1978
Copy link
Contributor Author

そうだった。developだった...。久しぶりすぎてowlのルールを忘れてました・・・

\App::bind('Owl\Repositories\ItemRepositoryInterface', 'Owl\Repositories\Fluent\ItemRepository');
\App::bind('Owl\Repositories\ItemFtsRepositoryInterface', 'Owl\Repositories\Fluent\ItemFtsRepository');
if(env('DB_DRIVER', 'sqlite') == 'mysql') {
Copy link
Member

Choose a reason for hiding this comment

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

ここ、PSR-2に合わせてifとelseの前後などに半角スペース1つください...

(phpcsの代わりにscrutinizerにしたのでエラー出てない.... 🙇 )

$fts->words = FtsUtils::toNgram($item->title . "\n\n" . $item->body);
$fts->save();
}
if(env('DB_DRIVER') === 'mysql'){
Copy link
Member

Choose a reason for hiding this comment

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

Hide comment

ここもスペース!

@@ -32,7 +39,15 @@ public function up()
*/
public function down()
{
DB::statement('DROP TABLE items_fts ;');
if(env('DB_DRIVER') === 'mysql') {
Copy link
Member

Choose a reason for hiding this comment

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

ここもスペース!

$fts->words = FtsUtils::toNgram($tag->name);
$fts->save();
}
if(env('DB_DRIVER') === 'mysql'){
Copy link
Member

Choose a reason for hiding this comment

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

ここも(

@@ -31,7 +37,13 @@ public function up()
*/
public function down()
{
DB::statement('DROP TABLE tags_fts ;');
if(env('DB_DRIVER') === 'mysql'){
Copy link
Member

Choose a reason for hiding this comment

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

ここm(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

すいません、IDEに不慣れだったせいで、タブとスペースが混ざっていたことに今さっき気づきました。とりあえず指摘点を修正し終わったら、その辺相談させて下さい。

@fortkle fortkle assigned hanhan1978 and unassigned fortkle Oct 9, 2016
hanhan1978 added a commit to hanhan1978/owl that referenced this pull request Oct 13, 2016
- Append space after if/else to follow psr2
- Fix php doc return type
- Revert change in migrations
- Separate migration by database schema
- modify item_tag foreign key constraint
    -> Add delete cascade for mysql compatibility
- Fix migration rollback for items table
    -> must drop fulltext index before changing collation of a related column.
Change mysql setting [strict] false => true
  => avoid migration error for creatd_at default value(0)
Change migration files for MySQL
  1. remove query builder method [after]
    => caused mysql error (may be fixed in Laravel 5.1~)
  2. change token column data type from text  to varchar(512)
    => cannot set unique index for blob data type in MySQL
Add setting in .env.example
  => default sqlite
Sync .env setting int .env.behat
  => add database config
Add MySQL specific repository for fulltext search
  => MySQL/ItemFtsRepository
  => MySQL/TagFtsRepository
- Append space after if/else to follow psr2
- Fix php doc return type
- Revert change in migrations
- Separate migration by database schema
- modify item_tag foreign key constraint
    -> Add delete cascade for mysql compatibility
- Fix migration rollback for items table
    -> must drop fulltext index before changing collation of a related column.
@hanhan1978 hanhan1978 changed the base branch from master to develop October 13, 2016 04:26
@hanhan1978 hanhan1978 force-pushed the features/mysql-driver branch from 3352f28 to 87e21c2 Compare October 13, 2016 05:00
@hanhan1978
Copy link
Contributor Author

@fortkle @sota1235 修正&developに切り替えました。ご確認よろしくです。

@fortkle
Copy link
Member
fortkle commented Oct 23, 2016

@hanhan1978
LGTM!!
最高にクールなPRでした!マージします!!

LGTM! Please wait until the image is uploaded...

@fortkle fortkle merged commit 327bd83 into owl:develop Oct 23, 2016
@fortkle fortkle mentioned this pull request Oct 11, 2017
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.

3 participants
0