Skip to content

Commit

Permalink
create apps before apikeys for #97
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Sep 2, 2020
1 parent 45b7dbe commit ecc6043
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
9 changes: 5 additions & 4 deletions lib/auth/apikey.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ defmodule Auth.Apikey do
schema "apikeys" do
field :client_secret, :binary
field :client_id, :binary
field :description, :string
field :name, :string
field :url, :binary
# field :description, :string
# field :name, :string
# field :url, :binary
field :person_id, :id
field :status, :id
belongs_to :app, Auth.App

timestamps()
end

@doc false
def changeset(apikey, attrs) do
apikey
|> cast(attrs, [:client_id, :client_secret, :name, :description, :url, :person_id])
|> cast(attrs, [:client_id, :client_secret, :person_id])
|> validate_required([:client_secret])
end

Expand Down
3 changes: 2 additions & 1 deletion lib/auth/app.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ defmodule Auth.App do
field :url, :binary
field :person_id, :id
field :status, :id
field :apikey_id, :id
# field :apikey_id, :id
# has_many :apikeys, Auth.Status

timestamps()
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ defmodule Auth.Repo.Migrations.CreateApps do
add :end, :naive_datetime
add :person_id, references(:people, on_delete: :nothing)
add :status, references(:status, on_delete: :nothing)
add :apikey_id, references(:apikeys, on_delete: :nothing)
# add :apikey_id, references(:apikeys, on_delete: :nothing)

timestamps()
end

create index(:apps, [:person_id])
create index(:apps, [:status])
create index(:apps, [:apikey_id])
# create index(:apps, [:apikey_id])
end
end
7 changes: 4 additions & 3 deletions priv/repo/migrations/20200424141938_create_apikeys.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ defmodule Auth.Repo.Migrations.CreateApikeys do
create table(:apikeys) do
add :client_id, :binary
add :client_secret, :binary
add :name, :string
add :description, :text
add :url, :binary
# add :name, :string
# add :description, :text
# add :url, :binary
add :app_id, references(:apps, on_delete: :nothing)
add :person_id, references(:people, on_delete: :nothing)
add :status, references(:status, on_delete: :nothing)

Expand Down

0 comments on commit ecc6043

Please sign in to comment.