Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Schema changes #221

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/dbservice/batches/batch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ defmodule Dbservice.Batches.Batch do
field :parent_id, :integer
field :start_date, :date
field :end_date, :date
field :af_medium, :string

belongs_to :program, Program
belongs_to :auth_group, AuthGroup
Expand All @@ -42,7 +43,8 @@ defmodule Dbservice.Batches.Batch do
:start_date,
:end_date,
:program_id,
:auth_group_id
:auth_group_id,
:af_medium
])
|> validate_required([:name])
end
Expand Down
2 changes: 2 additions & 0 deletions lib/dbservice/grades/grade.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ defmodule Dbservice.Grades.Grade do
alias Dbservice.Tags.Tag
alias Dbservice.Chapters.Chapter
alias Dbservice.Topics.Topic
alias Dbservice.Users.Student

schema "grade" do
field(:number, :integer)

timestamps()

has_many(:chapter, Chapter)
has_many(:student, Student)
has_many(:topic, Topic)
belongs_to(:tag, Tag)
end
Expand Down
6 changes: 5 additions & 1 deletion lib/dbservice/programs/program.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ defmodule Dbservice.Programs.Program do
field :target_outreach, :integer
field :donor, :string
field :state, :string
field :model, :string
field :is_current, :boolean, default: true

belongs_to :product, Product
has_many :group, Group, foreign_key: :child_id, where: [type: "program"]
Expand All @@ -32,7 +34,9 @@ defmodule Dbservice.Programs.Program do
:target_outreach,
:donor,
:state,
:product_id
:product_id,
:model,
:is_current
])
|> validate_required([:name])
end
Expand Down
2 changes: 0 additions & 2 deletions lib/dbservice/schools/school.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ defmodule Dbservice.Schools.School do
field :block_code, :string
field :block_name, :string
field :board, :string
field :board_medium, :string

has_many :group, Group, foreign_key: :child_id, where: [type: "school"]

Expand Down Expand Up @@ -52,7 +51,6 @@ defmodule Dbservice.Schools.School do
:block_code,
:block_name,
:board,
:board_medium,
:user_id
])
|> validate_required([:code, :name])
Expand Down
5 changes: 4 additions & 1 deletion lib/dbservice/users/student.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Dbservice.Users.Student do
alias Dbservice.Users.User
alias Dbservice.Profiles.StudentProfile
alias Dbservice.Exams.StudentExamRecord
alias Dbservice.Grades.Grade

schema "student" do
field(:student_id, :string)
Expand Down Expand Up @@ -50,6 +51,7 @@ defmodule Dbservice.Users.Student do
field(:planned_competitive_exams, {:array, :integer})
field(:status, :string)
field(:board_stream, :string)
field(:school_medium, :string)

belongs_to(:user, User)
has_one(:student_profile, StudentProfile)
Expand Down Expand Up @@ -103,7 +105,8 @@ defmodule Dbservice.Users.Student do
:photo,
:planned_competitive_exams,
:status,
:board_stream
:board_stream,
:school_medium
])
|> validate_required([:user_id])
end
Expand Down
4 changes: 3 additions & 1 deletion lib/dbservice_web/swagger_schemas/batch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ defmodule DbserviceWeb.SwaggerSchema.Batch do
contact_hours_per_week(:integer, "Contact hours per week of a batch")
batch_id(:string, "The id of a batch")
parent_id(:string, "The id of a parent batch")
af_medium(:stream, "AF medium")
end

example(%{
name: "Delhi-12-NEET",
contact_hours_per_week: 48,
batch_id: "DelhiStudents_11_Photon_Eng_23_001",
parent_id: 1
parent_id: 1,
af_medium: "medical"
})
end
}
Expand Down
4 changes: 3 additions & 1 deletion lib/dbservice_web/swagger_schemas/program.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ defmodule DbserviceWeb.SwaggerSchema.Program do
donor(:string, "Donor of a program")
model(:string, "Program Model")
group_id(:integer, "ID of the group")
is_current(:boolean, "Program is currently active/inactive")
end

example(%{
Expand All @@ -34,7 +35,8 @@ defmodule DbserviceWeb.SwaggerSchema.Program do
donor: "Infosys, MSDF, Sofina",
state: "Delhi",
model: "Live Classes",
group_id: 1
group_id: 1,
is_current: true
})
end
}
Expand Down
2 changes: 0 additions & 2 deletions lib/dbservice_web/swagger_schemas/school.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ defmodule DbserviceWeb.SwaggerSchema.School do
block_code(:string, "Block Code")
block_name(:string, "Block Name")
board(:string, "Board")
board_medium(:string, "Medium")
user_id(:integer, "User ID of a school")
end

Expand All @@ -41,7 +40,6 @@ defmodule DbserviceWeb.SwaggerSchema.School do
district: "NORTH WEST DELHI",
block_code: "DOEAIDED",
board: "CBSE",
board_medium: "en",
user_id: 1
})
end
Expand Down
5 changes: 4 additions & 1 deletion lib/dbservice_web/swagger_schemas/student.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ defmodule DbserviceWeb.SwaggerSchema.Student do
:string,
"Stream or subjects chosen for the board (e.g., PCB, PCM, Commerce, Arts)"
)

school_medium(:school_medium, "Medium of student's school")
end

example(%{
Expand All @@ -54,7 +56,8 @@ defmodule DbserviceWeb.SwaggerSchema.Student do
has_internet_access: "Yes",
primary_smartphone_owner: "Father",
primary_smartphone_owner_profession: "Employed",
board_stream: "PCM"
board_stream: "PCM",
school_medium: "Hindi"
})
end
}
Expand Down
3 changes: 2 additions & 1 deletion lib/dbservice_web/views/batch_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ defmodule DbserviceWeb.BatchView do
start_date: batch.start_date,
end_date: batch.end_date,
program_id: batch.program_id,
auth_group_id: batch.auth_group_id
auth_group_id: batch.auth_group_id,
af_medium: batch.af_medium
}
end
end
4 changes: 3 additions & 1 deletion lib/dbservice_web/views/program_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ defmodule DbserviceWeb.ProgramView do
target_outreach: program.target_outreach,
donor: program.donor,
state: program.state,
product_id: program.product_id
product_id: program.product_id,
model: program.model,
is_current: program.is_current
}
end
end
1 change: 0 additions & 1 deletion lib/dbservice_web/views/school_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ defmodule DbserviceWeb.SchoolView do
block_code: school.block_code,
block_name: school.block_name,
board: school.board,
board_medium: school.board_medium,
user_id: school.user_id,
user: render_one(school.user, UserView, "user.json")
}
Expand Down
3 changes: 2 additions & 1 deletion lib/dbservice_web/views/student_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ defmodule DbserviceWeb.StudentView do
photo: student.photo,
user: render_one(student.user, UserView, "user.json"),
status: student.status,
board_stream: student.board_stream
board_stream: student.board_stream,
school_medium: student.school_medium
}
end

Expand Down
22 changes: 22 additions & 0 deletions priv/repo/migrations/20240930142432_update_tables_and_columns.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defmodule Dbservice.Repo.Migrations.UpdateTablesAndColumns do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migration doesn't affect any current analysis/data flows?

use Ecto.Migration

def change do
alter table(:school) do
remove :board_medium
end

alter table(:student) do
add :school_medium, :string
end

alter table(:batch) do
add :af_medium, :string
end

alter table(:program) do
add :model, :string
add :is_current, :boolean, default: true
end
end
end
Loading