View Source Plausible.DataMigration.LocationsSync (Plausible v0.0.1)

ClickHouse locations data migration for storing location names in ClickHouse.

Only run when Location.version() changes: either as a migration or in cron.

The migration:

  1. Truncates existing location_data table (if exists)
  2. Creates new table (if needed)
  3. Inserts new data from Location module
  4. (Re-)Creates dictionary to read location data from table
  5. Creates ALIAS columns in events_v2, sessions_v2 and imported_locations table to make reading location names easy
  6. Updates table comment for location_data to indicate last version synced.

Note that the dictionary is large enough to cache the whole dataset in memory, making lookups fast.

This migration is intended to be idempotent and rerunnable - if run multiple times, it should always set things to the same result as if run once.

SQL files available at: priv/data_migrations/LocationsSync/sql

Summary

Functions

Link to this function

confirm(message, func, default_choice \\ :yes)

View Source
Link to this function

do_run(name, query, options \\ [])

View Source
Link to this function

run_sql(name, assigns \\ [], options \\ [])

View Source

Runs a single SQL query in a file.

Valid options:

  • quiet - reduces output from running the SQL
  • params - List of query parameters.
  • query_options - passed to Repo.query
Link to this function

run_sql_confirm(name, assigns \\ [], options \\ [])

View Source
Link to this function

run_sql_multi(name, assigns \\ [], options \\ [])

View Source

Runs multiple SQL queries from a single file.

Note that each query must be separated by semicolons.

Link to this function

unwrap(name, assigns \\ [])

View Source