plankanban / planka

The realtime kanban board for workgroups built with React and Redux.
https://planka.app
GNU Affero General Public License v3.0
7.67k stars 708 forks source link

Make default schema name for databse configurable #544

Open hazayan opened 9 months ago

hazayan commented 9 months ago

Currently when a planka database is created, or queried, knex defaults to using public as the schema name. Would it be acceptable to allow the possibility to pass a custom schema name through an environment variable to knex, the same way the database connection url is ? (I can create a PR for that if this gets approved).

//knexfile would become
module.exports = {
  client: 'pg',
  connection: {
    connectionString: process.env.DATABASE_URL,
    ssl: buildSSLConfig(),
    searchPath: [process.env.DEFAULT_SCHEMA || 'public'],
  },
  migrations: {
    tableName: 'migration',
    directory: path.join(__dirname, 'migrations'),
  },
  seeds: {
    directory: path.join(__dirname, 'seeds'),
  },
  wrapIdentifier: (value, origImpl) => origImpl(_.snakeCase(value)),
};
meltyshev commented 9 months ago

Hi! Is this only needed in Knex? Since we only use it for migrations and the application itself uses Waterline. But in any case, PRs are always welcome :)

hazayan commented 9 months ago

Actually I found a much easier solution with no code change required. At least for the docker based deployment. Obviously this solution doesn't change the fact that the database url, database adapter and database schema should be made explicitly configurable along with sane defaults.

So the solution in question is to override the /app/config/env/production.js with a local version of the same file having the diff below, in the docker-compose.yml section for the planka app, effectively allowing for the schema name to be passed on as an environment variable.

diff --git a/server/config/env/production.js b/server/config/env/production.js
index bed4f31..55e40ee 100644
--- a/server/config/env/production.js
+++ b/server/config/env/production.js
@@ -50,6 +50,9 @@ module.exports = {
      */

     default: {
+      url: process.env.DATABASE_URL,
+      adapter: process.env.DATABASE_ADAPTER,
+      schemaName: process.env.DATABASE_SCHEMA,
       // adapter: 'sails-mysql',
       // url: 'mysql://user:password@host:port/database',
       /**