architex/priv/repo/migrations/20210830160818_create_initial_tables.exs

88 lines
3 KiB
Elixir
Raw Normal View History

2021-09-01 12:43:55 +00:00
defmodule Architex.Repo.Migrations.CreateInitialTables do
2021-08-30 16:27:34 +00:00
use Ecto.Migration
def change do
create table(:accounts) do
add :localpart, :string, null: false
2021-08-30 16:27:34 +00:00
add :password_hash, :string, size: 60, null: false
timestamps(updated_at: false)
end
create index(:accounts, [:localpart], unique: true)
2021-08-30 16:27:34 +00:00
create table(:rooms, primary_key: false) do
2021-09-04 14:40:17 +00:00
add :id, :string, primary_key: true, null: false
2021-08-30 16:27:34 +00:00
add :state, {:array, {:array, :string}}, default: [], null: false
add :forward_extremities, {:array, :string}, default: [], null: false
add :visibility, :string, null: false, default: "public"
end
create table(:joined_rooms, primary_key: false) do
add :account_id, references(:accounts), primary_key: true, null: false
2021-08-30 16:27:34 +00:00
add :room_id, references(:rooms, type: :string),
primary_key: true,
null: false
end
create table(:events, primary_key: false) do
2021-09-04 14:40:17 +00:00
add :nid, :serial, primary_key: true
2021-08-30 16:27:34 +00:00
add :origin_server_ts, :bigint, null: false
add :unsigned, :map, default: %{}, null: true
add :hashes, :map, null: false
add :signatures, :map, null: false
2021-09-04 14:40:17 +00:00
add :id, :string, null: false
2021-08-30 16:27:34 +00:00
add :content, :map
add :type, :string, null: false
add :state_key, :string
add :sender, :string, null: false
add :prev_events, {:array, :string}, null: false
add :auth_events, {:array, :string}, null: false
add :room_id, references(:rooms, type: :string), null: false
end
2021-09-04 14:40:17 +00:00
create index(:events, [:id], unique: true)
2021-08-30 16:27:34 +00:00
create table(:server_key_info, primary_key: false) do
add :valid_until, :bigint, default: 0, null: false
add :server_name, :string, primary_key: true, null: false
end
create table(:signing_keys, primary_key: false) do
add :server_name,
references(:server_key_info, column: :server_name, type: :string, on_delete: :delete_all),
null: false
add :signing_key_id, :string, primary_key: true, null: false
add :signing_key, :binary, null: false
end
create table(:aliases, primary_key: false) do
add :alias, :string, primary_key: true, null: false
add :room_id, references(:rooms, type: :string, on_delete: :delete_all), null: false
end
create index(:aliases, [:room_id])
2021-09-04 14:40:17 +00:00
create table(:devices, primary_key: false) do
add :nid, :serial, primary_key: true
add :id, :string, null: false
add :access_token, :string, null: false
2021-08-30 16:27:34 +00:00
add :display_name, :string
add :account_id, references(:accounts, on_delete: :delete_all), null: false
2021-08-30 16:27:34 +00:00
end
2021-09-04 14:40:17 +00:00
create index(:devices, [:id, :account_id], unique: true)
create index(:devices, [:account_id])
2021-08-30 16:27:34 +00:00
create index(:devices, [:access_token], unique: true)
create table(:device_transactions, primary_key: false) do
add :txn_id, :string, primary_key: true, null: false
2021-09-04 14:40:17 +00:00
add :device_nid, references(:devices, column: :nid, on_delete: :delete_all), primary_key: true
add :event_id, :string, null: false
end
2021-08-30 16:27:34 +00:00
end
end