chore: add migrations to git

This commit is contained in:
2026-05-12 16:00:46 +02:00
parent 68136d1602
commit 25f411a3df
9 changed files with 109 additions and 1 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ defmodule Localiser.Migrator do
end
def init(_args) do
path = Application.app_dir(:localiserd, "priv/repo/migrations")
path = Application.app_dir(:localiserd, "migrations")
Ecto.Migrator.run(Localiser.Repo, path, :up, all: true)
{:ok, %{}}
end
@@ -0,0 +1,11 @@
defmodule Localiser.Repo.Migrations.CreateFloors do
use Ecto.Migration
def change do
create table(:floors) do
add :name, :string, null: false
timestamps(type: :utc_datetime)
end
end
end
@@ -0,0 +1,18 @@
defmodule Localiser.Repo.Migrations.CreateRooms do
use Ecto.Migration
def change do
create table(:rooms) do
add :name, :string, null: false
add :floor_id, references(:floors, on_delete: :delete_all), null: false
add :width, :float
add :height, :float
add :offset_x, :float
add :offset_y, :float
timestamps(type: :utc_datetime)
end
create index(:rooms, [:floor_id])
end
end
@@ -0,0 +1,17 @@
defmodule Localiser.Repo.Migrations.CreateSensors do
use Ecto.Migration
def change do
create table(:sensors) do
add :sensor_id, :string, null: false
add :room_id, references(:rooms, on_delete: :nilify_all)
add :x, :float
add :y, :float
timestamps(type: :utc_datetime)
end
create unique_index(:sensors, [:sensor_id])
create index(:sensors, [:room_id])
end
end
@@ -0,0 +1,15 @@
defmodule Localiser.Repo.Migrations.CreateSensorCalibrations do
use Ecto.Migration
def change do
create table(:sensor_calibrations) do
add :sensor_id, references(:sensors, on_delete: :delete_all), null: false
add :rssi_ref, :integer, null: false
add :path_loss_exp, :float, null: false
add :calibrated_at, :utc_datetime, null: false
add :inserted_at, :utc_datetime, null: false
end
create index(:sensor_calibrations, [:sensor_id])
end
end
+16
View File
@@ -0,0 +1,16 @@
defmodule Localiser.Repo.Migrations.CreateTags do
use Ecto.Migration
def change do
create table(:tags) do
add :tag_id, :string, null: false
add :name, :string
add :color, :string
add :metadata, :text
timestamps(type: :utc_datetime)
end
create unique_index(:tags, [:tag_id])
end
end
@@ -0,0 +1,14 @@
defmodule Localiser.Repo.Migrations.CreateUsers do
use Ecto.Migration
def change do
create table(:users) do
add :username, :string, null: false
add :password_hash, :string, null: false
timestamps(type: :utc_datetime)
end
create unique_index(:users, [:username])
end
end
@@ -0,0 +1,9 @@
defmodule Localiser.Repo.Migrations.AddIsAdminToUsers do
use Ecto.Migration
def change do
alter table(:users) do
add :is_admin, :boolean, default: false, null: false
end
end
end
@@ -0,0 +1,8 @@
defmodule Localiser.Repo.Migrations.RenameRoomsOffsetColumns do
use Ecto.Migration
def change do
rename table(:rooms), :offset_x, to: :x
rename table(:rooms), :offset_y, to: :y
end
end