Fix: Materialized view reconstruction uses WITH NO DATA
During plan validation, setSchemaForEmptyDatabase reconstructs the source schema in a temporary database. For materialized views, the Add() method previously emitted CREATE MATERIALIZED VIEW ... AS <query> without WITH NO DATA, causing Postgres to execute the view's stored query. This is unnecessary (the temp DB is discarded immediately) and potentially unsafe.
Changes
- Append
WITH NO DATAto allCREATE MATERIALIZED VIEWDDL generated during schema reconstruction - Strip trailing semicolons from
pg_get_viewdef()output to prevent syntax errors when appendingWITH NO DATA
Files changed
pkg/diff/materialized_view_sql_generator.gopkg/diff/schema_migration_plan_test.go(3 new unit tests)
Full PR: #305