-
Notifications
You must be signed in to change notification settings - Fork 46
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
Plugin does not work with db schemas other than "public" #76
Comments
After some further investigation, it seems that it works with different schemas as well but only if it the same as the db username. Postgres has a feature where it searches automatically for schema names public and $user so that's why it only works in these cases. It still won't work for any other arbitrary schema name. The other thing that I found out while investigating this issue on our side is that in the code snippet above, you are using knex.js raw query without using prepared statements. This is a HUGE issue on it's own and you should fix it ASAP even though you are not assigning user-input data to |
I found a workaround for this issue by applying this configuration in strapi db configuration file: module.exports = ({ env }) => ({
connection: {
client: 'postgres',
connection: {
host: "localhost",
port: 5432,
database: "mystrapidb",
user: "strapiuser",
password: "strapipwd",
schema: "strapischema",
},
searchPath: ["strapiuser", "strapischema", "public"], // add your schema name to this array and also your db username to preserve default functionality
debug: false,
}, |
I think that's an important point you raised about replacing raw sql queries with the knex query builder. I wonder if it's possible to go a step further and use the strapi ORM instead and if performance permits this. Because this will make it easier to maintain the plugin especially when breaking changes are made to strapi/core. Or maybe this isn't the route to take as the ORM will trigger lifecycle methods. What were your design considerations here in terms of bypassing the strapi orm for a sql query? Just trying to gain an understanding of the project as I may contribute in the future. Thanks for open-sourcing this plugin btw. It is very valuable to me :) |
Hi @jpizzle34, I will be taking over the maintenance of the plugin. I definitely agree with you that replacing the sql raw queries with something else will make it easier to maintain the plugin. This should be also one of our priorities once we solve the patch package problem. |
Can you guys please add "Doesn't work under schemas other than public" under Known Limitations? |
Hi, @IvanCodeslol will do :) Thank you for the suggestion |
Bug report
Describe the bug
If Strapi is using postgres db schema other than the default public or the one named the same as the db user e.g. DB_USERNAME=strapi SCHEMA_NAME=strapi, it fails in places where custom SQL queries are written, e.g. beforeUpdate.js lifecycle hook or beforeDelete.js hook.
Steps to reproduce the behavior
Expected behavior
User should be able to delete or update/publish versioned entry
Code snippets
same applies for
beforeUpdate.js
System
The text was updated successfully, but these errors were encountered: