feat: use AprilTag instead of QR code
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
defmodule ComponentsElixir.Repo.Migrations.MigrateQrToApriltag do
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
# Rename qr_code column to qr_code_old for backup
|
||||
rename table(:storage_locations), :qr_code, to: :qr_code_old
|
||||
|
||||
# Add new apriltag_id column as integer
|
||||
alter table(:storage_locations) do
|
||||
add :apriltag_id, :integer
|
||||
end
|
||||
|
||||
# Create unique index for apriltag_id
|
||||
create unique_index(:storage_locations, [:apriltag_id])
|
||||
|
||||
# Add constraint to ensure apriltag_id is in valid range (0-586 for tag36h11)
|
||||
create constraint(:storage_locations, :apriltag_id_range, check: "apriltag_id >= 0 AND apriltag_id <= 586")
|
||||
|
||||
# Note: We keep qr_code_old for now in case we need to rollback
|
||||
# It can be removed in a future migration after confirming everything works
|
||||
end
|
||||
|
||||
def down do
|
||||
# Remove apriltag_id column and constraints
|
||||
drop constraint(:storage_locations, :apriltag_id_range)
|
||||
drop unique_index(:storage_locations, [:apriltag_id])
|
||||
|
||||
alter table(:storage_locations) do
|
||||
remove :apriltag_id
|
||||
end
|
||||
|
||||
# Rename back to qr_code
|
||||
rename table(:storage_locations), :qr_code_old, to: :qr_code
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
defmodule ComponentsElixir.Repo.Migrations.DropQrCodeOldColumn do
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
# Drop the qr_code_old column since we've fully migrated to AprilTags
|
||||
alter table(:storage_locations) do
|
||||
remove :qr_code_old
|
||||
end
|
||||
end
|
||||
|
||||
def down do
|
||||
# If we need to rollback, re-add the qr_code_old column
|
||||
# Note: This will not restore the original data
|
||||
alter table(:storage_locations) do
|
||||
add :qr_code_old, :string, null: false, default: ""
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user