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

Use bigint DBAL type for ID fields by default #2208

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions demos/_demo-data/create-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public function import(array $rowsMulti)
$model->addField('name', ['type' => 'string']);
$model->addField('type', ['type' => 'string']);
$model->addField('is_folder', ['type' => 'boolean']);
$model->addField('parent_folder_id', ['type' => 'integer']);
$model->addField('parent_folder_id', ['type' => 'bigint']);
(new Migrator($model))->create();
(new Migrator($model))->createForeignKey([$model->getField('atk_fp_file__parent_folder_id'), $model->getField('atk_fp_file__id')]);
$model->import([
Expand Down Expand Up @@ -1125,7 +1125,7 @@ public function import(array $rowsMulti)

$model = new ImportModelWithPrefixedFields($db, ['table' => 'product_sub_category']);
$model->addField('name', ['type' => 'string']);
$model->addField('product_category_id', ['type' => 'integer']);
$model->addField('product_category_id', ['type' => 'bigint']);
$productSubcategoryIdField = $model->getField('atk_fp_6f3c91cf51e02fd5__id');
(new Migrator($model))->create();
(new Migrator($model))->createForeignKey([$model->getField('atk_fp_6f3c91cf51e02fd5__product_category_id'), $productCategoryIdField]);
Expand All @@ -1144,8 +1144,8 @@ public function import(array $rowsMulti)
$model = new ImportModelWithPrefixedFields($db, ['table' => 'product']);
$model->addField('name', ['type' => 'string']);
$model->addField('brand', ['type' => 'string']);
$model->addField('product_category_id', ['type' => 'integer']);
$model->addField('product_sub_category_id', ['type' => 'integer']);
$model->addField('product_category_id', ['type' => 'bigint']);
$model->addField('product_sub_category_id', ['type' => 'bigint']);
(new Migrator($model))->create();
(new Migrator($model))->createForeignKey([$model->getField('atk_fp_product__product_category_id'), $productCategoryIdField]);
(new Migrator($model))->createForeignKey([$model->getField('atk_fp_product__6f3c91cf51e02fd5_id'), $productSubcategoryIdField]);
Expand All @@ -1163,7 +1163,7 @@ public function import(array $rowsMulti)
$model->addField('item', ['type' => 'string']);
$model->addField('inv_date', ['type' => 'date']);
$model->addField('inv_time', ['type' => 'time']);
$model->addField('country_id', ['type' => 'integer']);
$model->addField('country_id', ['type' => 'bigint']);
$model->addField('qty', ['type' => 'integer']);
$model->addField('box', ['type' => 'integer']);
(new Migrator($model))->create();
Expand Down
4 changes: 2 additions & 2 deletions demos/init-app.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function typecastAttributeSaveField(Field $field, $value): ?string
if ($field->type === WrappedIdType::NAME) {
return $value === null
? null
: $this->typecastAttributeSaveField(new Field(['type' => 'integer']), $value->getId() + 218_000_000);
: $this->typecastAttributeSaveField(new Field(['type' => 'bigint']), $value->getId() + 218_000_000);
}

return parent::typecastAttributeSaveField($field, $value);
Expand All @@ -57,7 +57,7 @@ public function typecastAttributeSaveField(Field $field, $value): ?string
public function typecastAttributeLoadField(Field $field, ?string $value)
{
if ($field->type === WrappedIdType::NAME) {
$value = $this->typecastAttributeLoadField(new Field(['type' => 'integer']), $value);
$value = $this->typecastAttributeLoadField(new Field(['type' => 'bigint']), $value);

return $value === null
? null
Expand Down
10 changes: 5 additions & 5 deletions demos/init-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getName(): string
#[\Override]
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
{
return DbalType::getType('integer')->getSQLDeclaration($fieldDeclaration, $platform);
return DbalType::getType('bigint')->getSQLDeclaration($fieldDeclaration, $platform);
}

#[\Override]
Expand All @@ -75,7 +75,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?int
return null;
}

return DbalType::getType('integer')->convertToDatabaseValue($value->getId(), $platform);
return DbalType::getType('bigint')->convertToDatabaseValue($value->getId(), $platform);
}

#[\Override]
Expand All @@ -85,7 +85,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?object
return null;
}

return new WrappedId(DbalType::getType('integer')->convertToPHPValue($value, $platform));
return new WrappedId((int) DbalType::getType('bigint')->convertToPHPValue($value, $platform)); // once DBAL 3.x support is dropped, the explicit cast should no longer be needed
}

#[\Override]
Expand Down Expand Up @@ -675,13 +675,13 @@ protected function init(): void
'expr' => function (Model /* TODO self is not working because of clone in Multiline */ $row) {
return $row->expr('{' . $this->fieldName()->qty . '} * {' . $this->fieldName()->box . '}'); // @phpstan-ignore method.notFound
},
'type' => 'integer',
'type' => 'bigint',
]);
$this->addCalculatedField($this->fieldName()->total_php, [
'expr' => static function (self $row) {
return $row->qty * $row->box;
},
'type' => 'integer',
'type' => 'bigint',
]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/multiline.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class InventoryItem extends \Atk4\Data\Model
$this->addField('box', ['type' => 'integer', 'caption' => '# of Boxes', 'required' => true, 'ui' => ['multiline' => [Form\Control\Multiline::TABLE_CELL => ['width' => 2]]]]);
$this->addExpression('total', ['expr' => function (Model $row) {
return $row->get('qty') * $row->get('box');
}, 'type' => 'integer']);
}, 'type' => 'bigint']);
}
}
```
Expand Down Expand Up @@ -242,7 +242,7 @@ $this->addExpression('total', [
'expr' => function (Model $row) {
return $row->get('qty') * $row->get('box');
},
'type' => 'integer',
'type' => 'bigint',
'ui' => ['multiline' => [Multiline::TABLE_CELL => ['width' => 1, 'class' => 'blue']]],
]);
```
Expand Down
2 changes: 2 additions & 0 deletions js/src/vue-components/multiline/multiline-header.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export default {
let align = 'left';
if (!column.isEditable) {
switch (column.type) {
case 'smallint':
case 'integer':
case 'bigint':
case 'float':
case 'atk4_money': {
align = 'right';
Expand Down
2 changes: 2 additions & 0 deletions public/js/atk-vue-multiline.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/js/atk-vue-multiline.js.map

Large diffs are not rendered by default.

Loading
Loading