Tom Hammond
Tom Hammond

Reputation: 6080

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?

Upvotes: 0

Views: 100

Answers (1)

user3309314
user3309314

Reputation: 2543

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)

Upvotes: 1

Related Questions