mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-06-09 00:49:23 +00:00
21 lines
413 B
Elixir
21 lines
413 B
Elixir
defmodule LiveBeats.Repo.Migrations.AddSongsNumberToUsers do
|
|
use Ecto.Migration
|
|
|
|
def up do
|
|
alter table(:users) do
|
|
add :songs_count, :integer, null: false, default: 0
|
|
end
|
|
|
|
execute("
|
|
UPDATE users set songs_count =
|
|
(SELECT count (*) from songs
|
|
where songs.user_id = users.id)")
|
|
end
|
|
|
|
def down do
|
|
alter table(:users) do
|
|
remove :songs_count
|
|
end
|
|
end
|
|
end
|