General development - AlfredGranson/pcrm GitHub Wiki
Common tools
General commands
- Running tests:
MIX_ENV=test mix test
DB commands
Since pcrm employs phoenix it also employs ecto. It is encouraged to read the ecto docs, however, the most used tools for working with pcrm are documented here.
Generating a new resource
LiveView
- Generate a new live resource with mix phx.gen.live.
ex:
mix phx.gen.live Customers Customer customers family_name:string
- The console will provide you with a list of routes to include in the
lib/pcrm_web/router.ex
file under the/
scope. - Before migrating, update the new migration file to correspond with pcrm's standards.
- Ensure
citext
is enabled after thedef change do
:ex:
execute "CREATE EXTENSION IF NOT EXISTS citext", "DROP EXTENSION IF EXISTS citext"
- Ensure the table's id is a uuid.
- Indicate
primary_key: false
in thecreate table
attributesex:
create table(:customers, primary_key: false) do
- Add the uuid as a field.
ex:
add :id, :binary_id, primary_key: true
- Update fields to reflect types
- Text fields that require sorting should be changed from type
:string
to type:citext
- Required fields should have
null: false
added to their attributes.ex:
add :family_name, :citext, null: false
- Text fields that require sorting should be changed from type
- Indicate
- Ensure
- Update the new schema file to correspond with pcrm's standards.
- Indicate the id is a uuid.
ex:
@primary_key {:id, :binary_id, autogenerate: true}
- Remove non-required fields from the
validate_required
function call.ex:
|> validate_required([:family_name])
- Indicate the id is a uuid.
- Several
.html.heex
files will be generated inlib/pcrm_web/[resource name]_live/
.- All generated text custom to the resource should be translated using
dgettext
provided the resource's name as a domain (lower case and plural)ex:
<%= dgettext "customers", "Family name"%>
- All universal generated text should be translated using
gettext
ex:
<%= gettext "Welcome to %{name}!", name: "pcrm" %>
- Run
mix gettext.extract --merge
inside the container. This will update the translation files inside ofpriv/gettext
. Any strings that require translated should be done so at this point.
- All generated text custom to the resource should be translated using
- The generated controller (ex.
lib/pcrm/customers.ex
) will need to have it's inserts/updates/deleted functions updated to usePaperTrail
instead ofRepo
ex: |> PaperTrail.insert()
- The generated live test(s) (ex.
test/pcrm_web/live/customer_live_test.exs
) require updating.- All tests that require authentication need to utilize the
register_and_log_in_user
function to pass.ex: %{conn: conn} = register_and_log_in_user(%{conn: conn})
- Create/update/delete functions require updated pattern matching for Paper Trail.
ex: assert {:ok, %{model: %Customer{}} = %{model: customer}}
- All tests that require authentication need to utilize the
- You can now run
mix ecto.migrate
inside the container to migrate the database.