defmodule ArcadiaCloud.Repo.Migrations.TenantIdToString do use Ecto.Migration # tenant_id is string-typed everywhere else (cloud_deployments, # tenant_invoices) and arcadia uses non-UUID tenant slugs like # "platform-admin". cloud_resources/cloud_projects were binary_id — # align them so cross-table joins (analytics COALESCE) work and # non-UUID tenant ids don't blow up Ecto casts. def up do execute "ALTER TABLE cloud_resources ALTER COLUMN tenant_id TYPE text USING tenant_id::text" execute "ALTER TABLE cloud_projects ALTER COLUMN tenant_id TYPE text USING tenant_id::text" end def down do execute "ALTER TABLE cloud_resources ALTER COLUMN tenant_id TYPE uuid USING tenant_id::uuid" execute "ALTER TABLE cloud_projects ALTER COLUMN tenant_id TYPE uuid USING tenant_id::uuid" end end