Squash migrations
This commit is contained in:
parent
072ef27480
commit
dfc3fa450d
18 changed files with 82 additions and 205 deletions
|
@ -1,11 +0,0 @@
|
|||
defmodule MatrixServer.Repo.Migrations.AddAccountsTable do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:accounts, primary_key: false) do
|
||||
add :localpart, :string, primary_key: true, null: false
|
||||
add :password_hash, :string, size: 60, null: false
|
||||
timestamps(updated_at: false)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
defmodule MatrixServer.Repo.Migrations.AddDevicesTable do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:devices, primary_key: false) do
|
||||
add :device_id, :string, primary_key: true, null: false
|
||||
add :access_token, :string
|
||||
add :display_name, :string
|
||||
|
||||
add :localpart,
|
||||
references(:accounts, column: :localpart, on_delete: :delete_all, type: :string),
|
||||
primary_key: true,
|
||||
null: false
|
||||
end
|
||||
|
||||
# Compound primary already indexes device_id.
|
||||
create index(:devices, [:localpart])
|
||||
end
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
defmodule MatrixServer.Repo.Migrations.AddAccessTokenIndexToDevices do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create index(:devices, [:access_token], unique: true)
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
defmodule MatrixServer.Repo.Migrations.AddEventsAndRoomsTable do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:rooms, primary_key: false) do
|
||||
add :id, :string, primary_key: true, null: false
|
||||
add :visibility, :string, null: false, default: "public"
|
||||
end
|
||||
|
||||
create table(:events, primary_key: false) do
|
||||
add :id, :string, primary_key: true, null: false
|
||||
add :type, :string, null: false
|
||||
add :timestamp, :naive_datetime, null: false
|
||||
add :state_key, :string
|
||||
add :sender, :string, null: false
|
||||
add :content, :string
|
||||
add :prev_events, {:array, :string}, null: false
|
||||
add :auth_events, {:array, :string}, null: false
|
||||
add :room_id, references(:rooms, type: :string), null: false
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,10 +0,0 @@
|
|||
defmodule MatrixServer.Repo.Migrations.ChangeEventContentToJson do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
execute(
|
||||
"alter table events alter column content type jsonb using (content::jsonb);",
|
||||
"alter table events alter column content type character varying(255);"
|
||||
)
|
||||
end
|
||||
end
|
|
@ -1,10 +0,0 @@
|
|||
defmodule MatrixServer.Repo.Migrations.ChangeEventTimestampToInteger do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:events) do
|
||||
remove :timestamp, :string, null: false
|
||||
add :origin_server_ts, :integer, null: false
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
defmodule MatrixServer.Repo.Migrations.ChangeEventIdName do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
rename table(:events), :id, to: :event_id
|
||||
end
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
defmodule MatrixServer.Repo.Migrations.AddForwardExtremitiesToRooms do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:rooms) do
|
||||
add :forward_extremities, {:array, :string}, default: [], null: false
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
defmodule MatrixServer.Repo.Migrations.AddStateToRoom do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:rooms) do
|
||||
add :state, :map, default: %{}, null: false
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,10 +0,0 @@
|
|||
defmodule MatrixServer.Repo.Migrations.ChangeRoomStateToArray do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:rooms) do
|
||||
remove :state, :map, default: %{}, null: false
|
||||
add :state, {:array, {:array, :string}}, default: [], null: false
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,12 +0,0 @@
|
|||
defmodule MatrixServer.Repo.Migrations.CreateAliasesTable do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
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])
|
||||
end
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
defmodule MatrixServer.Repo.Migrations.CreateSigningKeyAndServerKeyInfoTable do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:server_key_info, primary_key: false) do
|
||||
add :server_name, :string, primary_key: true, null: false
|
||||
add :valid_until, :bigint, default: 0, 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
|
||||
end
|
||||
end
|
|
@ -1,15 +0,0 @@
|
|||
defmodule MatrixServer.Repo.Migrations.ChangeTimestampsToDatetime do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:events) do
|
||||
remove :origin_server_ts, :integer, null: false
|
||||
add :origin_server_ts, :utc_datetime_usec, null: false
|
||||
end
|
||||
|
||||
alter table(:server_key_info) do
|
||||
remove :valid_until, :bigint, default: 0, null: false
|
||||
add :valid_until, :utc_datetime_usec, null: false
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,11 +0,0 @@
|
|||
defmodule MatrixServer.Repo.Migrations.AddFieldsToEvents do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:events) do
|
||||
add :unsigned, :map, default: %{}, null: true
|
||||
add :hashes, :map, null: false
|
||||
add :signatures, :map, null: false
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,15 +0,0 @@
|
|||
defmodule MatrixServer.Repo.Migrations.MoveTimestampsToIntsAgain do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:events) do
|
||||
remove :origin_server_ts, :utc_datetime_usec, null: false
|
||||
add :origin_server_ts, :bigint, null: false
|
||||
end
|
||||
|
||||
alter table(:server_key_info) do
|
||||
remove :valid_until, :utc_datetime_usec, null: false
|
||||
add :valid_until, :bigint, default: 0, null: false
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
defmodule MatrixServer.Repo.Migrations.CreateJoinedRoomsTable do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:joined_rooms, primary_key: false) do
|
||||
add :localpart,
|
||||
references(:accounts, column: :localpart, type: :string),
|
||||
primary_key: true,
|
||||
null: false
|
||||
|
||||
add :room_id, references(:rooms, type: :string),
|
||||
primary_key: true,
|
||||
null: false
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,81 @@
|
|||
defmodule MatrixServer.Repo.Migrations.CreateInitialTables do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:accounts, primary_key: false) do
|
||||
add :localpart, :string, primary_key: true, null: false
|
||||
add :password_hash, :string, size: 60, null: false
|
||||
timestamps(updated_at: false)
|
||||
end
|
||||
|
||||
create table(:rooms, primary_key: false) do
|
||||
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
|
||||
|
||||
create table(:joined_rooms, primary_key: false) do
|
||||
add :localpart,
|
||||
references(:accounts, column: :localpart, type: :string),
|
||||
primary_key: true,
|
||||
null: false
|
||||
|
||||
add :room_id, references(:rooms, type: :string),
|
||||
primary_key: true,
|
||||
null: false
|
||||
end
|
||||
|
||||
create table(:events, primary_key: false) do
|
||||
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 :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
|
||||
|
||||
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])
|
||||
|
||||
create table(:devices, primary_key: false) do
|
||||
add :device_id, :string, primary_key: true, null: false
|
||||
add :access_token, :string
|
||||
add :display_name, :string
|
||||
|
||||
add :localpart,
|
||||
references(:accounts, column: :localpart, on_delete: :delete_all, type: :string),
|
||||
primary_key: true,
|
||||
null: false
|
||||
end
|
||||
|
||||
# Compound primary already indexes device_id.
|
||||
create index(:devices, [:localpart])
|
||||
|
||||
create index(:devices, [:access_token], unique: true)
|
||||
end
|
||||
end
|
|
@ -1,6 +1,4 @@
|
|||
alias MatrixServer.{Repo, Room, Event, Account, Device}
|
||||
|
||||
timestamp = fn n -> DateTime.from_unix!(n, :microsecond) end
|
||||
alias MatrixServer.{Repo, Account, Device}
|
||||
|
||||
Repo.insert!(%Account{
|
||||
localpart: "chuck",
|
||||
|
|
Loading…
Reference in a new issue