Squash migrations
This commit is contained in:
parent
072ef27480
commit
dfc3fa450d
18 changed files with 82 additions and 205 deletions
priv/repo
migrations
20210622142112_add_accounts_table.exs20210623145023_add_devices_table.exs20210625205812_add_access_token_index_to_devices.exs20210707123852_add_events_and_rooms_table.exs20210714150725_change_event_content_to_json.exs20210715093944_change_event_timestamp_to_integer.exs20210716212330_change_event_id_name.exs20210725121639_add_forward_extremities_to_rooms.exs20210725151601_add_state_to_room.exs20210729143750_change_room_state_to_array.exs20210730122017_create_aliases_table.exs20210812105932_create_signing_key_and_server_key_info_table.exs20210816144214_change_timestamps_to_datetime.exs20210818133912_add_fields_to_events.exs20210820184601_move_timestamps_to_ints_again.exs20210823083642_create_joined_rooms_table.exs20210830160818_create_initial_tables.exs
seeds.exs
|
@ -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…
Add table
Add a link
Reference in a new issue