Reputation: 1815
I have multi-tenant application rails with postgresql, i want to drop schema (schema name = subdomain) and delete or table on schema.
primitive code on controller, wkwkwk. accounts_controller.rb
def destroy
@account = Account.find(params[:id])
conn = ActiveRecord::Base.connection
conn.execute("DROP SCHEMA "[email protected])
end
error message
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
any ideas?
thx
Upvotes: 3
Views: 2176
Reputation: 1815
problem solved with
add CASCADE to conn.execute("DROP SCHEMA "[email protected]+" CASCADE")
Upvotes: 3