Improve primary keys usage
This commit is contained in:
parent
232df26b85
commit
40f3eeff7c
16 changed files with 66 additions and 48 deletions
|
@ -11,9 +11,9 @@ defmodule Architex.Repo.Migrations.CreateInitialTables do
|
|||
create index(:accounts, [:localpart], unique: true)
|
||||
|
||||
create table(:rooms, primary_key: false) do
|
||||
add :id, :string, primary_key: true, null: false
|
||||
add :state, {:array, {:array, :string}}, default: [], null: false
|
||||
add :forward_extremities, {:array, :string}, default: [], null: false
|
||||
add :id, :string, primary_key: true, null: false
|
||||
add :visibility, :string, null: false, default: "public"
|
||||
end
|
||||
|
||||
|
@ -26,11 +26,13 @@ defmodule Architex.Repo.Migrations.CreateInitialTables do
|
|||
end
|
||||
|
||||
create table(:events, primary_key: false) do
|
||||
add :nid, :serial, primary_key: true
|
||||
|
||||
add :origin_server_ts, :bigint, null: false
|
||||
add :unsigned, :map, default: %{}, null: true
|
||||
add :hashes, :map, null: false
|
||||
add :signatures, :map, null: false
|
||||
add :event_id, :string, null: false
|
||||
add :id, :string, null: false
|
||||
add :content, :map
|
||||
add :type, :string, null: false
|
||||
add :state_key, :string
|
||||
|
@ -40,6 +42,8 @@ defmodule Architex.Repo.Migrations.CreateInitialTables do
|
|||
add :room_id, references(:rooms, type: :string), null: false
|
||||
end
|
||||
|
||||
create index(:events, [:id], unique: true)
|
||||
|
||||
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
|
||||
|
@ -61,21 +65,22 @@ defmodule Architex.Repo.Migrations.CreateInitialTables do
|
|||
|
||||
create index(:aliases, [:room_id])
|
||||
|
||||
create table(:devices) do
|
||||
add :device_id, :string, null: false
|
||||
create table(:devices, primary_key: false) do
|
||||
add :nid, :serial, primary_key: true
|
||||
add :id, :string, null: false
|
||||
add :access_token, :string, null: false
|
||||
add :display_name, :string
|
||||
|
||||
add :account_id, references(:accounts, on_delete: :delete_all), null: false
|
||||
end
|
||||
|
||||
create index(:devices, [:device_id, :account_id], unique: true)
|
||||
create index(:devices, [:id, :account_id], unique: true)
|
||||
create index(:devices, [:account_id])
|
||||
create index(:devices, [:access_token], unique: true)
|
||||
|
||||
create table(:device_transactions, primary_key: false) do
|
||||
add :txn_id, :string, primary_key: true, null: false
|
||||
add :device_id, references(:devices, on_delete: :delete_all), primary_key: true, null: false
|
||||
add :device_nid, references(:devices, column: :nid, on_delete: :delete_all), primary_key: true
|
||||
add :event_id, :string, null: false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ account =
|
|||
|
||||
account
|
||||
|> Ecto.build_assoc(:devices,
|
||||
device_id: "android",
|
||||
id: "android",
|
||||
display_name: "My Android",
|
||||
access_token: "sneed"
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue