Saved segments/create table (#4797)

* Add migration for Saved Segments

* Remove premature optimisation

* Format

* Refactor to explicit segment type
This commit is contained in:
Artur Pata 2024-11-11 18:31:43 +02:00 committed by GitHub
parent d620432227
commit b22b35793c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,22 @@
defmodule Plausible.Repo.Migrations.CreateSegments do
use Ecto.Migration
def change do
execute(
"CREATE TYPE segment_type AS ENUM ('personal', 'site')",
"DROP TYPE segment_type"
)
create table(:segments) do
add :name, :string, null: false
add :type, :segment_type, null: false, default: "personal"
add :segment_data, :map, null: false
add :site_id, references(:sites, on_delete: :delete_all), null: false
add :owner_id, references(:users, on_delete: :nothing), null: true
timestamps()
end
create index(:segments, [:site_id])
end
end