Skip to content

Add support for Materialized Views #173

Closed

Description

@jayadevanm

The documentation does mention that Views are not supported. It looks like Materialized Views are also not supported, though they are more like tables than views. We can create indexes, they contain data etc.

Activity

  1. added
    enhancement
    on Sep 10, 2024
  2. bplunkett-stripe commented on Sep 13, 2024

    @bplunkett-stripe
    Contributor

    It's unfortunately not the straight forward (think webs of dependencies), but I do intend to add support for them and have a mental model in my head as to how I will achieve it. I first would like to refactor the SQL generation a bit before I implement (materialized) views.

  3. KEHyeon commented on Jan 9, 2025

    @KEHyeon

    @bplunkett-stripe I wonder when the View will be added.
    and I'm very interested in this project. Can I try refactoring it too?

  4. bplunkett-stripe commented on Jan 14, 2025

    @bplunkett-stripe
    Contributor

    Sure! You can give it a shot, but a thorough implementation will be pretty complex. I can try to add really simple view support in the future.

  5. KEHyeon commented on Feb 5, 2025

    @KEHyeon

    @bplunkett-stripe
    First, I want to analyze this project code. Can you briefly explain the code and internal principles?

  6. bplunkett-stripe commented on Feb 5, 2025

    @bplunkett-stripe
    Contributor

    There are three main parts:

    1. Schema extraction
    2. Schema diffing
    3. SQL generation

    The latter part is the most complex: we take the diff generated from step 2 and build a graph that we topologically sort in order to get our ordered SQL statements

  7. kiwicopple commented on Apr 4, 2025

    @kiwicopple

    hey @bplunkett-stripe - we (supabase) would love to help with this one and then switch to using it as our default tool

    If you want to spec it out, that's great. Alternatively if you prefer for us to propose something then we can do that too. We're flexible - let us know the best direction. I'm available on emails/dms(all platforms) if you want to chat.

  8. bplunkett-stripe commented on Apr 4, 2025

    @bplunkett-stripe
    Contributor

    I'll try to take a stab at it this weekend. I think there are some large simplifications I can make to get some sort of MVP out.

    I'll add I am basically working on this in my own free time. Ironically, I work on schema-less document databases now, so I have to balance this against other priorities.

  9. Navbryce commented on Aug 12, 2025

    @Navbryce
    Collaborator

    Rough materialized view support has been added. I still need to add support for indexes...and various "quality of life" features.

  10. ewan-escience commented on Sep 10, 2025

    @ewan-escience

    When using pg-schema-diff to (as a test only) migrate the RSD from version 5.1.0 to version 5.2.0, I get the following error message:

    Error: generating plan: generating plan statements: diffing indexes: diffing for "public"."count_software_mentions_cached_software_idx": checking if index is on partitioned table: could not find table in new schema with name "public"."count_software_mentions_cached"
    

    The index is on a materialized view, which can be found here.

    I'm using v1.0.2 of pg-schema-diff (in Docker), golang:1.22.12-bookworm (Docker) and postgres:17.6 (Docker). Is an error like this still expected? Can I tell pg-schema-diff to ignore errors like these?

  11. jperasmus commented on Nov 20, 2025

    @jperasmus

    Ran into the same error as @ewan-escience using pg-schema-diff via the Supabase CLI (v2.58.5). I see that indexes on matviews were reverted here

    Are there plans to support indexes in the near future, or did you hit a dead end for now?

  12. surprisetalk commented on Dec 3, 2025

    @surprisetalk

    Yep, running into the same issue:

    ~/D/superbam pg-schema-diff plan --from-dsn 'postgresql://[email protected]:5432/superbam' --to-dir db.sql                                                                                   
    Error: generating plan: generating plan statements: generating migration statements: resolving index diff: generating delete statements for "sb"."sb_stat_t_idx": generating sql: could not find table in new schema with name "sb"."stat"   
    
  13. GeertJohan commented on Dec 12, 2025

    @GeertJohan

    Thanks @bernardoamc-stripe / @Navbryce for your work on this!

    Can you please elaborate on what is needed to get the revert reverted? Is that about the two TODO's that are in there?

  14. bplunkett-stripe commented on Dec 31, 2025

    @bplunkett-stripe
    Contributor

    Index support for materialized views has been added! Let me know if that solves everyone's above asks!

  15. GeertJohan commented on Dec 31, 2025

    @GeertJohan

    Thanks @bplunkett-stripe, this fixed the errors around materialized view I ran into :)

    We've recently changed trek to use pg-schema-diff, it was using migra before. So far it's been a good experience. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions