Skip to content
This repository was archived by the owner on May 13, 2022. It is now read-only.
This repository was archived by the owner on May 13, 2022. It is now read-only.

Dependent Views and recreating views #165

@bamorim

Description

@bamorim

Well, I have a test suite that I keep database up do date with ActiveRecord::Migration.maintain_test_schema!

The problem is that it tries to recreate the database and sometimes it drops a view that others views depends, so it raises this exception

/home/bamorim/.rvm/gems/ruby-2.1.0@respondeai/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `async_exec': PG::DependentObjectsStillExist: ERROR:  cannot drop view analysis_periods because other objects depend on it (ActiveRecord::StatementInvalid)
DETAIL:  view impression_counts_by_period depends on view analysis_periods
view activity_statuses_by_period depends on view impression_counts_by_period
view subscription_statuses_by_period depends on view analysis_periods
view user_metrics_by_period depends on view analysis_periods
HINT:  Use DROP ... CASCADE to drop the dependent objects too.
: DROP VIEW IF EXISTS "analysis_periods"

I have two approaches for this but can't realize which one is better because they have flaws.

The first one is using CREATE OR REPLACE VIEW istead o DROP and then CREATING.
The problem is that with this approach we can't change the type of the return, I mean, we cannot change the type of each column nor the order or the number of columns.

The other approach is using DROP VIEW ... CASCADE, but with this one we wouldn't know what views are going to be dropped and then needed to be rebuilt.

What do you guys think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions