Rake db: schema: dump does not show fields with rails 3.2.3 and SQL Server 2008

I am transferring the application from rails 2.3.8 to 3.2.3. "Rake db: schema: dump" works fine in rails 2.3 but only generates table names without column names in rails 3.2.

Even if the application successfully connected through the console, I had to change config / application.rb to enable

ActiveRecord::Base.table_name_prefix = 'dbo.' 

Do I need to do something else for the rake task to pick up these prefixes? Or is something else causing a problem with missing column names?

Further clarification: I am looking for rake db: schema: dump, because the programmers on the site stopped using migrations and immediately made changes to db. Now I am trying to restart using migration. The first step recommended in this process is to use a dump of the circuit as a starting point. Also, (and I'm not sure), it is necessary for tests to rebuild test db from db development.

+4
source share
1 answer

Short answer:

db:schema:dump wrong to use, but you can add a few lines of code to your Rakefile to get the desired result.

Longer answer:

The workaround is that the db:schema:dump task should not really dump anything more than the structure. (I know this is the wrong name.) This is an analogue of db:structure:dump , except that it gives you the .rb file and the other gives you the .sql file.

You can create your own rake reset command by adding the following code to your Rakefile:

For SQL 2008

 task :mydump do ActiveRecord::Base.connection.execute( "dbcc traceon(2544, -1) \n go \n dbcc traceon(2546, -1) \n go \n dbcc stackdump" ) end 

Using the SQL server itself to dump (this is what the output code does) limits you because the dump will always go to your log directory; you cannot specify otherwise.

If you use SqlDumper or some other utility, you will have more freedom. You can call such a utility from your rake task by executing it as from a command line using the system method. (See the MySQL example below, which uses the mysqldump utility.)

(I did not test the source code without having to install SQL 2008 myself, but the SQL source code for dumping from the SQL server is explained on this blog .)

Rake task

Then, on the command line, call rake mydump or rake mydump RAILS_ENV=production .

For MySQL

You can do something similar for MySQL with the following:

 task :mydump do config = Rails.configuration.database_configuration[Rails.env] system "mysqldump -h #{config["host"]} -u #{config["username"]} -p#{config["password"]} #{config["database"]} > db/dump.sql" end 
+5
source

Source: https://habr.com/ru/post/1415755/


All Articles