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

Gracefully fallback on version migrations for sqlite < 3.7.11 #24685

Merged
merged 1 commit into from Apr 22, 2016

Conversation

vipulnsward
Copy link
Member

42dd233 changed INSERT INTO versions to run in 1 single query.

This breaks for sqlite versions < 3.7.11, which is especially the case on Ubuntu 12.04 LTS, that has SQLite version 3.7.9 as default.

So we check for support for multi insert, before performing single query inserts, else fallback to older version of running multiple queries.

@vipulnsward
Copy link
Member Author

@yahonda I already took a stab at this
r? @jeremy

@yahonda
Copy link
Member

yahonda commented Apr 22, 2016

@vipulnsward Your code is much nicer than that I'm working on.

"INSERT INTO #{sm_table} (version) VALUES ('#{version}');"
}.join "\n\n"
end

Copy link
Member

@jeremy jeremy Apr 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting the insert methods means the caller is responsible for figuring out which to use. The caller is concerned with inserting versions, not with which insertion technique to use. Let's combine a single insert_versions(versions) for them to call:

def dump_schema_information
  insert_versions_sql ActiveRecord::SchemaMigration.order('version').pluck(:version)
end

def insert_versions_sql(versions)
  sm_table = ActiveRecord::Migrator.schema_migrations_table_name

  if supports_multi_insert?
    
  else
    
  end
end

def assume_migrated_upto_version(version, migrations_paths)
  
  execute insert_versions_sql(versions)
end

@vipulnsward vipulnsward force-pushed the sqlite-compat-for-multi-insert branch from 95851d7 to 961ac79 Compare April 22, 2016 19:01
@@ -29,6 +30,23 @@ def test_dump_schema_information_outputs_lexically_ordered_versions
ActiveRecord::SchemaMigration.delete_all
end

if current_adapter?(:SQLite3Adapter)
%w{3.7.8 3.7.11 3.7.12}.each do |version_string|
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added check for different versions <, <=, >

@vipulnsward vipulnsward force-pushed the sqlite-compat-for-multi-insert branch from 961ac79 to 85345ef Compare April 22, 2016 19:04
@@ -1026,7 +1047,7 @@ def assume_migrated_upto_version(version, migrations_paths)
if (duplicate = inserting.detect {|v| inserting.count(v) > 1})
raise "Duplicate migration #{duplicate}. Please renumber your migrations to resolve the conflict."
end
execute "INSERT INTO #{sm_table} (version) VALUES #{inserting.map {|v| "('#{v}')"}.join(', ') }"
insert_versions(versions)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to execute this SQL…

@vipulnsward vipulnsward force-pushed the sqlite-compat-for-multi-insert branch from 85345ef to b95155b Compare April 22, 2016 21:45
This breaks for sqlite versions < 3.7.11, which is especially the case on Ubuntu 12.04 LTS, that has SQLite version 3.7.9 as default.

So we check for support for multi insert, before performing single query inserts, else fallback to older version of running multiple queries.
[Vipul A M & Yasuo Honda]
@vipulnsward vipulnsward force-pushed the sqlite-compat-for-multi-insert branch from b95155b to 6e09828 Compare April 22, 2016 21:48
@vipulnsward
Copy link
Member Author

Done with the changes.

@jeremy jeremy merged commit 6e09828 into rails:master Apr 22, 2016
jeremy added a commit that referenced this pull request Apr 22, 2016
…sert

Gracefully fallback on version migrations for sqlite < 3.7.11
@vipulnsward vipulnsward deleted the sqlite-compat-for-multi-insert branch April 22, 2016 22:38
@vipulnsward
Copy link
Member Author

@jeremy thank you for the patient review!

@jeremy
Copy link
Member

jeremy commented Apr 22, 2016

Thank you, @vipulnsward! 👏

@amatsuda
Copy link
Member

@vipulnsward Thank you for working on this! ❤️ ❤️ ❤️

@mechanicles
Copy link
Contributor

👏

kamipo added a commit to kamipo/rails that referenced this pull request Apr 24, 2016
Follow up to rails#24685. `insert_versions_sql` is not public API.
@mvz
Copy link

mvz commented Dec 4, 2016

It appears the fallback doesn't actually work and doesn't store all versions. See the output of this Travis run: https://travis-ci.org/publify/publify_core/builds/180931099, in particular the part where I list the migrations and the versions in the migrations table:

Available migration versions:
113 InitialSchema
114 FixesBuggyArticlesAndNotes
115 DropsCategoriesForTags
20150207131657 AddMissingIndexes
20150807134129 SimplifyRedirectRelations
20150808052637 AddBlogIds
20150808191127 AddBlogIdToRedirects
20150810094754 AddBlogIdToTags
20160108111120 AddDeviseToUsers
20160108184201 MoveLastConnectionToLastSignInAt
20160110094906 RemoveProfilesRights
20160605103918 ReplaceProfileIdWithString
20160605154632 RemoveProfiles
20160701061851 DemandBlogIdOnContents
20160701062604 AddBlogIdToResources
Migrated migration versions:
114
20160701062604

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants