diff options
author | Pavel Pravosud <pavel@pravosud.com> | 2016-05-10 15:10:46 -0700 |
---|---|---|
committer | Jon McCartie <jon@mccartie.com> | 2016-12-05 11:40:32 -0800 |
commit | 3e452b12043ecfd983c6132d6eb97eb79db952b7 (patch) | |
tree | 4c6d98ed9f1a35a13ccb2f7be3d903a05a3a6ec8 /activerecord/lib/active_record/connection_adapters | |
parent | b92ae610699f991e4616409815fa1e7f134dacc5 (diff) | |
download | rails-3e452b12043ecfd983c6132d6eb97eb79db952b7.tar.gz rails-3e452b12043ecfd983c6132d6eb97eb79db952b7.tar.bz2 rails-3e452b12043ecfd983c6132d6eb97eb79db952b7.zip |
Make pg adapter use bigserial for pk by default
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 6eb7e0ae52..971b274265 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -39,7 +39,7 @@ module ActiveRecord self.emulate_booleans = true NATIVE_DATABASE_TYPES = { - primary_key: "BIGINT(8) UNSIGNED DEFAULT NULL auto_increment PRIMARY KEY", + primary_key: "BIGINT(8) UNSIGNED auto_increment PRIMARY KEY", string: { name: "varchar", limit: 255 }, text: { name: "text", limit: 65535 }, integer: { name: "int", limit: 4 }, @@ -736,6 +736,8 @@ module ActiveRecord ER_NO_REFERENCED_ROW_2 = 1452 ER_DATA_TOO_LONG = 1406 ER_LOCK_DEADLOCK = 1213 + ER_CANNOT_ADD_FOREIGN = 1215 + ER_CANNOT_CREATE_TABLE = 1005 def translate_exception(exception, message) case error_number(exception) @@ -743,6 +745,14 @@ module ActiveRecord RecordNotUnique.new(message) when ER_NO_REFERENCED_ROW_2 InvalidForeignKey.new(message) + when ER_CANNOT_ADD_FOREIGN + mismatched_foreign_key(message) + when ER_CANNOT_CREATE_TABLE + if message.include?("errno: 150") + mismatched_foreign_key(message) + else + super + end when ER_DATA_TOO_LONG ValueTooLong.new(message) when ER_LOCK_DEADLOCK @@ -914,6 +924,18 @@ module ActiveRecord MySQL::TableDefinition.new(*args) end + def mismatched_foreign_key(message) + parts = message.scan(/`(\w+)`[ $)]/).flatten + MismatchedForeignKey.new( + self, + message: message, + table: parts[0], + foreign_key: parts[1], + target_table: parts[2], + primary_key: parts[3], + ) + end + def extract_schema_qualified_name(string) # :nodoc: schema, name = string.to_s.scan(/[^`.\s]+|`[^`]*`/) schema, name = @config[:database], schema unless name |