简体   繁体   中英

Rails Migration Syntax Error

I'm seeing this error when I try a rake db:migrate :

/db/migrate/20180124161533_a_dd_uid_to_appuser_and_response.rb:22: syntax error, unexpected '\n', expecting =>

From what I can see, I don't see any new lines in the migration file though:

class ADdUidToAppuserAndResponse < ActiveRecord::Migration

  disable_ddl_transaction!

  def change

    add_column :appusers, :archived, :boolean, algorithm: :concurrently, if !column_exists?(:appusers, :archived)
    add_column :responses, :archived, :boolean, algorithm: :concurrently, if !column_exists?(:responses, :archived)
    add_column :appuser_rewards, :archived, :boolean, algorithm: :concurrently, if !column_exists?(:appuser_rewards, :archived)

    add_column :appusers, :last_checked_campaigns_at, :datetime, algorithm: :concurrently, if !column_exists?(:appusers, :last_checked_campaigns_at)
    add_column :appusers, :last_checked_for_available_campaigns_at, :datetime, algorithm: :concurrently, if !column_exists?(:appusers, :last_checked_for_available_campaigns_at)    

    add_column :appusers, :uid, :uuid, default: 'uuid_generate_v4()', algorithm: :concurrently, if !column_exists?(:appusers, :uid)
    add_column :responses, :uid, :uuid, default: 'uuid_generate_v4()', algorithm: :concurrently, if !column_exists?(:responses, :uid)
    add_column :appuser_rewards, :uuid, :uuid, default: 'uuid_generate_v4()', algorithm: :concurrently, if !column_exists?(:appusers, :uuid)

    add_index :appusers, :uid, algorithm: :concurrently, where: "archived = false", if !index_exists?(:appusers, :uid)
    add_index :responses, :uid, algorithm: :concurrently, where: "archived = false", if !index_exists?(:responses, :uid)


  end
end

Any idea what the problem is?

Here is the example how you should modify your code. Just remove , before if statement for all lines. So for example the line:

add_column :appusers, :archived, :boolean, algorithm: :concurrently, if !column_exists?(:appusers, :archived)

is supposed to be:

add_column :appusers, :archived, :boolean, algorithm: :concurrently if !column_exists?(:appusers, :archived)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM