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

Error running migration 20230526212613_convert_to_active_storage.rb #1122

Open
steveyken opened this issue Jun 6, 2023 · 8 comments
Open
Assignees
Labels

Comments

@steveyken
Copy link
Member

Steps to reproduce:

  1. git clone ffcrm...
  2. bundle install
  3. rake db:create
  4. rake db:migrate

I get the following error (truncated):

== 20230526211831 CreateActiveStorageTables: migrating ========================
-- create_table(:active_storage_blobs, {:id=>:primary_key})
   -> 0.0217s
-- create_table(:active_storage_attachments, {:id=>:primary_key})
   -> 0.0273s
-- create_table(:active_storage_variant_records, {:id=>:primary_key})
   -> 0.0218s
== 20230526211831 CreateActiveStorageTables: migrated (0.0713s) ===============

== 20230526212613 ConvertToActiveStorage: migrating ===========================
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

wrong number of arguments (given 1, expected 2..3)
~/code/ffcrm/fat_free_crm/db/migrate/20230526212613_convert_to_active_storage.rb:18:in `prepare'
~code/ffcrm/fat_free_crm/db/migrate/20230526212613_convert_to_active_storage.rb:18:in `up'
...
@steveyken steveyken changed the title Error runnign migration 20230526212613_convert_to_active_storage.rb Error running migration 20230526212613_convert_to_active_storage.rb Jun 6, 2023
@steveyken steveyken added the Bug label Jun 6, 2023
@steveyken
Copy link
Member Author

steveyken commented Jun 6, 2023

Seems related to erroneous ActiveStorage migration guide code in PaperClip - thoughtbot/paperclip#2603

Potential solution: thoughtbot/paperclip#2568 (comment)

@johnbumgardner
Copy link
Member

What database are you using to get this?

@steveyken
Copy link
Member Author

postgresql, will check which version

@johnbumgardner
Copy link
Member

ugh i tested the active storage migration on sqlite and mysql, shouldve checked pg too :/

@ferrisoxide
Copy link
Contributor

I'm not sure if this is useful, but this is a hacky change that at least the migration runs - though without prepare statements unfortunately.

    ActiveRecord::Base.connection.raw_connection.then do |conn|
      unless conn.is_a?(PG::Connection)
        ActiveRecord::Base.connection.raw_connection.prepare(<<-SQL)
          INSERT INTO active_storage_blobs (
            `key`, filename, content_type, metadata, byte_size, checksum, created_at
          ) VALUES (?, ?, ?, '{}', ?, ?, ?)
        SQL

        ActiveRecord::Base.connection.raw_connection.prepare(<<-SQL)
          INSERT INTO active_storage_attachments (
            name, record_type, record_id, blob_id, created_at
          ) VALUES (?, ?, ?, #{get_blob_id}, ?)
        SQL
      end
    end

@nelsonmatenda
Copy link

I went through the same error. I tested both with postgres and mysql and I always have some error to do this migration

@ferrisoxide
Copy link
Contributor

ferrisoxide commented Jul 25, 2023

Here's a PR that at least allows the migration to run on Postgres. I haven't been able to test on MySQL or other RDBMSes

#1135

This may not be generally useful, but maybe there's something here that someone can pick through to get things working on their own boxes. I had to update Ruby in order to get mini_racer to install.

Per request from @CloCkWeRX , the fix for this has been broken out into a separate PR (see #1137)

CloCkWeRX added a commit that referenced this issue Aug 10, 2023
…n_20230526212613_convert_to_active_storage_rb

Support for Postgres prepare statement #1122
@ferrisoxide
Copy link
Contributor

Can this be closed now #1137 is in master?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants