Current section

Files

Jump to
boruta priv repo migrations 20210824204150_add_oauth_prefix.exs
Raw

priv/repo/migrations/20210824204150_add_oauth_prefix.exs

defmodule Boruta.Repo.Migrations.AddOauthPrefix do
use Ecto.Migration
def change do
drop(unique_index(:clients, [:id, :secret]))
drop(index(:tokens, [:value]))
drop(unique_index(:tokens, [:client_id, :value]))
drop(unique_index(:tokens, [:client_id, :refresh_token]))
drop(unique_index(:scopes, [:name]))
rename(table(:tokens), to: table(:oauth_tokens))
rename(table(:clients), to: table(:oauth_clients))
rename(table(:scopes), to: table(:oauth_scopes))
rename(table(:clients_scopes), to: table(:oauth_clients_scopes))
alter table(:oauth_clients_scopes) do
modify(:client_id, references(:oauth_clients, type: :uuid, on_delete: :delete_all))
modify(:scope_id, references(:oauth_scopes, type: :uuid, on_delete: :delete_all))
end
alter table(:oauth_tokens) do
modify(:client_id, references(:oauth_clients, type: :uuid, on_delete: :nilify_all))
end
create(unique_index(:oauth_clients, [:id, :secret]))
create(index(:oauth_tokens, [:value]))
create(unique_index(:oauth_tokens, [:client_id, :value]))
create(unique_index(:oauth_tokens, [:client_id, :refresh_token]))
create(unique_index(:oauth_scopes, [:name]))
end
end