After I upgraded from Rails 5 to 6.1, the ActiveStorage raises an error:
unknown attribute 'service_name' for ActiveStorage::Blob.
Why, and how can I fix it?
These commands worked for me.
rails active_storage:update
rails db:migrate
Gemfile without the error:
gem 'rails', '~> 6.0.2'
Gemfile with the error:
gem 'rails', github: 'rails/rails', branch: 'master'
If you were already using active_storage and want to update your rails version to 6.1.0alpha, you have to run
rails active_storage:update
this will give you 2 new active_storage migrations that are needed for active_storage to work properly.
Migration 1:
# This migration comes from active_storage (originally 20190112182829)
class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
def up
unless column_exists?(:active_storage_blobs, :service_name)
add_column :active_storage_blobs, :service_name, :string
if configured_service = ActiveStorage::Blob.service.name
ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
end
change_column :active_storage_blobs, :service_name, :string, null: false
end
end
end
Migration 2:
# This migration comes from active_storage (originally 20191206030411)
class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
def up
create_table :active_storage_variant_records do |t|
t.belongs_to :blob, null: false, index: false
t.string :variation_digest, null: false
t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end
end
Than you just run
rails db:migrate
It works.
This is taken care of in the normal upgrade process:
rails app:update
rails db:migrate
This solution to the service_name change gets a mention in the 6.1 Release Notes. The rails app:update task calls the internal rails active_storage:update for you since Rails 6.0.0 (source).
step 1:
rm 20191021084642_create_active_storage_tables.active_storage.rb
step 2:
rails active_storage:install
step 3:
rails db:migrate
Related
C:\git\test (master) × berks --version
7.0.8
I have an issue with Berkshelf resolving chained git dependencies.
I have a test cookbook I generated to narrow down the issue, this cookbook depends on the cookbook windows-automation via a git reference.
test Berksfile
# frozen_string_literal: true
source 'https://supermarket.chef.io'
cookbook 'win-telegraf', path: '../win-telegraf/'
cookbook 'windows-automation', '~> 0.4.0', git: 'git#git.osky.io:ops/chef-windows-automation.git', branch: 'master'
# cookbook 'windows-library', '~> 0.1.0', git: 'git#git.osky.io:ops/chef-windows-library.git', branch: 'master'
metadata
test metadata.rb
depends 'win-telegraf'
depends 'windows-automation', '~> 0.4.0'
# depends 'windows-library', '~> 0.1.0'
windows-automation depends on windows-library via another git reference
windows-automation Berksfile
source 'https://supermarket.chef.io'
metadata
cookbook 'powershell', '~> 6.1.3'
cookbook 'windows', '~> 4.2.5'
# cookbook 'windows-library', path: '../chef-windows-library'
cookbook 'windows-library', '~> 0.1.0', git: 'git#git.osky.io:ops/chef-windows-library.git', branch: 'master'
windows-automation metadata
supports 'windows'
depends 'powershell', '~> 6.1.3'
depends 'windows-library', '~> 0.1.0'
This issue comes when I try to run berks install for the test cookbook. I get the following output
C:\git\test (master) × berks install
Resolving cookbook dependencies...
Fetching 'test' from source at .
Fetching 'win-telegraf' from source at ../win-telegraf
Fetching 'windows-automation' from git#git.osky.io:ops/chef-windows-automation.git (at master)
Fetching cookbook index from https://supermarket.chef.io...
Unable to satisfy constraints on package windows-library, which does not exist, due to solution constraint (test = 0.1.0). Solution constraints that may result in a constraint on windows-library: [(test = 0.1.0) -> (windows-automation = 0.4.0) -> (windows-library >= 0.0.0)], [(windows-automation = 0.4.0) -> (windows-library >= 0.0.0)]
Missing artifacts: windows-library
Demand that cannot be met: (test = 0.1.0)
Unable to find a solution for demands: test (0.1.0), win-telegraf (0.1.0), windows-automation (0.4.0)
This issue gets resolved if in the test cookbook I add a dependency to windows-library. But I am wondering why berkshelf cannot resolve this without the dependency. I feel like I should not need to explicitly depend on all transative git dependencies.
Known issue with berkshelf that is marked as wontfix.
https://github.com/berkshelf/berkshelf/issues/1829
So I have installed this twice now and still have the same error
I run mongod
I run unicorn
it tells me to create and account,
i create the account
log in
then Sass::SyntaxError in Locomotive/pages#index
Showing /Users/jorybraun/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/locomotive_cms-2.4.1/app/views/locomotive/shared/_head.html.haml where line #14 raised:
File to import not found or unreadable: compass/css3/transform-legacy.
Load paths:
Sass::Rails::Importer(/Users/jorybraun/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/locomotive_cms-2.4.1/app/assets/stylesheets/locomotive/backoffice/menu/main.css.scss)
/Users/jorybraun/sites/jancms/jancms/app/assets/stylesheets
/Users/jorybraun/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/compass-core-1.0.1/stylesheets
Compass::SpriteImporter
(in /Users/jorybraun/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/locomotive_cms-2.4.1/app/assets/stylesheets/locomotive/backoffice/menu/main.css.scss)
Extracted source (around line #14):
11: :plain
12: window.Locomotive = { mounted_on: '#{Locomotive.mounted_on}' }
13:
14: = stylesheet_link_tag 'locomotive', media: 'screen'
15: = javascript_include_tag 'locomotive'
16:
17: = render 'locomotive/shared/main_app_head_before_backbone'
Trace of template inclusion: /Users/jorybraun/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/locomotive_cms-2.4.1/app/views/locomotive/layouts/application.html.haml
any ideas ?
I had the same problem today. I solved it by adding the following line to my project's Gemfile:
gem 'compass', '~> 0.12.7'
Apparently there is some kind of bug in compass 1.0.1, and assets won't precompile. This line forces the version of compass to be 0.12.x, so add this in, run
bundle update
bundle install
... and you should be good to go.
On a machine I have only a user account on, I want to dump the output of a job into an sqlite database instead of textfiles. To this end, I run jruby from the jarfile.
The approach usings gems (dbi, dbd/Jdbc, jdbc/sqlite3) from a local GEM_HOME did not work (No suitable driver found) and also produces deprecation messages from the gems ("include_class is deprecated. Use java_import.")
I turned to Zentus' sqlitejdbc-v056.jar and ran JRuby with Zentus' in the path:
java -cp .:sqlitejdbc-v056.jar -jar jruby-complete-1.7.0.preview1.jar test.rb
where test.rb in inspired by http://www.zentus.com/sqlitejdbc/ and How to initialize the SQLite3 JDBC driver in JRuby? :
require 'java'
require '/home/jens/jruby/sqlitejdbc-v056.jar'
org.sqlite.JDBC # load the driver so DriverManager detects it
p clazz = Java::JavaClass.for_name("org.sqlite.JDBC")
java.sql.DriverManager.registerDriver( clazz )
#Java::OrgSqlite::JDBC # alternate means of same
puts "enumerating..."
java.sql.DriverManager.getDrivers.each{ |e| puts e }
connection = java.sql.DriverManager.getConnection 'jdbc:sqlite:/home/jens/jruby/test.db'
begin
statement = connection.createStatement
...
ensure
connection.close
end
The output I get from this is:
class org.sqlite.JDBC
enumerating...
sun.jdbc.odbc.JdbcOdbcDriver#73415727
DriverManager.java:602:in `getConnection': java.sql.SQLException: No suitable driver found for jdbc:sqlite:/home/jens/jruby/test.db
from DriverManager.java:207:in `getConnection'
from NativeMethodAccessorImpl.java:-2:in `invoke0'
...
Curiously, the driver is listed by the DriverManager, but not deemed suitable for sqlite.
I'm looking forward to any suggestions.
First of all you should use bundler to manage your gem dependencies. Bundler uses a Gemfile to list the gems you need (place it where your script is). And make sure that jruby is in your path.
In your case the Gemfile should contain:
source 'http://rubygems.org'
gem "activerecord-jdbcsqlite3-adapter", ">= 1.2"
Then execute:
bundle install --path vendor/bundle
Then modify your script like this:
require 'rubygems'
require "java"
require 'bundler/setup'
require 'jdbc/sqlite3'
Bundler.require
org.sqlite.JDBC # load the driver so DriverManager detects it
p clazz = Java::JavaClass.for_name("org.sqlite.JDBC")
java.sql.DriverManager.registerDriver( clazz )
puts "enumerating..."
java.sql.DriverManager.getDrivers.each{ |e| puts e }
connection = java.sql.DriverManager.getConnection 'jdbc:sqlite:/home/jens/jruby/test.db'
begin
statement = connection.createStatement
ensure
connection.close
end
I am having some fun with Jruby, but I am having troubles getting my app deployed on EngineYard. Under deploy I am getting the follow error:
ActiveRecord::JDBCError: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(2147483647) DEFAULT NULL' at line 1: ALTER TABLE `iterations` CHANGE `points` `points` longtext(2147483647) DEFAULT NULL
Even though my database.yml uses SQLITE and not MySQL. The migration file is listed as:
class ChangePointsToLongtext < ActiveRecord::Migration
def up
change_column :iterations, :points, :longtext
end
def down
change_column :iterations, :points, :text
end
end
I am almost certrain its the change_column - I have tried t.change and looked around for other syntax changes. I think it may be an issue with the Jruby version running on EngineYard - which I can't update.
My GemFile looks like this:
platforms :jruby do
gem 'jruby-openssl'
gem 'trinidad'
gem 'activerecord-jdbc-adapter'
gem 'activerecord-jdbcmysql-adapter'
gem 'jdbc-mysql', :require => false
gem 'jdbc-sqlite3', :require => false
end
So I believe I have all the relevant gems loaded in order to establish a database under Jruby, although I may be very wrong! I think I just need an alternative to change_column
Has anyone run into a similar problem? Or have any advice on changes? any help is always much appreciated!
Thanks
C
First, please use https://support.cloud.engineyard.com/ if you need help with Engine Yard.
Second, EY does not support SQLite. When your application is deployed to EY, EY will replace database.yml with appropriate information so that your application can use DB indicated in the environment configuration. The DB choice should default to MySQL when you set up your environment.
And finally, it appears that something is generating the incorrect SQL statement. Seeing that a similar migration works with MRI and mysql2 adapter, the issue probably lies with JDBC adapter. You can open an issue at https://github.com/jruby/activerecord-jdbc-adapter/issues or http://bugs.jruby.org.
Thanks.
I'm working on the RoR3 Tutorial and i'm on chapter 6 when I tried the rakedb:migrate command. I received the message:
rake aborted!
undefined method `prerequisites' for nil:NilClass
I ignored the changes to the Gemfile because it already was installing sqlite3. When I changed it to 'sqlite3-ruby', '1.2.5' :required => 'sqlite3', i got an ActiveRecord::ConnectionNotEstablished message when trying to view the page locally. So, I just decided to not make that change.
I am using lion os, ruby 1.9.2p290, rails 3.1.0.rc8. Thx!
I'm working on the same tutorial at the moment, and ran into the same issue. After some digging, it turns out this is a bug with rspec-rails. If you look at rpsec-rails' change log for 2.6.1
guard against calling prerequisites on nil default rake task (Jack
Dempsey)
the book also doesn't get a chance to go into detail on what's going on when you run "bundle install", turns out bundler is meant to solve application dependencies: http://gembundler.com/rationale.html
Anyway, this was the solution: https://github.com/rails/rails/issues/1723
Change 'rspec-rails' under :development in your gemfile to:
gem 'rspec-rails', '2.6.1.beta1'
and 'rspec' under :test to
gem 'rspec', '2.6'
worked for me. Let me know if you want to work through the book together!