Skip to content

Type casting for change_column_type_concurrently

What does this MR do?

In !33955 (closed) I tried to change the type of the properties column in the services table from text to jsonb. We store json values in this column so it would be useful to use a jsonb type.

However, change_column_type_concurrently :services, :properties, :jsonb fails with

PG::DatatypeMismatch: ERROR:  column "properties_for_type_change" is of type jsonb but expression is of type text
LINE 1: ...ATE "services" SET "properties_for_type_change" = "services"...

This is because text can't be automatically translated to json. The query it executes when the value is copied to the temporary column is

UPDATE "services" SET "properties_for_type_change" = "services"."properties"

With the type_cast option added in this MR, the query will be:

UPDATE "services" SET "properties_for_type_change" = jsonb("services"."properties")

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Andy Schoenen

Merge request reports