Skip to content

Commit

Permalink
Add Indexes
Browse files Browse the repository at this point in the history
- EC-CUBE#1805

- dtb_customer
  - email
  - create_date
  - update_date
  - last_buy_date
  - buy_times
  - buy_total

- dtb_order
  - pre_order_id(EC-CUBE#1036)
  - order_email
  - order_date
  - payment_date
  - commit_date
  - update_date

- dtb_product_class
  - price02
  - stock, stock_unlimited

- dtb_page_layout
  - url
  • Loading branch information
nanasess committed Oct 14, 2016
1 parent d8324b8 commit fc8bd4c
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Eccube/Resource/doctrine/Eccube.Entity.Customer.dcm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ Eccube\Entity\Customer:
secret_key:
columns:
- secret_key
indexes:
# requires a length on MySQL
# dtb_customer_email_idx:
# columns:
# - email
dtb_customer_create_date_idx:
columns:
- create_date
dtb_customer_update_date_idx:
columns:
- update_date
dtb_customer_last_buy_date_idx:
columns:
- last_buy_date
dtb_customer_buy_times_idx:
columns:
- buy_times
dtb_customer_buy_total_idx:
columns:
- buy_total
id:
id:
type: integer
Expand Down
20 changes: 20 additions & 0 deletions src/Eccube/Resource/doctrine/Eccube.Entity.Order.dcm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@ Eccube\Entity\Order:
type: entity
table: dtb_order
repositoryClass: Eccube\Repository\OrderRepository
indexes:
# requires a length on MySQL
# dtb_order_pre_order_id_idx:
# columns:
# - pre_order_id
# dtb_order_order_email_idx:
# columns:
# - order_email
dtb_order_order_date_idx:
columns:
- order_date
dtb_order_payment_date_idx:
columns:
- payment_date
dtb_order_commit_date_idx:
columns:
- commit_date
dtb_order_update_date_idx:
columns:
- update_date
id:
id:
type: integer
Expand Down
5 changes: 5 additions & 0 deletions src/Eccube/Resource/doctrine/Eccube.Entity.PageLayout.dcm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ Eccube\Entity\PageLayout:
type: entity
table: dtb_page_layout
repositoryClass: Eccube\Repository\PageLayoutRepository
indexes:
# requires a length on MySQL
# dtb_page_layout_url_idx:
# columns:
# - url
id:
id:
type: integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ Eccube\Entity\ProductClass:
type: entity
table: dtb_product_class
repositoryClass: Eccube\Repository\ProductClassRepository
indexes:
dtb_product_class_price02_idx:
columns:
- price02
dtb_product_class_stock_stock_unlimited_idx:
columns:
- stock
- stock_unlimited
id:
id:
type: integer
Expand Down
100 changes: 100 additions & 0 deletions src/Eccube/Resource/doctrine/migration/Version20161014100031.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

namespace DoctrineMigrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

class Version20161014100031 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$this->createIndex($schema, 'dtb_product_class', array('price02'), 'dtb_product_class_price02_idx');
$this->createIndex($schema, 'dtb_product_class', array('stock', 'stock_unlimited'), 'dtb_product_class_stock_stock_unlimited_idx');
$this->createIndex($schema, 'dtb_customer', array('email'), 'dtb_customer_email_idx', array('email' => 256));
$this->createIndex($schema, 'dtb_customer', array('create_date'), 'dtb_customer_create_date_idx');
$this->createIndex($schema, 'dtb_customer', array('update_date'), 'dtb_customer_update_date_idx');
$this->createIndex($schema, 'dtb_customer', array('last_buy_date'), 'dtb_customer_last_buy_date_idx');
$this->createIndex($schema, 'dtb_customer', array('buy_times'), 'dtb_customer_buy_times_idx');
$this->createIndex($schema, 'dtb_customer', array('buy_total'), 'dtb_customer_buy_total_idx');
$this->createIndex($schema, 'dtb_order', array('pre_order_id'), 'dtb_order_pre_order_id_idx', array('pre_order_id' => 40));
$this->createIndex($schema, 'dtb_order', array('order_email'), 'dtb_order_order_email_idx', array('order_email' => 256));
$this->createIndex($schema, 'dtb_order', array('order_date'), 'dtb_order_order_date_idx');
$this->createIndex($schema, 'dtb_order', array('payment_date'), 'dtb_order_payment_date_idx');
$this->createIndex($schema, 'dtb_order', array('commit_date'), 'dtb_order_commit_date_idx');
$this->createIndex($schema, 'dtb_order', array('update_date'), 'dtb_order_update_date_idx');
$this->createIndex($schema, 'dtb_page_layout', array('url'), 'dtb_page_layout_url_idx', array('url' => 128));
}

/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
$this->dropIndex($schema, 'dtb_product_class', 'dtb_product_class_price02_idx');
$this->dropIndex($schema, 'dtb_product_class', 'dtb_product_class_stock_stock_unlimited_idx');
$this->dropIndex($schema, 'dtb_customer', 'dtb_customer_email_idx');
$this->dropIndex($schema, 'dtb_customer', 'dtb_customer_create_date_idx');
$this->dropIndex($schema, 'dtb_customer', 'dtb_customer_update_date_idx');
$this->dropIndex($schema, 'dtb_customer', 'dtb_customer_last_buy_date_idx');
$this->dropIndex($schema, 'dtb_customer', 'dtb_customer_buy_times_idx');
$this->dropIndex($schema, 'dtb_customer', 'dtb_customer_buy_total_idx');
$this->dropIndex($schema, 'dtb_order', 'dtb_order_pre_order_id_idx');
$this->dropIndex($schema, 'dtb_order', 'dtb_order_pre_order_email_idx');
$this->dropIndex($schema, 'dtb_order', 'dtb_order_pre_order_date_idx');
$this->dropIndex($schema, 'dtb_order', 'dtb_order_pre_payment_date_idx');
$this->dropIndex($schema, 'dtb_order', 'dtb_order_pre_commit_date_idx');
$this->dropIndex($schema, 'dtb_order', 'dtb_order_pre_update_date_idx');
$this->dropIndex($schema, 'dtb_page_layout', 'dtb_page_layout_url_idx');
}

/**
* @param Schema $schema
* @param string $tableName
* @param array $columns
* @param string $indexName
* @param array $length
*/
protected function createIndex(Schema $schema, $tableName, array $columns, $indexName, array $length = array())
{
if (!$schema->hasTable($tableName)) {
return false;
}

$table = $schema->getTable($tableName);
if (!$table->hasIndex($indexName)) {
if ($this->connection->getDatabasePlatform()->getName() == "mysql" && !empty($length)) {
$cols = array();
foreach ($length as $column => $len) {
$cols[] = sprintf('%s(%d)', $column, $len);
}
$this->addSql('CREATE INDEX '.$indexName.' ON '.$tableName.'('.implode(', ', $cols).');');
} else {
$table->addIndex($columns, $indexName);
}
return true;
}
return false;
}

/**
* @param Schema $schema
* @param string $tableName
* @param string $indexName
*/
protected function dropIndex(Schema $schema, $tableName, $indexName)
{
if (!$schema->hasTable($tableName)) {
return false;
}
$table = $schema->getTable($tableName);
if ($table->hasIndex($indexName)) {
$table->dropIndex($indexName);
return true;
}
return false;
}
}

0 comments on commit fc8bd4c

Please sign in to comment.