通过控制器 Rails 删除或删除架构 Postgresql



我有带有postgresql的多租户应用程序轨道,我想删除架构(架构名称 = 子域)并删除或表在架构上。

控制器上的原始代码,wkwkwk。accounts_controller.rb

def destroy
        @account = Account.find(params[:id])
        conn = ActiveRecord::Base.connection
        conn.execute("DROP SCHEMA "+@account.subdomain)
    end

错误信息

ActiveRecord::StatementInvalid in AccountsController#destroy
PG::Error: ERROR:  cannot drop schema subdomain1 because other objects depend on it
DETAIL:  table articles depends on schema subdomain1
table gambarinfos depends on schema subdomain1
table pages depends on schema subdomain1
table redactor_assets depends on schema subdomain1
table schema_migrations depends on schema subdomain1
table usersekolahs depends on schema subdomain1
HINT:  Use DROP ... CASCADE to drop the dependent objects too.
: DROP SCHEMA subdomain1

有什么想法吗?

感谢

问题解决方法

将级联添加到conn.execute("DROP SCHEMA "+@account.subdomain+" CASCADE")

最新更新