influitive / apartment

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

Dumping tenants in structure.sql #550

Open alencarandre opened 6 years ago

alencarandre commented 6 years ago

Steps to reproduce

Configure to use structure.sql instead of schema.rb in rails

config.active_record.schema_format = :sql

run rake db:migrate

Create some tenant

Apartment::Tenant.create('my_tenant')

Expected behavior

~In file structure.sql must have only public schema~ In file structure.sql must have only table, without schema.

Actual behavior

In file structure.sql has public schema and other

Example:

CREATE TABLE public.ar_internal_metadata (
    key character varying NOT NULL,
    value character varying,
    created_at timestamp without time zone NOT NULL,
    updated_at timestamp without time zone NOT NULL
);

CREATE TABLE my_tenant.ar_internal_metadata (
    key character varying NOT NULL,
    value character varying,
    created_at timestamp without time zone NOT NULL,
    updated_at timestamp without time zone NOT NULL
);

System configuration

hoffmanilya commented 4 years ago

You can try to set config.active_record.dump_schemas to 'public'. This will tell AR to only dump the public schema.

https://edgeguides.rubyonrails.org/configuring.html#configuring-active-record