Pulling schema updates from Postgres Db

I have few node microservices connected to single postgres db. I also have an elixir service for realtime message passing between BE and FE.

I am now enhancing realtime service with some additional features, so I added ecto and ash_postgres to mix and connected with postgres. Since core app is nodejs, I want that to be source of truth for db schema changes, and elixir should pull updated schema into the model layer. We have multi schema db, and public schema would be readonly, and elx would be full access schema for elixir.

I tried this using introspex
`mix ecto.gen.schema --repo RealtimeService.Repo.Public --path lib/realtime_service/ --module-prefix RealtimeService.Db.Public.Models --schema public` and it was able to generate initial schema but it just wrote comments for fields with enums and jsonb objects. Also I could not pull updates again.

Can someone guide me properly, most of chatgpt answers were wrong, Claude helped a little but now its just imagining things. I might be a programmer for decade but I am an elixir newbie

  1. I need a way to update model layer in elixir app, from db, any changes in db schema even if only needed by elixir app, will be done from node app to maintain single source of truth for db.
  2. Need enums also, jsonb could simply be a map, and I think array were successfully pulled.
  3. I also need to be able to pull schema changes again, without overwriting everything back.

Thanks.

Requires using Ash, but ash_postgres can do at least some of this. I don’t recall if we extract enums or not but that could be added likely. I think your question was tagged ash-postgres on happenstance not because you actually were using Ash, but thats what tagged me to come look :smiley:

If you use the --fragments option, it will keep a separate file per resource updated which is “managed” so as things change you can rerun and it will replace that fragment.

1 Like

I added ash as tag because we are planning to use it for this feature, Its still on design phase so not much has been added as of yet. This was just some attempt to check if its possible to safely maintain single source of truth for db schema.

I will try your method today and let you know.. Thanks.