Current section
Files
Jump to
Current section
Files
priv/repo/seeds.exs
# Script for populating the database. You can run it as:
#
# mix run priv/repo/seeds.exs
#
# Inside the script, you can read and write to any of your
# repositories directly:
#
# Repo.insert!(%Oli.SomeSchema{})
#
# We recommend using the bang functions (`insert!`, `update!`
# and so on) as they will fail if something goes wrong.
alias Lti_1p3.DataProviders.EctoProvider
alias Lti_1p3.DataProviders.EctoProvider.Repo
# create a default active lti_1p3 jwk
if !Repo.get_by(EctoProvider.Jwk, id: 1) do
%{private_key: private_key} = Lti_1p3.KeyGenerator.generate_key_pair()
{:ok, _jwk} = EctoProvider.create_jwk(%{
pem: private_key,
typ: "JWT",
alg: "RS256",
kid: UUID.uuid4(),
active: true,
})
end
# create lti_1p3 platform roles
if !Repo.get_by(EctoProvider.PlatformRole, id: 1) do
Lti_1p3.PlatformRoles.list_roles()
|> Enum.map(&Lti_1p3.PlatformRole.changeset/1)
|> Enum.map(fn t -> Repo.insert!(t, on_conflict: :replace_all, conflict_target: :id) end)
end
# create lti_1p3 context roles
if !Repo.get_by(EctoProvider.ContextRole, id: 1) do
Lti_1p3.ContextRoles.list_roles()
|> Enum.map(&Lti_1p3.ContextRole.changeset/1)
|> Enum.map(fn t -> Repo.insert!(t, on_conflict: :replace_all, conflict_target: :id) end)
end