Fix dry run mode in DataMigration.SiteImports (#3965)

This commit is contained in:
Adrian Gruntkowski 2024-04-02 14:05:34 +02:00 committed by GitHub
parent 23a3699dd7
commit 9f27fa303c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -141,7 +141,9 @@ defmodule Plausible.DataMigration.SiteImports do
defp insert!(changeset, true = _dry_run?) do
if changeset.valid? do
Ecto.Changeset.apply_changes(changeset)
changeset
|> Ecto.Changeset.change(id: 0)
|> Ecto.Changeset.apply_changes()
else
raise "Invalid insert: #{inspect(changeset)}"
end

View File

@ -50,6 +50,24 @@ defmodule Plausible.DataMigration.SiteImportsTest do
assert site_import.source == :universal_analytics
end
test "runs in dry mode without making any persistent changes" do
site =
insert(:site)
|> Site.start_import(~D[2021-01-02], ~D[2021-01-08], "Google Analytics", "ok")
|> Repo.update!()
populate_stats(site, 0, [
build(:imported_visitors, date: ~D[2021-01-07])
])
assert capture_io(fn ->
assert :ok = SiteImports.run()
end) =~ "Processing 1 sites"
assert [%{id: id, legacy: true}] = Imported.list_all_imports(site)
assert id == 0
end
test "does not set end date to latter than the current one" do
site =
insert(:site)