influitive / apartment

Database multi-tenancy for Rack (and Rails) applications
2.68k stars 460 forks source link

raw SQL doesn't get interpreted by apartment to use schemas #659

Open DonGiulio opened 4 years ago

DonGiulio commented 4 years ago

Steps to reproduce

create a migration with raw sql in it,

for example:

`

class createListView < ActiveRecord::Migration
  def up
    execute <<-SQL
    create view list as
      SELECT
      'House' AS type,
      houses.id AS id
      FROM houses
      WHERE houses.id IS NOT NULL
      UNION
      SELECT
      'Apartment' AS type,
      apartments.id AS id,
      FROM apartments
      WHERE apartments.id IS NOT NULL;
    SQL
  end

  def down
    execute 'drop view list'
  end
end

`

Expected behavior

a view is created on all tenant schemas

Actual behavior

schemas don't have the view, only the public schema has it.

System configuration