mirror of
https://github.com/plausible/analytics.git
synced 2024-12-02 07:38:47 +03:00
29 lines
531 B
Elixir
29 lines
531 B
Elixir
|
defmodule :"Elixir.Plausible.Repo.Migrations.Associate-goals-with-sites" do
|
||
|
use Ecto.Migration
|
||
|
|
||
|
def up do
|
||
|
alter table(:goals) do
|
||
|
add :site_id, :integer, null: true
|
||
|
end
|
||
|
|
||
|
execute """
|
||
|
DELETE FROM goals g WHERE NOT EXISTS (
|
||
|
SELECT 1 FROM sites s
|
||
|
WHERE s.domain = g.domain
|
||
|
)
|
||
|
"""
|
||
|
|
||
|
execute """
|
||
|
UPDATE goals g SET site_id = (
|
||
|
SELECT s.id FROM sites s WHERE s.domain = g.domain
|
||
|
)
|
||
|
"""
|
||
|
end
|
||
|
|
||
|
def down do
|
||
|
alter table(:goals) do
|
||
|
remove :site_id
|
||
|
end
|
||
|
end
|
||
|
end
|