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 Postgres Adapter #107

Merged
merged 58 commits into from
Jan 26, 2023
Merged

Add Postgres Adapter #107

merged 58 commits into from
Jan 26, 2023

Conversation

vermakhushboo
Copy link
Member

@vermakhushboo vermakhushboo commented Feb 4, 2022

Work in progress

Edge cases in Appwrite but not in Utopia

  • Had to change the exception type to ‘Throwable’ instead of ‘PDOException’ for Appwrite as the exception wasn’t getting captured in createDocument and updateDocument methods
    TODO:

    • Add more tests that throw exceptions not caught by PDOException
    • Find places where we throw the wrong errors
    • Rethrow exceptions that Appwrite can understand
  • There are not enough tests in Utopia to verify that double-quotes were needed around {$attribute} in the find() method to handle reserved words
    TODO:

  • Had to remove all alphanumeric values in getSQLCondition() method. Need to add better edge cases for full-text search in Utopia, it is missing many cases
    TODO:

    • Add more tests to cover similar scenarios in Utopia
    • For example email ids etc
    • Add tests specific to databases

Improvements needed in Appwrite for future adapters
TODO:

  • Hardcoded DB names in init.php, realtime.php, worker.php. Create generic interface for all adapters, allowing configurations using env variables
  • Add health check method to each adapter
  • Had to create a file PostgresSQLStatement.php and override Swoole methods, potentially move it to Utopia in the future

@vermakhushboo vermakhushboo marked this pull request as draft February 4, 2022 15:50
@kevinjoshi46b
Copy link

Hey @vermakhushboo ,
I have started working on adding postgres adapter a few days back. I had created a rfc for the same and had a discussion regarding me starting to work on it on appwrites discord server as well.
Are you working on it too?

@vermakhushboo
Copy link
Member Author

Hey @vermakhushboo , I have started working on adding postgres adapter a few days back. I had created a rfc for the same and had a discussion regarding me starting to work on it on appwrites discord server as well. Are you working on it too?

Hey @KevinJ-hub, have you made considerable progress on the same? If yes, please take this forward, otherwise, I'd request you to pick something else.

@kevinjoshi46b
Copy link

Hey @vermakhushboo , I have started working on adding postgres adapter a few days back. I had created a rfc for the same and had a discussion regarding me starting to work on it on appwrites discord server as well. Are you working on it too?

Hey @KevinJ-hub, have you made considerable progress on the same? If yes, please take this forward, otherwise, I'd request you to pick something else.

Yes, I have started working on it from January. I had a discussion with the appwrite team on their discord server as well regarding me working on this and then on their approval, I started to work on it.

@christyjacob4
Copy link
Contributor

@KevinJ-hub Please create a PR with your changes. The postgres adapter has a high priority at the moment and we want to ensure you have enough time to pick it up. We're expecting to ship it in the coming week. Let us know if you would be able to commit to it 🙂

@kevinjoshi46b
Copy link

@KevinJ-hub Please create a PR with your changes. The postgres adapter has a high priority at the moment and we want to ensure you have enough time to pick it up. We're expecting to ship it in the coming week. Let us know if you would be able to commit to it slightly_smiling_face

@christyjacob4 Ohhh, I won't be able to commit on finishing it in a week since I am currently a bit caught up with college work. If thats the case then its fine @vermakhushboo you can please continue with postgres adapter I might pick something else and work on it. 👍

@christyjacob4
Copy link
Contributor

@KevinJ-hub Thank you so much for understanding! Really appreciate the honesty. If you need some guidance on issues you can pick up, please let me know. I'd be happy to assist.

@vermakhushboo vermakhushboo marked this pull request as ready for review March 9, 2022 19:17
Copy link

@kevinjoshi46b kevinjoshi46b left a comment

Choose a reason for hiding this comment

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

Hey @vermakhushboo ,
The double quotes wrapped around role in read and write permission seem to be redundent over here since they do not get stored in the postgres DB. So I would like to request you to please check it once and remove them.

VALUES ({$columns} :_uid, :_read, :_write)");

$read = array_map(fn($role) => '"'.$role.'"', $document->getRead());

Choose a reason for hiding this comment

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

The double quotes wrapped around role seem to be redundent


$read = array_map(fn($role) => '"'.$role.'"', $document->getRead());
$write = array_map(fn($role) => '"'.$role.'"', $document->getWrite());

Choose a reason for hiding this comment

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

Same as above

SET {$columns} _uid = :_uid, _read = :_read, _write = :_write WHERE _uid = :_uid");

$read = array_map(fn($role) => '"'.$role.'"', $document->getRead());

Choose a reason for hiding this comment

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

Same as above


$read = array_map(fn($role) => '"'.$role.'"', $document->getRead());
$write = $read = array_map(fn($role) => '"'.$role.'"', $document->getWrite());

Choose a reason for hiding this comment

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

Same as above

Copy link
Member

@abnegate abnegate left a comment

Choose a reason for hiding this comment

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

Looks really good! One small type change and some readability updates and I think we'll be good to go 😁

src/Database/Adapter/Postgres.php Outdated Show resolved Hide resolved
src/Database/Adapter/Postgres.php Outdated Show resolved Hide resolved
src/Database/Adapter/Postgres.php Outdated Show resolved Hide resolved
src/Database/Adapter/Postgres.php Outdated Show resolved Hide resolved
@abnegate abnegate merged commit acb7f0a into main Jan 26, 2023
@abnegate abnegate deleted the feat-postgresql-adapter branch November 23, 2023 01:50
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapter Add support for a new Database Adapter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants