Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create function - the planned state does not match the desired state after applying #3200

Closed
NathanBaulch opened this issue Oct 25, 2024 · 2 comments · Fixed by #3201
Closed

Comments

@NathanBaulch
Copy link

Something seems to have changed in v0.28.0 - I can no longer apply my schema which contains functions with table row args.

> atlas.exe schema apply --env local
Abort: the planned state does not match the desired state after applying the file:
--- planned state
+++ desired state
@@ -18,7 +18,7 @@
 );
 CREATE INDEX "ix__contact__name-id" ON "contact" ("name", "id");
 CREATE INDEX "ix__contact__resource_groups-id" ON "contact" ("resource_groups", "id");
-CREATE FUNCTION "get_contact_tsv" ("data" "contact") RETURNS tsvector LANGUAGE plpgsql AS $$
+CREATE FUNCTION "get_contact_tsv" ("data" myapp.contact) RETURNS tsvector LANGUAGE plpgsql AS $$
 BEGIN
     RETURN setweight(to_tsvector(coalesce(data.name, '')), 'A');
 END;

Here's the function definition. I've also tried specifying the arg with type = table.contact but no change.

function "get_contact_tsv" {
  schema = schema.myapp
  lang   = PLpgSQL
  arg "data" {
    type = sql("contact")
  }
  return = tsvector
  as     = <<-SQL
  BEGIN
      RETURN setweight(to_tsvector(coalesce(data.name, '')), 'A');
  END;
  SQL
  depends_on = [table.contact]
}

I've also tried with v0.28.1 without luck. Where am I going wrong?

@a8m
Copy link
Member

a8m commented Oct 26, 2024

Hey @NathanBaulch 👋

Thanks for reporting this. I tried to reproduce it locally without success. Here is the schema I used:

schema "myapp" {}

table "contact" {
  schema = schema.myapp
  column "name" {
    type = text
  }
}

function "get_contact_tsv" {
  schema = schema.myapp
  lang   = PLpgSQL
  arg "data" {
    type = table.contact
  }
  return = tsvector
  as     = <<-SQL
  BEGIN
      RETURN setweight(to_tsvector(coalesce(data.name, '')), 'A');
  END;
  SQL
}

Just note, I used type = table.contact instead, since myapp.contact may differs from contact as the default search_path is public.

Could you provide a bit more information to help reproduce this? Are you using a dev-url in this env? Can you share the dev-url/url value you are using (omit the user/password/hostname before sharing).

a8m added a commit that referenced this issue Oct 26, 2024
If the connection is scoped to a specific schema, we should use InspectSchema to
get the inspected realm. That is because PostgreSQL unsets the search_path when
inspecting the entire realm, causing us to lose the schema context and get qualified
composite types on inspection.

Fixed #3200
@a8m a8m closed this as completed in #3201 Oct 26, 2024
@a8m a8m closed this as completed in f490381 Oct 26, 2024
@a8m
Copy link
Member

a8m commented Oct 26, 2024

OK, I was able to reproduce this when I scoped my connection to a specific schema.

The issue related to the new lint stage that was added to the declarative workflow (schema plan and schema apply) and it was fixed with #3201.

Thanks for reporting this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants