I am squashing migrations and rewriting all constructs like:
CREATE TABLE entities (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
title text NOT NULL,
description text
);
CREATE INDEX ON entities (title);
CREATE INDEX ON entities (description);
Into:
CREATE TABLE IF NOT EXISTS entities (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
title text NOT NULL,
description text
);
CREATE INDEX IF NOT EXISTS ON entities (title);
CREATE INDEX IF NOT EXISTS ON entities (description);
When I run the squash I get a syntax error on the CREATE INDEX IF NOT EXISTS ON entities (title);
line. After squinting harder at the docs reference I noticed IF NOT EXISTS
does in fact require name
after it.
So what is the right way to conditionally recreate "default" indexes like this?