Phoenix 1.3: context and schema -- access to common table

I’ve been looking at Phoenix 1.3 … in my case it would make sense to have, say, contexts Reader and Editor where both have access to the document table via different schemas. Reader needs a smaller set of fields than does Editor. Is this possible? Or am I just on the wrong track?

In general I think Reader and Editor sound more like roles than contexts. You know your domain best though and if that’s a sensible way to organize your app you can certainly do it. I fell like you may end up having a lot of document-related functionality that’s not specific to Readers or Editors and it not be clear which context it belongs in. But not being familiar with your app it’s hard to say. If you go this route you’d need to create two schemas, Reader.Document and Editor.Document. Both schemas would be associated with the “documents” table. If you create them using generators you’ll need to edit the generated files a bit. You’ll want to edit the migration file for the first schema and change the table name from “reader_documents” to “documents” and add all the columns that the table needs, not just the ones that Reader.Document needs. You’ll want to delete the migration that’s generated for the second schema as the table will already exist. Then you’ll need to change the table names in both schema files from reader_documents and editor_documents to documents in both cases.

1 Like