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

Set Postgres schema #104

Closed
EmileSpecs opened this issue Jun 29, 2020 · 3 comments
Closed

Set Postgres schema #104

EmileSpecs opened this issue Jun 29, 2020 · 3 comments
Assignees

Comments

@EmileSpecs
Copy link
Contributor

Can't seem to figure out how to set the Postgres schema.

In feathers-knex it can be set in die service options as well as through hooks (setting context.service.schema).

This doesn't seem to work with feathers-objection, is there some way to set the schema (it obviously defaults to "public")?

@dekelev
Copy link
Member

dekelev commented Jun 30, 2020

ObjectionJS has models (JSON Schema format) that is used for data validation, hooks, describe relations and more.

ObjectionJS models won't help you with schema migration - for this you can use Knex migrate tool.

Check here for how to initiated Knex with PostgreSQL or try with the following example:

{
      "client": "pg",
      "schema": "schema",
      "connection": {
        "host": "localhost",
        "port": 5432,
        "user": "postgres",
        "password": "",
        "database": "database"
     }
}

@dekelev dekelev closed this as completed Jun 30, 2020
@EmileSpecs
Copy link
Contributor Author

EmileSpecs commented Jun 30, 2020

Hi @dekelev
Thanks for the reply, I think you misunderstood my question.

Using feathers-knex my services are defined as:

module.exports = function (app) {
  const options = {
    Model: createModel(app),
    paginate: app.get('paginate'),
    schema: app.get('postgres').connection.schema // can set the schema on a per service basis
  };

  // Initialize our service with any options it requires
  app.use('/accounts', new Accounts(options, app));

  // Get our initialized service so that we can register hooks
  const service = app.service('accounts');

  service.hooks(hooks);
};

feathers-knex allows for a schema option in service options.

I cannot do the same with feathers-objection, it always defaults to the "public" schema.
I cannot initiate it in the knex connection (as you've shown above) as not all the services use the same schema.

Can I set the schema somewhere in a hook perhaps?

@dekelev dekelev reopened this Jul 4, 2020
@dekelev dekelev self-assigned this Jul 4, 2020
@dekelev
Copy link
Member

dekelev commented Jul 4, 2020

Thanks @EmileSpecs , PR released with v5.6.0

@dekelev dekelev closed this as completed Jul 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants