From f9b6d34fb3a4d01435a98ad4ed93d0bccd86cdc3 Mon Sep 17 00:00:00 2001 From: Francesco Noacco Date: Thu, 14 Nov 2024 11:03:52 +0100 Subject: [PATCH] chore(containers): fix device foreign key in deployments the attribute type was set to :id, which sometimes generated a change when running migrations, changing the type to :integer instead of leaving it as :bigint. this happened on migration generation in the #711 this pr restores the correct database types and also removes the attribute type declaration so that the problem should not happen in the future Signed-off-by: Francesco Noacco --- backend/lib/edgehog/containers/deployment.ex | 1 - ...41114100347_fix_deployment_foreign_key.exs | 41 ++++ .../20241114100347.json | 215 ++++++++++++++++++ 3 files changed, 256 insertions(+), 1 deletion(-) create mode 100644 backend/priv/repo/migrations/20241114100347_fix_deployment_foreign_key.exs create mode 100644 backend/priv/resource_snapshots/repo/application_deployments/20241114100347.json diff --git a/backend/lib/edgehog/containers/deployment.ex b/backend/lib/edgehog/containers/deployment.ex index b74fc11d5..3a5377c9e 100644 --- a/backend/lib/edgehog/containers/deployment.ex +++ b/backend/lib/edgehog/containers/deployment.ex @@ -89,7 +89,6 @@ defmodule Edgehog.Containers.Deployment do relationships do belongs_to :device, Edgehog.Devices.Device do - attribute_type :id public? true end diff --git a/backend/priv/repo/migrations/20241114100347_fix_deployment_foreign_key.exs b/backend/priv/repo/migrations/20241114100347_fix_deployment_foreign_key.exs new file mode 100644 index 000000000..67fbf39f3 --- /dev/null +++ b/backend/priv/repo/migrations/20241114100347_fix_deployment_foreign_key.exs @@ -0,0 +1,41 @@ +# +# This file is part of Edgehog. +# +# Copyright 2024 SECO Mind Srl +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +defmodule Edgehog.Repo.Migrations.FixDeploymentForeignKey do + @moduledoc """ + Updates resources based on their most recent snapshots. + + This file was autogenerated with `mix ash_postgres.generate_migrations` + """ + + use Ecto.Migration + + def up do + alter table(:application_deployments) do + modify :device_id, :bigint + end + end + + def down do + alter table(:application_deployments) do + modify :device_id, :integer + end + end +end diff --git a/backend/priv/resource_snapshots/repo/application_deployments/20241114100347.json b/backend/priv/resource_snapshots/repo/application_deployments/20241114100347.json new file mode 100644 index 000000000..8a68c8e64 --- /dev/null +++ b/backend/priv/resource_snapshots/repo/application_deployments/20241114100347.json @@ -0,0 +1,215 @@ +{ + "attributes": [ + { + "allow_nil?": false, + "default": "fragment(\"gen_random_uuid()\")", + "generated?": false, + "primary_key?": true, + "references": null, + "size": null, + "source": "id", + "type": "uuid" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "status", + "type": "text" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "inserted_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "updated_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": { + "deferrable": false, + "destination_attribute": "tenant_id", + "destination_attribute_default": null, + "destination_attribute_generated": null, + "index?": false, + "match_type": null, + "match_with": null, + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "name": "application_deployments_tenant_id_fkey", + "on_delete": "delete", + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "tenants" + }, + "size": null, + "source": "tenant_id", + "type": "bigint" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": { + "deferrable": false, + "destination_attribute": "id", + "destination_attribute_default": null, + "destination_attribute_generated": null, + "index?": false, + "match_type": null, + "match_with": null, + "multitenancy": { + "attribute": "tenant_id", + "global": false, + "strategy": "attribute" + }, + "name": "application_deployments_device_id_fkey", + "on_delete": null, + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "devices" + }, + "size": null, + "source": "device_id", + "type": "bigint" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": { + "deferrable": false, + "destination_attribute": "id", + "destination_attribute_default": null, + "destination_attribute_generated": null, + "index?": false, + "match_type": null, + "match_with": null, + "multitenancy": { + "attribute": "tenant_id", + "global": false, + "strategy": "attribute" + }, + "name": "application_deployments_release_id_fkey", + "on_delete": null, + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "application_releases" + }, + "size": null, + "source": "release_id", + "type": "uuid" + } + ], + "base_filter": null, + "check_constraints": [], + "custom_indexes": [ + { + "all_tenants?": true, + "concurrently": false, + "error_fields": [ + "id", + "tenant_id" + ], + "fields": [ + { + "type": "atom", + "value": "id" + }, + { + "type": "atom", + "value": "tenant_id" + } + ], + "include": null, + "message": null, + "name": null, + "nulls_distinct": true, + "prefix": null, + "table": null, + "unique": true, + "using": null, + "where": null + }, + { + "all_tenants?": true, + "concurrently": false, + "error_fields": [ + "tenant_id" + ], + "fields": [ + { + "type": "atom", + "value": "tenant_id" + } + ], + "include": null, + "message": null, + "name": null, + "nulls_distinct": true, + "prefix": null, + "table": null, + "unique": false, + "using": null, + "where": null + } + ], + "custom_statements": [], + "has_create_action": true, + "hash": "834393C387179DA4F39DEC4471D85F3A8AB1CA83A546B7EB77BB705898189F50", + "identities": [ + { + "all_tenants?": false, + "base_filter": null, + "index_name": "application_deployments_release_instance_index", + "keys": [ + { + "type": "atom", + "value": "device_id" + }, + { + "type": "atom", + "value": "release_id" + } + ], + "name": "release_instance", + "nils_distinct?": true, + "where": null + } + ], + "multitenancy": { + "attribute": "tenant_id", + "global": false, + "strategy": "attribute" + }, + "repo": "Elixir.Edgehog.Repo", + "schema": null, + "table": "application_deployments" +} \ No newline at end of file