-
Notifications
You must be signed in to change notification settings - Fork 51
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
long size varchar with long index size mysql #210
Changes from 2 commits
534fb6b
6dfc741
fef0691
fa88dfb
ffe17f8
ae14887
8485a3c
8eb5a44
fda4df6
f77cbbd
c2a3354
6a7e558
a3ad9ca
577751d
92054f4
c96d008
f1ea80a
a25f7d6
c58ab07
44b4eff
a65d9e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,34 +148,48 @@ public function createCollection(string $name, array $attributes = [], array $in | |
$database = $this->getDefaultDatabase(); | ||
$namespace = $this->getNamespace(); | ||
$id = $this->filter($name); | ||
$collectionAttributes = []; | ||
|
||
foreach ($attributes as $key => $attribute) { | ||
$attrId = $this->filter($attribute->getId()); | ||
$attrType = $this->getSQLType($attribute->getAttribute('type'), $attribute->getAttribute('size', 0), $attribute->getAttribute('signed', true)); | ||
$size = $attribute->getAttribute('size', 0); | ||
$type = $attribute->getAttribute('type'); | ||
$signed = $attribute->getAttribute('signed', false); | ||
$attrType = $this->getSQLType($type, $size, $signed); | ||
|
||
if ($attribute->getAttribute('array')) { | ||
$attrType = 'LONGTEXT'; | ||
} | ||
|
||
$attributes[$key] = "`{$attrId}` {$attrType}, "; | ||
$collectionAttributes[$attrId] = $attribute; | ||
} | ||
|
||
foreach ($indexes as $key => $index) { | ||
$indexId = $this->filter($index->getId()); | ||
$indexType = $index->getAttribute('type'); | ||
|
||
$indexAttributes = $index->getAttribute('attributes'); | ||
|
||
foreach ($indexAttributes as $nested => $attribute) { | ||
$indexLength = $index->getAttribute('lengths')[$key] ?? ''; | ||
$indexLength = (empty($indexLength)) ? '' : '(' . (int)$indexLength . ')'; | ||
$indexOrder = $index->getAttribute('orders')[$key] ?? ''; | ||
$indexAttribute = $this->filter($attribute); | ||
|
||
//$collectionAttributes[$indexAttribute]['size'] = $collectionAttributes[$indexAttribute]['size'] ?? 0; | ||
$size = isset($index['lengths'][$key]) ? $index['lengths'][$key]:0 ; | ||
|
||
if($collectionAttributes[$indexAttribute]['type'] === Database::VAR_STRING){ | ||
if($collectionAttributes[$indexAttribute]['size'] > 700){ | ||
$size = $size === 0 || $size > 700 ? 700 : $size; | ||
} | ||
} | ||
|
||
$length = $size === 0 ? '' : '(' . $size . ')'; | ||
$indexOrder = $index->getAttribute('orders')[$key] ?? ''; | ||
|
||
if ($indexType === Database::INDEX_FULLTEXT) { | ||
$indexOrder = ''; | ||
} | ||
|
||
$indexAttributes[$nested] = "`{$indexAttribute}`{$indexLength} {$indexOrder}"; | ||
$indexAttributes[$nested] = "`{$indexAttribute}`{$length} {$indexOrder}"; | ||
} | ||
|
||
$indexes[$key] = "{$indexType} `{$indexId}` (" . \implode(", ", $indexAttributes) . " ),"; | ||
|
@@ -368,7 +382,6 @@ public function deleteAttribute(string $collection, string $id, bool $array = fa | |
* @param array $orders | ||
* @return bool | ||
* @throws Exception | ||
* @throws PDOException | ||
*/ | ||
public function createIndex(string $collection, string $id, string $type, array $attributes, array $lengths, array $orders): bool | ||
{ | ||
|
@@ -383,6 +396,18 @@ public function createIndex(string $collection, string $id, string $type, array | |
}, $attributes); | ||
|
||
foreach ($attributes as $key => $attribute) { | ||
|
||
// $size = (int)($lengths[$key] ?? 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we need this part? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the Index size, not the attribute size, it is not mandatory. |
||
// foreach ($collectionAttributes as $ca){ | ||
// if($attribute === $ca['key']){ | ||
// if($ca['type'] == Database::VAR_STRING){ | ||
// if($ca['size'] > 700){ | ||
// $size = $size === 0 || $size > 700 ? 700 : $size; | ||
// } | ||
// } | ||
// } | ||
// } | ||
|
||
$length = $lengths[$key] ?? ''; | ||
$length = (empty($length)) ? '' : '(' . (int)$length . ')'; | ||
$order = $orders[$key] ?? ''; | ||
|
@@ -1790,7 +1815,6 @@ protected function getSQLIndex(string $collection, string $id, string $type, ar | |
|
||
default: | ||
throw new Exception('Unknown Index Type:' . $type); | ||
break; | ||
} | ||
|
||
return "CREATE {$type} `{$id}` ON {$this->getSQLTable($collection)} ( " . implode(', ', $attributes) . " )"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1176,6 +1176,7 @@ public function renameIndex(string $collection, string $old, string $new): bool | |
* @param array $orders | ||
* | ||
* @return bool | ||
* @throws Exception | ||
*/ | ||
public function createIndex(string $collection, string $id, string $type, array $attributes, array $lengths = [], array $orders = []): bool | ||
{ | ||
|
@@ -1184,7 +1185,10 @@ public function createIndex(string $collection, string $id, string $type, array | |
} | ||
|
||
$collection = $this->silent(fn() => $this->getCollection($collection)); | ||
|
||
if($collection->isEmpty()){ | ||
throw new Exception('Not found'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we missing this check from other methods? We should make sure we keep a consistent behavior across the library. Please add this check in other places when absolutely needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. I added some more checks like this where the collection was called. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to |
||
} | ||
|
||
// index IDs are case insensitive | ||
$indexes = $collection->getAttribute('indexes', []); | ||
/** @var Document[] $indexes */ | ||
|
@@ -1219,7 +1223,6 @@ public function createIndex(string $collection, string $id, string $type, array | |
|
||
default: | ||
throw new Exception('Unknown index type: ' . $type); | ||
break; | ||
} | ||
|
||
$index = $this->adapter->createIndex($collection->getId(), $id, $type, $attributes, $lengths, $orders); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what this variable name should indicate. The story of this new logic is not very clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it for functions I think it is much clear now.