-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(AppFramework): Add full support for date / time / datetime columns #47329
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
Changes from 1 commit
ee02e32
e314d52
db94e10
0e54c2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Signed-off-by: Ferdinand Thiessen <[email protected]>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -15,7 +15,6 @@ | |||
| /** | ||||
| * @method int getId() | ||||
| * @method void setId(int $id) | ||||
| * @psalm-type AllowedTypes = 'json'|'blob'|'datetime'|'string'|'int'|'integer'|'bool'|'boolean'|'float'|'double'|'array'|'object' | ||||
| * @since 7.0.0 | ||||
| * @psalm-consistent-constructor | ||||
| */ | ||||
|
|
@@ -26,7 +25,7 @@ abstract class Entity { | |||
| public $id; | ||||
|
|
||||
| private array $_updatedFields = []; | ||||
| /** @var array<string, AllowedTypes> */ | ||||
| /** @var array<string, \OCP\DB\Types::*> */ | ||||
|
Member
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. I'm really not sure about this change.
In general I also don't like the mix of dictionaries.
Contributor
Author
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. First of all the
We already have 3 different mapping for db types: So the
Good point I think we should fix this here!
Only for psalm, it still works so does not break. I do not think it makes sense to add arbitrary aliases, no?
Well there is only
Contributor
Author
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. We also could have just added more types, but then we end up with 3 different type sources for the same task (mapping PHP -> DB types).
Member
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.
Not sure what "migration column types" is? Migrations should use Then for now let's make sure all
Contributor
Author
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.
Not sure the
Makes sense, thank you for your feedback! |
||||
| private array $_fieldTypes = ['id' => 'integer']; | ||||
|
|
||||
| /** | ||||
|
|
@@ -67,7 +66,7 @@ public static function fromRow(array $row): static { | |||
|
|
||||
|
|
||||
| /** | ||||
| * @return array<string, AllowedTypes> with attribute and type | ||||
| * @return array<string, \OCP\DB\Types::*> with attribute and type | ||||
| * @since 7.0.0 | ||||
| */ | ||||
| public function getFieldTypes(): array { | ||||
|
|
@@ -260,7 +259,7 @@ public function getUpdatedFields(): array { | |||
| * that value once its being returned from the database | ||||
| * | ||||
| * @param string $fieldName the name of the attribute | ||||
| * @param AllowedTypes $type the type which will be used to match a cast | ||||
| * @param \OCP\DB\Types::* $type the type which will be used to match a cast | ||||
| * @since 7.0.0 | ||||
| */ | ||||
| protected function addType(string $fieldName, string $type): void { | ||||
|
|
||||
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.
Someone should write a Rector rule for this
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.
Also this is not a clean replacement.
Types::INTEGERis'integer'not'int'which was used in almost all apps (at least the ones I maintain which now have dozens of Psalm errors 🙈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.
Came back to check if this was intentional.
@susnux would there be any downside of allow "int" again?
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.
Yes it was, as
int,double, andboolwere never documented, onlyinteger,floatandbooleanwere part of our documentation (since Nextcloud 20: https://docs.nextcloud.com/server/20/developer_manual/basics/storage/database.html#types ).So the idea was to still allow them (it does not break) but make usage of it an error for static code checking to make developers aware they are using something undocumented.
Meaning to make it easier for us to change types if needed as we only need to change a single source of truth (the DB types).
From my side: just duplicates a state, but lets add it back to make it less noisy for developers!
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.
Fair enough,
intindeed wasn't documented!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.
Results: 116
Results: 175
So while it was never documented, it was working and is used almost 40% of the time 🙈 So yeah we can not have it in docs going forward, but should keep an eye on keeping it working, so apps don't break unnecessarily.
For bool its more based with 17 (bool) to 68 (boolean), but still 20%
double I didn't find a single result (in apps we marketed, ship, support or maintain), neither for array or object.
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.
Ref #48837