oneshot
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
defmodule Rsh26pool.Repo.Migrations.CreateVotingTables do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:rooms) do
|
||||
add :room_number, :string, null: false
|
||||
add :name, :string, null: false
|
||||
add :votes_per_user, :integer, null: false, default: 3
|
||||
add :status, :string, null: false, default: "open"
|
||||
add :grouping_mode, :boolean, null: false, default: false
|
||||
add :leader_threshold, :integer, null: false, default: 2
|
||||
add :closes_at, :utc_datetime
|
||||
add :grouped_at, :utc_datetime
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
create unique_index(:rooms, [:room_number])
|
||||
create index(:rooms, [:status])
|
||||
create index(:rooms, [:closes_at])
|
||||
|
||||
create table(:participants) do
|
||||
add :token, :string, null: false
|
||||
add :name, :string, null: false
|
||||
add :role, :string, null: false, default: "member"
|
||||
add :is_leader, :boolean, null: false, default: false
|
||||
add :room_id, references(:rooms, on_delete: :delete_all), null: false
|
||||
add :assigned_leader_id, references(:participants, on_delete: :nilify_all)
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
create unique_index(:participants, [:token])
|
||||
create index(:participants, [:room_id])
|
||||
create index(:participants, [:assigned_leader_id])
|
||||
|
||||
create table(:ideas) do
|
||||
add :text, :string, null: false
|
||||
add :room_id, references(:rooms, on_delete: :delete_all), null: false
|
||||
add :participant_id, references(:participants, on_delete: :delete_all), null: false
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
create index(:ideas, [:room_id])
|
||||
create index(:ideas, [:participant_id])
|
||||
|
||||
create table(:votes) do
|
||||
add :idea_id, references(:ideas, on_delete: :delete_all), null: false
|
||||
add :participant_id, references(:participants, on_delete: :delete_all), null: false
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
create unique_index(:votes, [:idea_id, :participant_id])
|
||||
create index(:votes, [:participant_id])
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user