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

Upgrade issues #2

Open
lukaVarga opened this issue Dec 7, 2018 · 0 comments
Open

Upgrade issues #2

lukaVarga opened this issue Dec 7, 2018 · 0 comments

Comments

@lukaVarga
Copy link

lukaVarga commented Dec 7, 2018

I finished upgrading Spina from 0.12 to 1.0.3 along with upgrading Rails from 5.0.x to 5.2.x and there are some issues which are not documented and which the upgrade gem does not address.

This issue is meant more like a documentation of what should be done, so others don't lose time with resolving same problems.

  1. As mentioned in Upgrade seems to require ruby-progressbar gem but not automatically included #1 , the ruby-progressbar gem is not included so you should add gem 'ruby-progressbar' to your Gemfile.
  2. (OPTIONAL): If you're often dropping your development/test DB and just wish to re-create it and run migrations, you will need to fix an old migration from Spina 0.x called CreateSpinaTranslationTables . Replace it with the following:
  def up
    create_table :spina_page_translations, force: :cascade do |t|
      t.integer :spina_page_id, null: false
      t.string :locale, null: false
      t.string :title
      t.string :menu_title
      t.string :description
      t.string :seo_title
      t.string :materialized_path
      t.datetime :created_at, null: false
      t.datetime :updated_at, null: false
      t.index [:locale], name: :index_spina_page_translations_on_locale:
      t.index [:spina_page_id], name: :index_spina_page_translations_on_spina_page_id:
    end

    create_table :spina_line_translations, force: :cascade do |t|
      t.integer :spina_line_id, null: false
      t.string :locale, null: false
      t.string :content,
      t.datetime :created_at, null: false
      t.datetime :updated_at, null: false
      t.index [:locale], name: :index_spina_line_translations_on_locale:
      t.index [:spina_line_id], name: :index_spina_line_translations_on_spina_line_id:
    end

    create_table :spina_text_translations, force: :cascade do |t|
      t.integer :spina_text_id, null: false
      t.string :locale, null: false
      t.text :content
      t.datetime :created_at, null: false
      t.datetime :updated_at, null: false
      t.index [:locale], name: :index_spina_text_translations_on_locale:
      t.index [:spina_text_id], name: :index_spina_text_translations_on_spina_text_id:
    end
  end

  def down
    drop_table :spina_page_translations
    drop_table :spina_text_translations
    drop_table :spina_line_translations
  end
  1. Prior to running the rails g spina:upgrade command, you will need to create a migration with the following:
  def change
    create_table :spina_images do |t|
      t.integer :media_folder_id

      t.timestamps
    end
    add_index :spina_images, :media_folder_id

    create_table :spina_resources do |t|
      t.string :name, null: false, unique: true
      t.string :label
      t.string :view_template
      t.integer :parent_page_id
      t.string :order_by
      t.timestamps
    end
    add_column :spina_pages, :resource_id, :integer, null: true
    add_index :spina_pages, :resource_id
    add_index :spina_resources, :parent_page_id

    create_table :spina_image_collections do |t|
      t.timestamps
    end

    create_table :spina_image_collections_images, id: :serial, force: :cascade do |t|
      t.integer :image_collection_id
      t.integer :image_id
      t.integer :position
    end

    add_index :spina_image_collections_images, :image_collection_id
    add_index :spina_image_collections_images, :image_id
  end
  1. You will also need to create an initializer for Mobility, so in config/initializers, add a mobility.rb with the following:
Mobility.configure do |config|
  config.default_backend = :table
  
  config.accessor_method = :translates
  
  config.query_method    = :i18n
end

If you haven't been using ActiveStorage before, make sure you configure everything.

  1. Run rails g spina:upgrade which will create another migration file, run all your pending db migrations, run a rake file to handle the breaking change regarding Spina Image and you should get Upgrade done

  2. Replace Spina::Photo with Spina::Image as mentioned in the docs and make the necessary changes to your templates where you use images, your image handling should now look something like this:

<% if @page.content(:image)&.file&.attached? %>
    <%= image_tag(@page.content(:image).file.service_url, alt: @page.title) %>
<% end %>
  1. That's it, grab a beer and have fun.
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

No branches or pull requests

1 participant