I need View SQL and Stored Procedure in my Rails app so I have to change from schema.rb to structure.sql. This is my config in config/application.rb
config.active_record.schema_format = :sql
but then when I create a new record for an entity in seed.rb
Company.create(
name: 'Google',
subdomain: 'google'
)
error happened
my_project/db/schema.rb doesn't exist yet
I don't know what is the problem. Did I miss something in cofig, somewhere still require schema.rb or I miss some rake task command? I just used
rake db:migrate db:test:prepare
follow this blog https://rietta.com/blog/2013/11/28/rails-and-sql-views-for-a-report/#setting-up-the-sql-view
UPDATE:
I am using apartment-gem
and Company
entity is a Tenant.
Here is config in apartment.rb
Apartment.configure do |config|
config.excluded_models = %w{ Company CommonField }
config.tenant_names = lambda{ Company.pluck(:subdomain) }
# ==> PostgreSQL only options
config.use_schemas = true
# 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 respresented 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 = false
# <== PostgreSQL only options
config.prepend_environment = !Rails.env.production?
end
I try to change config.use_schemas
to false
then enable and set config.use_sql
to true
but it still not work. Maybe it's setting for PosrtgreSQL only.
So, have any setting for MySQL?