-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Channels: Migration to add materialized column, backfill code (#4798)
* Channels: Migration to add column, backfill code This change adds `acqusition_channel` columns to events_v2 and sessions_v2 tables. These columns are materialized - we don't ingest into them directly. Instead they're calculated based on other columns. The data migration changes now allow to also backfill the column. Tested the ability to change definitions by changing the function definitions and re-running the migration with backfill. Confirmed that the underlying data changed as expected. * quiet option * Exclude data migrations from validation * Migration consistency
- Loading branch information
Showing
7 changed files
with
103 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...ata_migrations/AcquisitionChannel/sql/acquisition_channel_add_materialized_column.sql.eex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ALTER TABLE <%= @table %> | ||
<%= @on_cluster_statement %> | ||
ADD COLUMN IF NOT EXISTS acquisition_channel LowCardinality(String) | ||
MATERIALIZED acquisition_channel(referrer_source, utm_medium, utm_campaign, utm_source, click_id_param) |
2 changes: 2 additions & 0 deletions
2
...igrations/AcquisitionChannel/sql/acquisition_channel_backfill_materialized_column.sql.eex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE <%= @table %> | ||
MATERIALIZE COLUMN acquisition_channel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
..._migrations/AcquisitionChannel/sql/acquisition_channel_update_materialized_column.sql.eex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ALTER TABLE <%= @table %> | ||
<%= @on_cluster_statement %> | ||
MODIFY COLUMN acquisition_channel LowCardinality(String) | ||
MATERIALIZED acquisition_channel(referrer_source, utm_medium, utm_campaign, utm_source, click_id_param) |
11 changes: 11 additions & 0 deletions
11
priv/ingest_repo/migrations/20241111084056_create_acquisition_channel_column.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
defmodule Plausible.IngestRepo.Migrations.CreateAcquisitionChannelColumn do | ||
use Ecto.Migration | ||
|
||
def up do | ||
Plausible.DataMigration.AcquisitionChannel.run(add_column: true, backfill: false) | ||
end | ||
|
||
def down do | ||
raise "irreversible" | ||
end | ||
end |