简体   繁体   中英

apartment gem - not creating tables postgresql

Rails 5.x , postgres, apartment gem

only below two tables created when Apartment::Tenant.create('microsoft') other 20 tables are not created, still in public schemas. microsoft schema created but not tables

在此处输入图像描述

Here is my apartment.rb

config.excluded_models = %w{ Account }

and tenant names

config.tenant_names = lambda { Account.pluck :domain }

use schemas

config.use_schemas = true

when I do rake db:migrate it is not creating anything on schema.rb whereas I created a new app with apartment. its generating another set of migration inside schema.rb.

eg: create_table "companies", force: :cascade do |t|

Please check your apartment.rb file in the initializers.

Confirm that your new tenant is configured. If you have a static array you need to extend it.

config.tenant_names = ['tenant1', 'myothertenant', 'microsoft']

You can make it also dynamic by adding a lambda to the config:

config.tenant_names = lambda { some_tenant_loading_func }

Also check that you have set the pg specific option:

config.use_schemas = true

This option specifies whether to use PostgreSQL schemas or create a new database per tenant.

sql format enabled config/application.rb

config.active_record.schema_format = :sql

as mentioned in the apartment config,

Apartment can be forced to use raw SQL dumps instead of schema.rb for creating new schemas. Use this when you are using some extra features in PostgreSQL that can't be represented in schema.rb, like materialized views etc. (only applies with use_schemas set to true). (Note: this option doesn't use db/structure.sql, it creates SQL dump by executing pg_dump)

config.use_sql = true

fixed the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM