How to contribute

Copy Markdown

Report a bug or a problem

Report in the issue tracker at https://codeberg.org/ArthurClemens/collect/issues

Suggest a code improvement

  • Set up your development environment - see below.
  • Create a branch with your code changes.
  • Make sure to run tests to ensure new code won't break them. When adding code, fix current tests when needed, or add new tests.
  • Run mix qa to perform formatting and checks.
  • Open a new pull request at https://codeberg.org/ArthurClemens/collect/pulls.

Development environment

Setup

Clone this repository, initialize the database and start an iex session.

mix deps.get
mix destroy_dev_repo
mix init_dev_repo
iex -S mix

Add test data

Add data that is also used in the unit tests.

alias Collect.Test.{Database, Factory}
alias Collect.Dev.Repo

Database.init()
Factory.seed_services()

Create a document table.

alias Collect.Dev.Repo

config = %{
  source_table: "services",
  add_identity_column_if_not_exists: true,
  identity_column: "identity",
  language: "english",
  data_fields: [
    %{field_name: "title", value_column: "title"},
    %{field_name: "summary", value_column: "summary"}
  ],
  search_fields: [
    %{field_name: "title", weight: 1},
    %{field_name: "summary"}
  ],
  scopes: [%{where: "active = true"}]
}

Collect.create_document_table("service_documents", config, repo: Repo)

Making changes

When starting an iex session from here, first start the database:

alias Collect.Test.Database

Database.start()

Minimal example:

alias Collect.Test.TestHelpers

TestHelpers.update_row("services", [identity: 3], title: "Fudges")
TestHelpers.update_row("services", [summary: "inactive"], active: true)

Table service_documents_deltas should now have 2 entries.

Merge changes:

Collect.merge_deltas("service_documents", config, repo: Repo)

Both changes should now be visible in table service_documents.

Clean up

Remove the documents and documents_deltas tables, as well as triggers and trigger functions,. Finally, reset the auto-incrementing identity sequence.

Collect.TestHelpers.reset_document_artifacts("service_documents", config, repo: Repo)

Repo.query!("""
  TRUNCATE #{config.source_table}
  RESTART IDENTITY CASCADE
""")