pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

indexes on materialized views are not dumped

Open whoward opened this issue 1 year ago • 1 comments

Continuing on from #59 we've found that indexes installed on materialized views are not replicated. Here's a somewhat convoluted example:

CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    email TEXT NOT NULL,
    created_at TIMESTAMP DEFAULT NOW()
);

CREATE MATERIALIZED VIEW user_summary AS
SELECT
    id,
    email,
    created_at
FROM users;

CREATE INDEX idx_user_summary_created_at ON user_summary(created_at);
CREATE UNIQUE INDEX idx_user_summary_email ON user_summary(email);

When we run pgschema dump on this database we get the following output:

--
-- pgschema database dump
--

-- Dumped from database version PostgreSQL 17.0
-- Dumped by pgschema version 1.2.1


--
-- Name: users; Type: TABLE; Schema: -; Owner: -
--

CREATE TABLE IF NOT EXISTS users (
    id SERIAL PRIMARY KEY,
    email text NOT NULL,
    created_at timestamp DEFAULT now()
);

--
-- Name: user_summary; Type: VIEW; Schema: -; Owner: -
--

CREATE MATERIALIZED VIEW IF NOT EXISTS user_summary AS
 SELECT id,
    email,
    created_at
   FROM users;

As we can see the indexes are not included in the dump.

whoward avatar Oct 10 '25 19:10 whoward

tested this change and it works great! thanks! 👍

whoward avatar Oct 14 '25 16:10 whoward