Skip to content

sample code for db migration doesn' work #8312

Closed
@imurata

Description

@imurata

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions