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

Postgres DDL Schemas #117

Open
akosasante opened this issue Jul 1, 2021 · 1 comment
Open

Postgres DDL Schemas #117

akosasante opened this issue Jul 1, 2021 · 1 comment

Comments

@akosasante
Copy link

Is it possible to pass a schema/prefix to the library if my Postgres tables are in a schema different from the default 'public' one? For ecto itself, I'm able to do this by setting a prefix, following the instructions in the Ecto docs:

### config/dev.exs
use Mix.Config

# Configuring postgres schema to use for all queries
query_args = ["SET search_path TO dev", []]

# Configure your database
config :my_app, MyApp.Repo,
  username: username,
  password: password,
  database: database,
  hostname: "localhost",
  show_sensitive_data_on_connection_error: true,
  pool_size: 10,
  after_connect: {Postgrex, :query!, query_args}

But not sure how to do something similar with Plsm.

@tomjoro
Copy link

tomjoro commented Aug 12, 2021

I have a fork that will do this. It's not too difficult in my fork.

  1. You specify schemas in configuration file like this:
...
  username: "someone",
  password: "******",  
  module_name: "SomeModule",
  type: :postgres,
  schemas: [  "debt", "accounts"]   # the default is 'public' if you don't specify any schemas

And then it generates the schema by and adds the Ecto prefix for them like this (note the @schema_prefix):

defmodule SomeModule.Invoice do
  use Ecto.Schema
  import Ecto.Changeset

  @schema_prefix "debt"
  @primary_key false
  schema "invoice" do
    field :billing_date, :date, primary_key: false
...

I'm still working on the changes. I was going to change the Module name so that it is namespaced as well because you might have same table name in multiple schemas... like this:
SomeModule.Debt.Invoice

I could generate a pull request but probably need some help testing and finalizing...

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

2 participants