fat_free_crm icon indicating copy to clipboard operation
fat_free_crm copied to clipboard

Error running migration 20230526212613_convert_to_active_storage.rb

Open steveyken opened this issue 1 year ago • 8 comments

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 avatar Jun 06 '23 07:06 steveyken

Seems related to erroneous ActiveStorage migration guide code in PaperClip - https://github.com/thoughtbot/paperclip/issues/2603

Potential solution: https://github.com/thoughtbot/paperclip/pull/2568#issuecomment-381629629

steveyken avatar Jun 06 '23 07:06 steveyken

What database are you using to get this?

johnbumgardner avatar Jun 06 '23 13:06 johnbumgardner

postgresql, will check which version

steveyken avatar Jun 06 '23 13:06 steveyken

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

johnbumgardner avatar Jun 06 '23 13:06 johnbumgardner

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

ferrisoxide avatar Jul 07 '23 12:07 ferrisoxide

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

nelsonmatenda avatar Jul 25 '23 13:07 nelsonmatenda

~~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~~

~~https://github.com/fatfreecrm/fat_free_crm/pull/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)

ferrisoxide avatar Jul 25 '23 15:07 ferrisoxide

Can this be closed now #1137 is in master?

ferrisoxide avatar Aug 27 '23 09:08 ferrisoxide