Enhancement idea: Throw error if index references a column that does not exist

16 views
Skip to first unread message

John Moses

unread,
Oct 11, 2017, 4:58:54 PM10/11/17
to Ruby on Rails: Talk
I would like to discuss the idea of throwing an error if an index is added in a migration that references a column that does not exist at the time of migration.  Currently in MySQL, when you add an index on a column that does not exist then MySQL will throw an error.  In SQLite, no error will be thrown.  The error would be encountered by the user at runtime.

Consider the following migrations:

class CreateApplications < ActiveRecord::Migration[5.1]
 
def change
    create_table
:applications do |t|
      t
.string :name


      t
.timestamps
   
end
 
end
end

class CreateVersions < ActiveRecord::Migration[5.1]
 
def change
    create_table
:versions do |t|
      t
.string :name
      t
.references :application, foreign_key: true
      t
.index [:application, :name], unique: true


      t
.timestamps
   
end
 
end
end

Has this ever come up for anybody else?  I was considering my first contribution to the code base and thought this might be a good addition, but was hoping for a consensus before starting work.

John

Ben Edwards

unread,
Oct 15, 2017, 9:20:49 AM10/15/17
to Ruby on Rails: Talk
Sqllite is not really apropreate fro production systems.  Personaly I would use Postgres, its performance is on par with MySQL and seems more robust and fully features.  i would imagine the mgrations can only throw errors from the database engine.  The fact that SQLlight does not throw an error is a good reason not to use it.
Reply all
Reply to author
Forward
0 new messages