I am creating test and development databases that mirror the schema of an existing production database. First, I create db/schema.rb by dumping the production schema:
RAILS_ENV=production rake db:schema:dump
This creates a schema.rb which has an empty table for each system table:
ActiveRecord::Schema.define(version: 0) do
create_table "MSreplication_objects", id: false, force: :cascade do |t|
end
...
These empty tables cause an error when I try to create the test and development databases:
$ rake db:reset
-- create_table("MSreplication_objects", {:id=>false, :force=>:cascade})
rake aborted!
ActiveRecord::StatementInvalid: TinyTds::Error: Incorrect syntax near ')'.: CREATE TABLE [MSreplication_objects] ()
If, in schema.rb, I delete the definitions for the system tables, then the databases are created normally:
$ rake db:reset
-- create_table("Org", {:primary_key=>"org_id", :force=>:cascade})
-> 0.0434s
-> -1 rows
...
How can I keep rake db:schema:dump
from dumping the definitions for empty system tables that cannot be created?
Versions:
There is hope:
ActiveRecord::SchemaDumper which does most of the heavy lifting supplies a singleton method for ignoring tables:
ActiveRecord::SchemaDumper.ignore_tables = ['MSreplication_objects', 'MSAnotherStupidSystemTable']
activerecord-sqlserver-adapter
does not seem to supply its own rake task for dumping the schema (which it should) where this should have been done.