How do you do rake db: schema: dump has the encoding and field mapping in schema.rb?

One of our fields must be case sensitive. We can write a migration to change the sort that works fine, but this change is not reflected in schema.rb. This will create problems, for example, when running tests, and the cloned test database will not have the required sorting for this field.

We are using mysql.

I was looking for a way to do this without any results.

I managed to find this on github but not sure how it was done https://github.com/cantino/huginn/blob/db792cdd82eb782e98d934995964809d9e8cb77d/db/schema.rb

+5
source share
2 answers

I think there is no โ€œofficialโ€ way (provided by Rails or ActiveRecord gems) to do this type of dump. Following the git story, on the Huginn repo itself, you can find the code needed to reach this dump. Take a look at this commit: https://github.com/cantino/huginn/commit/db792cdd82eb782e98d934995964809d9e8cb77d

The most suitable code is currently located here: https://github.com/cantino/huginn/blob/master/lib/ar_mysql_column_charset/main.rb

So, if you need this feature, you probably need to copy / paste this extension into your project.

UPDATE

I did a deeper review of the Huginn repo (git history and issues), and as you can read in this comment , this functionality was extracted into a gem: https://github.com/kamipo/activerecord-mysql-awesome .

+3
source

As mentioned in @ house9's comment, you can use struct.sql instead. Add this to your application.rb project:

 config.active_record.schema_format = :sql 

Then run bundle exec rake db:structure:dump to create the actual SQL structure. This saves encodings and sortings (which should ideally be in schema.rb, but alas).

A โ€œstructureโ€ is, by its nature, less portable than a โ€œscheme,โ€ but itโ€™s generally good that all team members and environments should use the same database and version anyway.

+1
source

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


All Articles