Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install active_storage migrations #1367

Closed
wants to merge 1 commit into from

Conversation

vsppedro
Copy link
Collaborator

@vsppedro vsppedro commented Nov 2, 2020

Suggestion: instead of creating the table manually, use the command 'bundle exec rake active_storage: install: migrations'.

@vsppedro vsppedro force-pushed the update-have-attached branch 2 times, most recently from 753acfe to a1154b2 Compare November 2, 2020 12:51
@vsppedro
Copy link
Collaborator Author

vsppedro commented Nov 2, 2020

Just taking some notes.

Error on CI with Rails 5.2 and DATABASE_ADAPTER=postgresql:

Expected User to have a has_many_attached called avatars, but this could not be proved.

         Expected User to have a has_many association called avatars_attachments (ActiveStorage::Attachment does not have a record_id foreign key.)

How to execute the tests using postgresql and Rails 5.2?

DATABASE_ADAPTER=postgresql BUNDLE_GEMFILE=/path/to/rails_5_2.gemfile bundle exec rake spec:unit

And update to_hash method to:

def to_hash
  ENVIRONMENTS.each_with_object({}) do |env, config_as_hash|
    config_as_hash[env] = {
      'adapter' => adapter.to_s,
      'database' => "#{database}_#{env}",
      'host' => 'localhost',
      'port' => 5432,
      'username' => 'postgres',
      'password' => '',
    }
  end
end

@vsppedro
Copy link
Collaborator Author

vsppedro commented Nov 5, 2020

This is weird. The active_storage tables are being created on postgres database instead of shoulda-matchers-test-development database on Rails 5.2. On Rails 6 it works and because of that, the tests pass. I will keep digging.

@vsppedro
Copy link
Collaborator Author

vsppedro commented Nov 5, 2020

To solves this problem it's necessary to update Rails from 5.2.4.1 to 5.2.4.4.

I noticed that the last PR that updated the dependencies of this project was 10 months ago - #1269. I think it's time to do another one.

@KapilSachdev
Copy link
Collaborator

5.2.4.1 to 5.2.4.4 diff does not show any related changes that might effect this issue.

I tried

DATABASE_ADAPTER=postgresql bundle exec appraisal rails_5_2 rspec spec/unit/shoulda/matchers/active_record/have_attached_matcher_spec.rb

with both the version and got the same errors.
Is upgrading working for you?

And about upgrading the dependencies, I too think we should do that.

@vsppedro
Copy link
Collaborator Author

vsppedro commented Nov 5, 2020

No, I thought it worked, but now I see it didn't work. I probably ran with another version of Rails and thought it was 5.2. My bad.

Thank you for pointing this out. I will keep digging.

@vsppedro vsppedro force-pushed the update-have-attached branch 3 times, most recently from 2025b55 to 4d11f7a Compare November 6, 2020 22:51
@vsppedro
Copy link
Collaborator Author

vsppedro commented Nov 7, 2020

I don't know the reason yet but when running bundle exec rake db:drop:all db:create:all db:migrate on Rails 5.2 with postgres the last command don't work as expected.

The migrattion is not being runned on the test database - when I tried locally it was adding in the postgres database. Separating the commands solves the problem.

I tried to change to bundle exec rake db:drop db:create db:migrate, but I got this error:

ActiveRecord::NoDatabaseError:

       FATAL:  database "shoulda-matchers-test_production" does not exist

In case you want to take a look at this error on the CI.

So, I will continue digging to get a better understanding of why we need a production database on the CI.

@vsppedro vsppedro changed the title Install active_storage migrations WIP - Install active_storage migrations Nov 7, 2020
@mcmire
Copy link
Collaborator

mcmire commented Nov 8, 2020

@vsppedro I can answer that question. We need a "production" database (really just a secondary database, but it keys off of database.yml and I think "production" was chosen just to mimic a real Rails app) in order to test the ability for have_db_index to be used with different models that connect to different databases, as added here: #1200.

@vsppedro vsppedro force-pushed the update-have-attached branch from 4d11f7a to febdaa3 Compare November 8, 2020 14:48
@vsppedro
Copy link
Collaborator Author

vsppedro commented Nov 8, 2020

Thank you for pointing this out.

I think it would be a good idea to change the names of these databases, but to be honest I can think of a better name now.

I'll leave that for later, in case I find better names and, of course, if you also think that this change would bring some value to the project.

@vsppedro vsppedro changed the title WIP - Install active_storage migrations Install active_storage migrations Nov 8, 2020
@KapilSachdev KapilSachdev added this to the 4.5.0 milestone Nov 11, 2020
@vsppedro vsppedro self-assigned this Nov 18, 2020
@vsppedro vsppedro closed this Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants