Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

AccountInfoRequest validation connection support #3687

Merged
merged 2 commits into from
May 10, 2021
Merged

AccountInfoRequest validation connection support #3687

merged 2 commits into from
May 10, 2021

Conversation

devpreview
Copy link
Contributor

No description provided.

@welcome
Copy link

welcome bot commented Apr 28, 2021

BOOM! Your first PR with us, thank you so much! Someone will take a look at it shortly.

Please keep in mind that:

  • if this constitutes a breaking change, it might take quite a while for this to get merged; we try to emulate the Laravel release cycle as much as possible, so developers can upgrade both software once; this means a new big release every ~6 months;
  • even if it's a non-breaking change, it might take a few days/weeks for the PR to get merged; unless it's a no-brainer, we like to have some community feedback on new features, before we merge them; this leads to higher-quality code, in the end; we learnt this the hard way :-)
  • not all PRs get merged; sometimes we just have to hold out new features, to keep the packages lean; sometimes we don't include features that only apply to niche use cases;
  • we're not perfect; if you think we're wrong, call us out on it; but in a kind way :-) we all make mistakes, best we learn from them and build better software together;

Thank you!

--
Justin Case
The Backpack Robot

@request-info
Copy link

request-info bot commented Apr 28, 2021

Hi there!

Could you please provide us with more info about this? Looks like you skipped the title/body.

Thank you!

--
Justin Case
The Backpack Robot

@pxpm
Copy link
Contributor

pxpm commented Apr 28, 2021

Hello @devpreview thanks for the PR.

Can you please clarify why this is needed ? Why use the connection name (mysql, sqlite, mongodb) to get the table name ?

If you use prefixes in your tables you should add that prefix to your database.php config file in your connection: 'prefix' => 'your_table_prefix'.

If you need the same connection with/without prefix just duplicate it and set the $connection property on model to use the one you need.

Don't forget to clear your config cache php artisan config:clear

Let me know,
Pedro

@devpreview
Copy link
Contributor Author

Hello @pxpm

I will refactor legacy project and
I have two connections:

mysql (default, with prefix 'v2_') connection for new models

'mysql' => [
  'driver' => 'mysql',
  'host' => env('DB_HOST', '127.0.0.1'),
  'port' => env('DB_PORT', '3306'),
  'database' => env('DB_DATABASE', 'forge'),
  'username' => env('DB_USERNAME', 'forge'),
  'password' => env('DB_PASSWORD', ''),
  ...
  'prefix' => 'v2_',
  ...
],

and mysql_compat (without prefix) connection for old models

'mysql' => [
  'driver' => 'mysql',
  'host' => env('DB_HOST', '127.0.0.1'),
  'port' => env('DB_PORT', '3306'),
  'database' => env('DB_DATABASE', 'forge'),
  'username' => env('DB_USERNAME', 'forge'),
  'password' => env('DB_PASSWORD', ''),
  ...
  'prefix' => '',
  ...
],

And Backpack Admin model Administrator with mysql_compat connection:

class Administrator extends Authenticatable
{
  ...
  protected $connection = 'mysql_compat';
  ...
}

On update /admin/edit-account-info I have error:

Illuminate\Database\QueryException
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sr111.v2_administrators' doesn't exist (SQL: select count(*) as aggregate from `v2_administrators` where `email` = sabo@devpreview.ru and `id` <> 10)

I think need specifying the connection is necessary for such cases

@promatik
Copy link
Contributor

promatik commented May 2, 2021

Indeed, to use a different connection we need to add the connection to the string.

@pxpm I didn't know about Model connections, it's actually very useful.
I'm not sure if this issue will pop in other places of backpack.

@promatik promatik added Minor Bug A bug that happens only in a very niche or specific use case. and removed needs-more-info labels May 2, 2021
@tabacitu
Copy link
Member

tabacitu commented May 3, 2021

I'm not sure if this issue will pop in other places of backpack.

I think it will. What do you guys think about doing this inside getTableWithPrefix() - would that solve it everywhere? Good/bad idea?

Copy link
Contributor

@pxpm pxpm left a comment

Choose a reason for hiding this comment

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

Sorry @devpreview I was unware of that caveat of Rule::unique. Totally makes sense, we need connection there to correctly make it work.

From my tests we don't need getTableWithPrefix here.

I've just corrected @promatik suggestion to don't use it.

@promatik
Copy link
Contributor

promatik commented May 4, 2021

@pxpm please check my last comment above, #3687 (comment)

@tabacitu I tested, and we don't need to "hack" into getTableWithPrefix 🙌 😅
Using a different connection everything seems to work. Lists, Creates, Updates, probably only minor stuff may appear, things like what this PR fixes (profile update).

@pxpm pxpm assigned promatik and unassigned pxpm May 5, 2021
@scrutinizer-notifier
Copy link

The inspection completed: No new issues

@tabacitu tabacitu merged commit d63a87a into Laravel-Backpack:master May 10, 2021
@welcome
Copy link

welcome bot commented May 10, 2021

WHOOP-WHOOP! Congrats, your first PR on this repo has officialy been merged.

party

You should also receive an email inviting you to the Community Members team. That's where we, commited community members, debate new features and decide what's in the Backpack roadmap. Feel free to ignore the invitation if you're not interested :-)

If you want to help out the community in other ways, you can:

  • give your opinion on other Github Issues & PRs;
  • chat with others in the Gitter Chatroom (usually for quick help: How do I do X);
  • answer Backpack questions on Stackoverflow; you get points, people get help; you can subscribe to the backpack-for-laravel tag by adding a new filter; that will send you emails when new questions come up with our tag;

Again. Thank you for the PR. You are a wonderful person. Keep 'em coming :-)
Cheers!

--
Justin Case
The Backpack Robot

P.S. Help in the Backpack community is rewarded with free Backpack commercial licenses. It's the least we can do. If you feel you've helped the community with PRs, help & other stuff, please apply for free licenses and mention this PR. You scratch my back, I scratch your back. Thank you!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Minor Bug A bug that happens only in a very niche or specific use case.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants