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

Unable to use db schema different than public for postgres #352

Open
osieltorres opened this issue Jul 17, 2022 · 1 comment
Open

Unable to use db schema different than public for postgres #352

osieltorres opened this issue Jul 17, 2022 · 1 comment

Comments

@osieltorres
Copy link

osieltorres commented Jul 17, 2022

I am having the following issue:
I have two models, User and Role, everything works fine until I tried to use PostgreSQL database custom schema rather than public . I have the following models:

// User model
class User extends Model {
  static table = 'new_schema.users';
  static timestamps = true;
  static fields = { ... };
  static role = () => this.hasOne(Role);
}
// Role model
class Role extends Model {
  static table = 'new_schema.roles';
  static timestamps = true;
  static fields = { ... };
  static users = () => this.hasOne(User);
}

Relationships.oneToOne(Role, User);

db.link([Role, User]);

The previous throws error:

error: Uncaught (in promise) PostgresError: relation "new_schema" does not exist
          error = new PostgresError(parseNoticeMessage(current_message));
               ^
    at Connection.#simpleQuery (https://deno.land/x/postgres@v0.14.2/connection/connection.ts:626:19)
    at async Connection.query (https://deno.land/x/postgres@v0.14.2/connection/connection.ts:875:16)
    at async PostgresConnector.query (https://deno.land/x/denodb@v1.1.0/lib/connectors/postgres-connector.ts:76:22)
    at async Database.query (https://deno.land/x/denodb@v1.1.0/lib/database.ts:240:21)
    at async Function.createTable (https://deno.land/x/denodb@v1.1.0/lib/model.ts:172:5)
    at async Database.sync (https://deno.land/x/denodb@v1.1.0/lib/database.ts:210:7)
    at async syncDatabase (file:///home/user/my_project/database/db.ts:62:7)
    at async file:///home/user/my_project/app.ts:33:24

Note that the tables are created in the correct schema new_schema if we remove relations between models, but it will fail if we setup any relation between models User and Role.

Questions:
Is there any way to setup tables within a custom schema different than default "public"?
What would be the correct way (if any) to use a custom schema for tables in order to get working the relation between models @eveningkid ?

@osieltorres osieltorres changed the title Not able to use schema different than public in postgres Unable to use db schema different than public for postgres Jul 22, 2022
@osieltorres
Copy link
Author

Is denodb still supported?

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

No branches or pull requests

1 participant