fordfrog/apgdiff — pull request #135 by intgr (2014-02-03 21:04:11+00:00)
Title: Materialized view support (PostgreSQL 9.3+)

PostgreSQL 9.3 added support for materialized views, but apgdiff doesn't support it yet. Matviews share some traits with views (mostly CREATE MATERIALIZED VIEW) and other traits with tables (indexes & ALTER MAT.VIEW).

This patch adds basic support for matviews; I wanted to get some feedback before I invest more time into this. Copy-pasting relevant code from table/view classes together wouldn't be very nice. My thoughts so far:
* Factor out common code from PgTable and PgView into a new class, maybe PgRelation? (That's what Postgres calls them)
* Merge AlterTableParser and AlterViewParser into a single class -- there is already a fair amount of duplication in these (AlterTableParser has a parseView method!). This also mirrors how the PostgreSQL grammar works -- the syntax for all ALTER relation commands is common and only implementations differ.
* Should I keep materialized views separate from PgView or keep them together? IMO there's no need for another class.

That's quite a bit of work.

Limitations of the current code:
* It seems that the apgdiff parser is too simplistic to handle WITH DATA/WITH NO DATA, but handling them as part of the view query works without problems.
* No COMMENT ON
* No ALTER MATERIALIZED VIEW (though pg_dump generates ALTER TABLEs so basic usage is covered)
* CREATE INDEX commands on matviews are currently ignored
* Probably many more...

PS: Most projects using git keep their active development on the "master" branch and stable code lives in a separate one. I think you should do that too, it makes it easier to get started and I don't have to manually set the source branch when submitting a pull request.