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

sample code for db migration doesn' work #8312

Open
2 tasks done
imurata opened this issue Jan 2, 2025 · 0 comments
Open
2 tasks done

sample code for db migration doesn' work #8312

imurata opened this issue Jan 2, 2025 · 0 comments

Comments

@imurata
Copy link
Contributor

imurata commented Jan 2, 2025

Where is the problem?

https://docs.konghq.com/gateway/latest/plugin-development/custom-entities/#migration-file-syntax

What happened?

The sample code on the Migration file syntax page of Storing Custom Entities is problematic in two ways

  • The way the END for DO is written is incorrect.
  • The assert parentheses are not completed, resulting in an error.
 assert(connector:query([[
...
]])
      END;
    $$;

What did you expect to happen?

I confirmed that the following code would work.

  postgres = {
    up = [[
      DO $$
      BEGIN
        ALTER TABLE IF EXISTS ONLY "my_plugin_table" ADD "cache_key" TEXT UNIQUE;
      EXCEPTION WHEN DUPLICATE_COLUMN THEN
        -- Do nothing, accept existing state
      END$$;
    ]],
    teardown = function(connector, helpers)
      assert(connector:connect_migrations())
      assert(connector:query([[
        DO $$
        BEGIN
          ALTER TABLE IF EXISTS ONLY "my_plugin_table" DROP "col1";
        EXCEPTION WHEN UNDEFINED_COLUMN THEN
          -- Do nothing, accept existing state
        END$$;
      ]]))
    end,
  }

Code of Conduct and Community Expectations

  • I agree to follow this project's Code of Conduct
  • I agree to abide by the Community Expectations
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

No branches or pull requests

1 participant