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

Added PGSQL Support #111

Merged
merged 10 commits into from
Feb 16, 2020
Merged

Added PGSQL Support #111

merged 10 commits into from
Feb 16, 2020

Conversation

rwdim
Copy link
Contributor

@rwdim rwdim commented Aug 25, 2018

Added functional postgresql support to this already fantastic utility.

@CristianLlanos
Copy link
Member

CristianLlanos commented Sep 2, 2018

Thanks for your contribution. Would you mind updating your branch with the latest changes, please? I'll wait for @gareth-ib's feedback and after that I'll merge your PR.

if (! $this->hasMapping()) {
throw new RuntimeException("There is no Schema Mapper registered for [{$this->type()}] connection.");
}

$schemas = forward_static_call([$this->getMapper(), 'schemas'], $this->connection);
Copy link
Member

Choose a reason for hiding this comment

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

Why did you remove these lines?

Copy link
Member

Choose a reason for hiding this comment

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

Please add them back. It's essential for the mapping process.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Except they render the code useless. When they are in, the code uses all schemas and generates all the tables from all the schemas, at least when using PostgreSQL. I tested it with and without on both and the functionality worked on both MySQL and PostgreSQL with the changes I made.
I'll do another round of testing, but I'm fairly certain I'll get the same result.

Copy link
Contributor Author

@rwdim rwdim Sep 3, 2018

Choose a reason for hiding this comment

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

It's important to note that I am running the latest Laravel Nova, and the behavior I experienced is using that code base. I will check both code bases to see if there's a difference in the behaviors.

Copy link
Member

Choose a reason for hiding this comment

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

You wouldn't notice the difference unless PostgreSQL supports multiple databases in a single database deamon as MySQL does. For instance, you can have a MySQL database a with a table a_table and a database b with a table b_table having a foreign key pointing to a.a_table. 😅 It's not easy to make a good example.

The key thing to generate proper relationships in our eloquent models would be being aware of cross-database relationships. I didn't find other way to achieve it.

@rwdim
Copy link
Contributor Author

rwdim commented Sep 3, 2018

I checked out the code, created an upstream reference to your repo, did a git fetch upstream and no changes were pulled as I had checked out your code the same day I made the changes. I restored your original code in SchemaManager and re-tested using MySQL and PGsql and they both worked fine, so I must have had a configuration issue at the time I did the original testing.

@rwdim
Copy link
Contributor Author

rwdim commented Sep 3, 2018 via email

@rwdim
Copy link
Contributor Author

rwdim commented Sep 4, 2018

The issue isn't about the same type of cross-database querying that you can do with MySql. That functionality isn't inherently available in PostgreSQL, at least not up to 10.0, without the use of plugins.

The issue is user rights and database isolation. PG allows each daemon access to all databases it knows about, and the only thing keeping an account from them is the role rights. In earlier versions, PG was less strict about enforcing those role rights.

In PG 8.3, which I still have a couple old dev databases running on, when you execute:

php artisan code:models  --schema=public

It spins forever, opens many, many connections, and generates all models for all databases your user has access to with public schemas.

When I do the same thing on 9.5, it isolates the user to the database and schema you've specified in your configuration.

Very odd behavior, but it works normally in current 9.5 and later versions.

@CristianLlanos
Copy link
Member

Wow! What do you suggest, @rwdim? Should we do something about it?

@CristianLlanos
Copy link
Member

CristianLlanos commented Sep 5, 2018

Where you say "it spins forever"... does it mean it never ends? 😅 'Cause if it does the job, I suppose, even if it takes too long, that would be OK? Obviously, there is room for improving efficiency 😅 but that might be subject for another PR.

@rwdim
Copy link
Contributor Author

rwdim commented Sep 5, 2018 via email

@CristianLlanos
Copy link
Member

Thanks 👍

@rwdim
Copy link
Contributor Author

rwdim commented Sep 6, 2018

Found one issue... I neglected to change the default table names to ignore...
Commit Link

Should I do a new PR?

Also started adding support for automatic Seeder and Migration support...

@CristianLlanos
Copy link
Member

It'd be better to add those features in different PRs, unless this PR needs them.

@rwdim
Copy link
Contributor Author

rwdim commented Sep 8, 2018 via email

@krlicmuhamed
Copy link

Any chance for publishing this PGSQL support?

@timhaak
Copy link
Contributor

timhaak commented Jan 27, 2020

Any chance for publishing this PGSQL support?

As they don't seem to be accepting pull requests and maintaining.

I've forked the repository and merged some of the pull requests.

https://github.com/haakco/reliese-laravel-models

https://packagist.org/packages/haakco/reliese-laravel-models

@CristianLlanos
Copy link
Member

@rwdim, thanks for all the effort you put into it.

@CristianLlanos CristianLlanos merged commit 5b29131 into reliese:master Feb 16, 2020
@rwdim
Copy link
Contributor Author

rwdim commented Feb 17, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants