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

Add AppFramework/Db base classes #17486

Closed
wants to merge 1 commit into from
Closed

Conversation

rullzer
Copy link
Member

@rullzer rullzer commented Oct 9, 2019

This will allow apps to use Entities that do not have an id attribute.
They can have other unique columns forcing an id is not ideal in all
cases.

For this two base classes are introduced and the current Entity and
QBMapper are actually based on the base classes.

The Entity is really simple and just adds the id property.
The BaseMapper is a bit less clean. As we can't know the where clause
for insert/delete or update parts.

Signed-off-by: Roeland Jago Douma roeland@famdouma.nl

@rullzer rullzer added enhancement 2. developing Work in progress labels Oct 9, 2019
@rullzer rullzer added this to the Nextcloud 18 milestone Oct 9, 2019
@rullzer
Copy link
Member Author

rullzer commented Oct 12, 2019

oooo the irony... this now fails because I made the classes strict.
But the setLastCheck is typehinted with an int. but we didn't convert the value yet.
Time to extract this as well

@ChristophWurst
Copy link
Member

2. developing

What's missing?

@rullzer
Copy link
Member Author

rullzer commented Oct 29, 2019

rebase and passing tests I think ;)

@ChristophWurst
Copy link
Member

Let's do this then :)

@rullzer rullzer modified the milestones: Nextcloud 18, Nextcloud 19 Dec 9, 2019
@rullzer rullzer force-pushed the enh/appframework/db_base branch 2 times, most recently from 472989f to c2a8624 Compare February 7, 2020 06:51
@rullzer rullzer added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Feb 7, 2020
Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

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

Looks fine otherwise!

lib/public/AppFramework/Db/QBBaseMapper.php Outdated Show resolved Hide resolved
Copy link
Member

@juliusknorr juliusknorr left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@rullzer rullzer force-pushed the enh/appframework/db_base branch 2 times, most recently from 873e56a to 001c624 Compare February 7, 2020 10:16
@kesselb
Copy link
Contributor

kesselb commented Feb 7, 2020

Does that still make sense? Having tables without a primary key. Percona already has some issues with those tables and also MySQL is adding a flag to enforce primary keys: #16311 (comment). It seems to be required for row based replication.

👍 for the change in general (it's much cleaner now) but we should probably enforce a primary key.

@ChristophWurst
Copy link
Member

It's not about having no primary key. But allowing other types or a composite key.

@kesselb
Copy link
Contributor

kesselb commented Feb 7, 2020

But allowing other types or a composite key.

Or no primary key. A id column was enforced before. I would prefer a getPrimaryKey method to be overwritten by subclasses and a default update method using getPrimaryKey. Laravel is using a similar approach: https://github.com/laravel/framework/blob/7efc5377ada189e707855b9e17e6159a1d350073/src/Illuminate/Database/Eloquent/Model.php#L45-L50

@ChristophWurst
Copy link
Member

Or no primary key. A id column was enforced before. I would prefer a getPrimaryKey method to be overwritten by subclasses

That should be doable. Like simple method that returns an array.

a default update method using getPrimaryKey

Should work as well if we know the types of the columns.

Laravel is using a similar approach

I remember fighting with composite keys and Laravel's Eloquent. They only allow a single key, right? All you can do is move it to another column.

@nickvergessen
Copy link
Member

nickvergessen commented Feb 26, 2020

So, how to continue?

We kind of need this in talk for the sessions table (nextcloud/spreed#2020). There is a unique string column "session" var(255), so there is no need for a second column to be unique

@kesselb
Copy link
Contributor

kesselb commented Feb 26, 2020

I would suggest to rename session to id, disable autoincrement, and use session as value. That should be possible without any change in server.

@nickvergessen
Copy link
Member

nickvergessen commented Feb 26, 2020

$qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))

There is code assuming id is int, so not without any changes at least.
But other places can be overwritten.

So we just fix that one thing and carry on?

@kesselb
Copy link
Contributor

kesselb commented Feb 26, 2020

😖

@nickvergessen
Copy link
Member

So something like #19659 should solve this?

@kesselb
Copy link
Contributor

kesselb commented Feb 26, 2020

Hmm. That might work. It was probably a bad suggestion to enforce a primary key code wise. It's still possible to use the query builder then. We might document (don't use tables without primary keys to make sure also row based replication works well) somewhere but don't enforce it.

@nickvergessen
Copy link
Member

We might document (don't use tables without primary keys to make sure also row based replication works well) somewhere but don't enforce it.

That has nothing to do with the entities however. We want to move more things over to those entities, instead of having the same customer stuff everywhere, because there are artificial limitations in the abstract base class.

@kesselb
Copy link
Contributor

kesselb commented Feb 26, 2020

All right. Another rebase and let's get this in 🎉

This will allow apps to use Entities that do not have an id attribute.
They can have other unique columns forcing an id is not ideal in all
cases.

For this two base classes are introduced and the current Entity and
QBMapper are actually based on the base classes.

The Entity is really simple and just adds the id property.
The BaseMapper is a bit less clean. As we can't know the where clause
for insert/delete or update parts.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
@nickvergessen
Copy link
Member

You misunderstood.... I think we should "just" merge #19659

@ChristophWurst
Copy link
Member

You misunderstood.... I think we should "just" merge #19659

And this PR :)

This was referenced Apr 4, 2020
This was referenced Apr 15, 2020
@rullzer
Copy link
Member Author

rullzer commented Apr 16, 2020

so going over this again...

what is the verdict. Composite keys? Or will that do boom.

@nickvergessen
Copy link
Member

Therewasa topic/issue somewhere with a couple of galera cluster people which apparently can not handle tables without a primary key. Let me find it and see if we can ask the experts

@nickvergessen
Copy link
Member

Can't find it anymore

@kesselb
Copy link
Contributor

kesselb commented Apr 21, 2020

Therewasa topic/issue somewhere with a couple of galera cluster people which apparently can not handle tables without a primary key. Let me find it and see if we can ask the experts

Sounds like #16311

@rullzer rullzer mentioned this pull request Apr 23, 2020
11 tasks
@rullzer rullzer modified the milestones: Nextcloud 19, Nextcloud 20 Apr 24, 2020
@MorrisJobke MorrisJobke mentioned this pull request Aug 11, 2020
57 tasks
@rullzer rullzer modified the milestones: Nextcloud 20, Nextcloud 21 Aug 11, 2020
@rullzer rullzer closed this Nov 9, 2020
@skjnldsv skjnldsv deleted the enh/appframework/db_base branch March 14, 2024 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants