defmodule PresenceEx.Repo.Migrations.Initial do @moduledoc false use Ecto.Migration alias PresenceEx.Repo alias PresenceEx.Utils def change do for i <- Utils.all_schema_ids() do prefix = "public_#{i}" query = "CREATE SCHEMA #{prefix}" Repo.query(query) create table(:statuses, primary_key: false, prefix: prefix) do add :account, :string, null: false, primary_key: true add :resource, :string, null: false, primary_key: true add :node, :string, null: true add :status, :string, null: false, default: "offline" add :features, :map, default: %{} end create index(:statuses, [:account], prefix: prefix) # Execute the commands on the current prefix # before moving on to the next prefix flush() end end end