Atlas now keeps an index operator class that PostgreSQL would not pick for the column on its own, such as text_ops on a citext column or bpchar_ops on a varchar column.
An index that names no operator class gets the default class of its column type, and an index can name another class the column type accepts. Inspection used to drop such a class whenever it was the default for its own input type, so plans and HCL recreated the index with the class PostgreSQL picks for the column. On a citext column, that turned text_ops, which compares values as text, into the case-insensitive citext_ops. Atlas now keeps the ops of these indexes, and still leaves out the class PostgreSQL picks.
Example
Two indexes on a citext column, with the extension installed:
CREATE TABLE users (email citext NOT NULL);CREATE UNIQUE INDEX users_email ON users (email citext_ops);CREATE INDEX users_email_text ON users (email text_ops);
atlas schema inspect keeps text_ops, which PostgreSQL does not pick for citext, and leaves out citext_ops, which it does:
table "users" { schema = schema.public column "email" { null = false type = sql("citext") } index "users_email" { unique = true columns = [column.email] } index "users_email_text" { on { column = column.email ops = text_ops } }}
Plans create the indexes the same way:
-- Create "users" tableCREATE TABLE "users" ( "email" citext NOT NULL);-- Create index "users_email" to table: "users"CREATE UNIQUE INDEX "users_email" ON "users" ("email");-- Create index "users_email_text" to table: "users"CREATE INDEX "users_email_text" ON "users" ("email" text_ops);
Existing schemas
Indexes inspected by earlier versions may have lost their class. After upgrading:
- atlas schema inspect reports the class of such indexes. HCL written without it plans a rebuild that drops the class, so add ops to keep it.
- atlas migrate diff plans a rebuild for indexes that migration files created without the class the desired schema names.