Metadata-Version: 2.0
Name: pg-materialize
Version: 0.2.5
Summary: Postgres Materialized View Dependency Manager
Home-page: http://github.com/aanari/pg-materialize
Author: Ali Anari
Author-email: ali@anari.io
License: MIT
Keywords: pg postgres psql pgsql postgresql materialized view dependency dependencies tool
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 2.7
Classifier: Topic :: Database
Classifier: Topic :: Utilities
Requires-Dist: Pygments
Requires-Dist: click
Requires-Dist: psqlparse (==1.0rc5)
Requires-Dist: pypandoc
Requires-Dist: six
Requires-Dist: toolz
Requires-Dist: toposort

pg\_materialize |Travis Status| |AppVeyor Status|
=================================================

.. figure:: logo.jpg
   :alt: pg\_materialize

   pg\_materialize

Description
-----------

``pg_materialize`` is a utility for generating PostgreSQL creation and
refresh scripts from a folder of `Materialized
View <https://www.postgresql.org/docs/9.6/static/rules-materializedviews.html>`__
SQL definitions. It uses
`psqlparse <https://github.com/alculquicondor/psqlparse>`__ to transform
the SQL into parse trees, identifies which Materialized Views have a
dependency on other views by generating a DAG, and produces the correct
order for constructing and refreshing these views. Cross-schema views
are handled correctly, and extraneous transaction blocks are filtered
out from the final output. The files from each subsequent run are
timestamped with the suffix ``YYYYMMDD-HHMMSS.sql``.

Options
-------

``pg_materialize`` accepts the following command line arguments.

| ``-d``
| ``--dry-run``

-  Analyzes dependencies without actually generating the output files.

| ``-i``
| ``--input-dir``

-  The directory for the PostgreSQL scripts to analyze.

| ``-I``
| ``--ignore-refresh``

-  Regex pattern to match when ignoring refresh on Materialized Views
   (i.e. "hist" for "users\_mv\_hist").

| ``-o``
| ``--output_dir``

-  The directory for the output creation and refresh scripts.

| ``-p``
| ``--pattern``

-  Materialized View regex pattern to match (i.e. "\_mv" for
   "users\_mv"),

| ``-v``
| ``--verbose``

-  Enables verbose logging.

Example
-------

**Command:**

.. code:: sh

    pg_materialize -v \
        -i ~/Projects/my_project/src \
        -I hist \
        -o ~/Projects/my_project/output

**Output:**

.. code:: sh

    Found 97 Scripts in /Users/ali/Projects/my_project/src
    Identified 169 Materialized Views, Containing 90 View Dependencies

    Materialized View Dependencies:
    'public.users_mv': ['public.user_addresses_mv',
                        'public.user_invites_mv'],
    'public.orders_mv': ['public.payment_methods_mv']

    Selecting 97 Materialized Views for Refresh
    Successfully Saved Creation Script to ~/Projects/my_project/output/create-20170824-120626.sql
    Successfully Saved Refresh Script to ~/Projects/my_project/output/refresh-20170824-120626.sql

.. |Travis Status| image:: https://travis-ci.org/aanari/pg-materialize.svg?branch=master
   :target: //travis-ci.org/aanari/pg-materialize
.. |AppVeyor Status| image:: https://ci.appveyor.com/api/projects/status/xfuqfl2pv1728c6x?svg=true
   :target: https://ci.appveyor.com/project/aanari/pg-materialize/branch/master


