Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Krrupa committed Mar 26, 2024
2 parents 8392b63 + 5bb1680 commit 82412e2
Show file tree
Hide file tree
Showing 77 changed files with 1,241 additions and 1,033 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/staging_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
USER_NAME: ${{ secrets.USER_NAME }}

run: |
branch_name="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} "
cd /var/www/html/db-service/config
Expand All @@ -42,7 +41,7 @@ jobs:
if [ -f /var/www/html/db-service/priv/static/swagger.json ]; then
sudo rm /var/www/html/db-service/priv/static/swagger.json
fi
sudo git pull origin \"$branch_name\" &&
sudo git pull origin main &&
sudo MIX_ENV=prod mix deps.get &&
sudo MIX_ENV=prod mix deps.compile &&
sudo MIX_ENV=prod mix ecto.migrate &&
Expand Down
31 changes: 31 additions & 0 deletions docs/INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ Install the following packages using your favorite package manager. Links are pr

- [Install Postgres](https://www.postgresql.org/download/)
- Run the following steps to install Postgres on a Mac device

```
brew install postgresql
brew services start postgresql
```

- Once installed, verify the installations using `postgres --version`. You should be able to see:

```
postgres (PostgreSQL) 14.9 (Homebrew)
```

- For Postgres, this app defaults to `postgres` as both the username and password. This can be edited in `config/dev.exs` file.
- Create a new database for the application called `dbservice_dev`. You can do this by running the command: `createdb dbservice_dev`
- You can also use interactive postgres terminal `psql`. To open database, use: `psql -d dbservice_dev`
Expand All @@ -40,6 +44,13 @@ Install the following packages using your favorite package manager. Links are pr
CREATE EXTENSION "uuid-ossp";
```

### Recommended Versions

For development, we recommend using the following versions:

- Elixir: 1.14.2
- Erlang/OTP: 25

## Installation steps

Follow the steps below to set up the repo for development
Expand All @@ -58,15 +69,35 @@ Follow the steps below to set up the repo for development
3. Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
4. You can see Swagger docs at `http://localhost:4000/docs/swagger/index.html`.
5. Please verify that `localhost` is part of whitelisted domains. If not, you can create a file `db-service/config/.env` and add the following lines to it:

```
WHITELISTED_DOMAINS="localhost"
```

### Adding data to local database

You can add data to local database by running `sh ./fetch-data.sh`. This will fetch data from production/staging database and sync with your local database. Please ask repository owners for the following credentials:

```production_db_host="xxx.rds.amazonaws.com"
production_db_name="xxx"
production_db_user="postgres"
production_db_password="xxx"
```

## Editor Support

For enhanced development experience with Elixir, consider installing [`ElixirLS: Elixir support and debugger`](https://marketplace.visualstudio.com/items?itemName=JakeBecker.elixir-ls) from the Visual Studio Marketplace.

### ElixirLS support matrix

| OTP Versions | Elixir Versions | Supports ElixirLS |
| :-------------: | :-------------: | :---------------: |
| any | <= 1.12 | No |
| 22 | 1.12 | Yes |
| 23 | 1.12 - 1.14 | Yes |
| 24 | 1.12 - 1.16 | Yes |
| 25 | 1.13.4 - 1.16 | Yes |
| 26.0.0 - 26.0.1 | any | No |
| 26.0.2 - 26.1.2 | 1.14.5 - 1.16 | *nix only |
| >= 26.2.0 | 1.14.5 - 1.16 | Yes |
| any | 1.15.5 | Yes |
100 changes: 100 additions & 0 deletions lib/dbservice/auth_groups.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
defmodule Dbservice.AuthGroups do
@moduledoc """
The AuthGroup context.
"""

import Ecto.Query, warn: false
alias Dbservice.Repo

alias Dbservice.Groups.AuthGroup
alias Dbservice.Groups.Group

@doc """
Returns the list of auth groups.
## Examples
iex> list_auth_group()
[%AuthGroup{}, ...]
"""
def list_auth_group do
Repo.all(AuthGroup)
end

@doc """
Gets a single auth-group.
Raises `Ecto.NoResultsError` if the AuthGroup does not exist.
## Examples
iex> get_auth_group!(123)
%AuthGroup{}
iex> get_auth_group!(456)
** (Ecto.NoResultsError)
"""
def get_auth_group!(id) do
Repo.get!(AuthGroup, id) |> Repo.preload(:group)
end

@doc """
Gets an auth group by name.
Raises `Ecto.NoResultsError` if the AuthGroup does not exist.
## Examples
iex> get_auth_group_by_name(DelhiStudents)
%AuthGroup{}
iex> get_auth_group_by_name(abc)
** (Ecto.NoResultsError)
"""
def get_auth_group_by_name(name) do
Repo.get_by(AuthGroup, name: name)
end

@doc """
Creates an auth group.
## Examples
iex> create_auth_group(%{field: value})
{:ok, %AuthGroup{}}
iex> create_auth_group(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_auth_group(attrs \\ %{}) do
%AuthGroup{}
|> AuthGroup.changeset(attrs)
|> Ecto.Changeset.put_assoc(:group, [
%Group{type: "auth_group", child_id: attrs["id"]}
])
|> Repo.insert()
end

@doc """
Updates an auth group.
## Examples
iex> update_auth_group(auth_group, %{field: new_value})
{:ok, %AuthGroup{}}
iex> update_auth_group(auth_group, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_auth_group(%AuthGroup{} = auth_group, attrs) do
auth_group
|> AuthGroup.changeset(attrs)
|> Repo.update()
end

@doc """
Deletes an auth group.
## Examples
iex> delete_auth_group(auth_group)
{:ok, %AuthGroup{}}
iex> delete_auth_group(auth_group)
{:error, %Ecto.Changeset{}}
"""
def delete_auth_group(%AuthGroup{} = auth_group) do
Repo.delete(auth_group)
end

@doc """
Returns an `%Ecto.Changeset{}` for tracking auth_group changes.
## Examples
iex> change_auth_group(auth_group)
%Ecto.Changeset{data: %AuthGroup{}}
"""
def change_auth_group(%AuthGroup{} = auth_group, attrs \\ %{}) do
AuthGroup.changeset(auth_group, attrs)
end
end
82 changes: 0 additions & 82 deletions lib/dbservice/batch_programs.ex

This file was deleted.

4 changes: 2 additions & 2 deletions lib/dbservice/batches.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Dbservice.Batches do
alias Dbservice.Repo

alias Dbservice.Batches.Batch
alias Dbservice.Groups.GroupType
alias Dbservice.Groups.Group

@doc """
Returns the list of batch.
Expand Down Expand Up @@ -54,7 +54,7 @@ defmodule Dbservice.Batches do
def create_batch(attrs \\ %{}) do
%Batch{}
|> Batch.changeset(attrs)
|> Ecto.Changeset.put_assoc(:group_type, [%GroupType{type: "batch", child_id: attrs["id"]}])
|> Ecto.Changeset.put_assoc(:group, [%Group{type: "batch", child_id: attrs["id"]}])
|> Repo.insert()
end

Expand Down
20 changes: 14 additions & 6 deletions lib/dbservice/batches/batch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@ defmodule Dbservice.Batches.Batch do
import Ecto.Changeset

alias Dbservice.Programs.Program
alias Dbservice.Groups.GroupType
alias Dbservice.Groups.Group
alias Dbservice.EnrollmentRecords.EnrollmentRecord
alias Dbservice.Sessions.SessionSchedule
alias Dbservice.Groups.AuthGroup

schema "batch" do
field :name, :string
field :contact_hours_per_week, :integer
field :batch_id, :string
field :parent_id, :integer
field :start_date, :date
field :end_date, :date

has_many :group_type, GroupType, foreign_key: :child_id, where: [type: "batch"]
belongs_to :program, Program
belongs_to :auth_group, AuthGroup
has_many :group, Group, foreign_key: :child_id, where: [type: "batch"]

has_many :enrollment_record, EnrollmentRecord,
foreign_key: :grouping_id,
where: [grouping_type: "batch"]
foreign_key: :group_id,
where: [group_type: "batch"]

many_to_many :program, Program, join_through: "batch_program", on_replace: :delete
has_one :session_schedule, SessionSchedule

timestamps()
Expand All @@ -34,7 +38,11 @@ defmodule Dbservice.Batches.Batch do
:name,
:contact_hours_per_week,
:batch_id,
:parent_id
:parent_id,
:start_date,
:end_date,
:program_id,
:auth_group_id
])
|> validate_required([:name])
end
Expand Down
25 changes: 0 additions & 25 deletions lib/dbservice/batches/batch_program.ex

This file was deleted.

Loading

0 comments on commit 82412e2

Please sign in to comment.