From 681a0bfc66fbc407a2facb15d69bd4af9706f46b Mon Sep 17 00:00:00 2001 From: Tianzhou Date: Sat, 11 Oct 2025 23:23:34 +0800 Subject: [PATCH] chore: correct MATERIALIZED VIEW TYPE --- internal/dump/formatter.go | 7 +++++++ testdata/dump/bytebase/pgschema.sql | 2 +- testdata/dump/employee/pgschema.sql | 2 +- testdata/dump/sakila/pgschema.sql | 2 +- testdata/dump/tenant/pgschema.sql | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/internal/dump/formatter.go b/internal/dump/formatter.go index 2cf8cd9f..b975ae66 100644 --- a/internal/dump/formatter.go +++ b/internal/dump/formatter.go @@ -365,6 +365,13 @@ func (f *DumpFormatter) formatObjectCommentHeader(step diff.Diff) string { // Always use the actual object type for consistency between single-file and multi-file modes displayType := strings.ToUpper(objectType) + // Special handling for materialized views + if displayType == "VIEW" && step.Source != nil { + if view, ok := step.Source.(*ir.View); ok && view.Materialized { + displayType = "MATERIALIZED VIEW" + } + } + output.WriteString(fmt.Sprintf("-- Name: %s; Type: %s; Schema: %s; Owner: -\n", objectName, displayType, commentSchemaName)) output.WriteString("--\n") output.WriteString("\n") diff --git a/testdata/dump/bytebase/pgschema.sql b/testdata/dump/bytebase/pgschema.sql index c6bfb888..c6905594 100644 --- a/testdata/dump/bytebase/pgschema.sql +++ b/testdata/dump/bytebase/pgschema.sql @@ -3,7 +3,7 @@ -- -- Dumped from database version PostgreSQL 17.5 --- Dumped by pgschema version 1.0.3 +-- Dumped by pgschema version 1.2.1 -- diff --git a/testdata/dump/employee/pgschema.sql b/testdata/dump/employee/pgschema.sql index a068d34e..80425b90 100644 --- a/testdata/dump/employee/pgschema.sql +++ b/testdata/dump/employee/pgschema.sql @@ -3,7 +3,7 @@ -- -- Dumped from database version PostgreSQL 17.5 --- Dumped by pgschema version 1.0.3 +-- Dumped by pgschema version 1.2.1 -- diff --git a/testdata/dump/sakila/pgschema.sql b/testdata/dump/sakila/pgschema.sql index 5f4cf7f2..d4e73305 100644 --- a/testdata/dump/sakila/pgschema.sql +++ b/testdata/dump/sakila/pgschema.sql @@ -1034,7 +1034,7 @@ CREATE OR REPLACE VIEW nicer_but_slower_film_list AS GROUP BY film.film_id, film.title, film.description, category.name, film.rental_rate, film.length, film.rating; -- --- Name: rental_by_category; Type: VIEW; Schema: -; Owner: - +-- Name: rental_by_category; Type: MATERIALIZED VIEW; Schema: -; Owner: - -- CREATE MATERIALIZED VIEW IF NOT EXISTS rental_by_category AS diff --git a/testdata/dump/tenant/pgschema.sql b/testdata/dump/tenant/pgschema.sql index 2aa2aaf6..9285a279 100644 --- a/testdata/dump/tenant/pgschema.sql +++ b/testdata/dump/tenant/pgschema.sql @@ -3,7 +3,7 @@ -- -- Dumped from database version PostgreSQL 17.5 --- Dumped by pgschema version 1.0.3 +-- Dumped by pgschema version 1.2.1 --