rails_materialized_views (mat_views)

Gem CI Maintainability Code Coverage License PostgreSQL

A Rails engine to define, create, refresh, and delete PostgreSQL materialized views with clean APIs, background jobs, observability, and CLI tasks. Built for high availability and repeatable ops.


Install (engine)

# Gemfile
gem 'mat_views'
# Install the gem
bundle install

# Generate the initializer and migrations
bin/rails g mat_views:install

# Run the migrations
bin/rails db:migrate
  • Installation & Setup for how to install the mat_views gem, configure it, and use the CLI tasks for managing materialized views in your Rails application.
  • Usage & Examples section for detailed guides on defining, creating, refreshing, and deleting materialized views using the mat_views gem.
  • Engine section for an overview of the engine’s structure, configuration, and how it integrates with your Rails application.
  • Validation & Benchmarking for how to validate your materialized views and benchmark their performance.
  • PostgreSQL MV Best Practices for practical, production-oriented advice on managing materialized views in PostgreSQL.
  • FAQ / Troubleshooting for answers to common questions and troubleshooting tips when working with the mat_views gem and PostgreSQL materialized views.

Features

  • DB definitions: SQL, strategy, unique index columns, dependencies
  • Create / Refresh / Delete services & jobs (uniform responses)
  • Refresh strategies: regular, concurrent (needs unique index), swap
  • CLI: Rake tasks for create/refresh/delete by name, id, or all (with confirm)
  • Observability: run tracking tables for create/refresh/delete
  • Rails-native: Active Job, Rails.logger, clear error reporting

Planned features

  • Scheduling: periodic refreshes via cron or background jobs
  • UI: dashboard for definitions, runs, errors, and manual operations
  • Notifications: alerts for failures, performance metrics
  • More job adapters: support for additional background job systems
  • Definition lifecycle: refresh or delete on definition changes
  • Any Ideas? Open an issue or PR on GitHub!

Professional support

Need help with Rails Materialized Views? We offer professional support and custom development services. Contact us at sales@codevedas.com for inquiries.

License

MIT © Codevedas Inc.