Permalink
Browse files

add the table name to the shortened index name

  • Loading branch information...
1 parent 10e2d6c commit a0446908c879b7a1b8c365ca0be539603bf42eb6 Chris Eberly committed Jun 29, 2011
Showing with 16 additions and 16 deletions.
  1. +14 −14 features/schema.feature
  2. +1 −1 lib/orel/relation/namer.rb
  3. +1 −1 spec/relation/namer_spec.rb
View
28 features/schema.feature
@@ -17,7 +17,7 @@ Feature: Create MySQL tables from relational definitions
"""
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
- UNIQUE KEY `i_b80bb7740288fda1f201890375a60c8f` (`id`)
+ UNIQUE KEY `u_i_b80bb7740288fda1f201890375a60c8f` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
"""
@@ -39,7 +39,7 @@ Feature: Create MySQL tables from relational definitions
CREATE TABLE `users` (
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
- UNIQUE KEY `fn_ln_453236cc5833e48a53bb6efb24da3d77` (`first_name`,`last_name`)
+ UNIQUE KEY `u_fn_ln_453236cc5833e48a53bb6efb24da3d77` (`first_name`,`last_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
"""
@@ -75,7 +75,7 @@ Feature: Create MySQL tables from relational definitions
`bio` text NOT NULL,
`good` tinyint(1) NOT NULL,
`time` bigint(20) NOT NULL,
- UNIQUE KEY `i_b80bb7740288fda1f201890375a60c8f` (`id`)
+ UNIQUE KEY `u_i_b80bb7740288fda1f201890375a60c8f` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
"""
@@ -104,7 +104,7 @@ Feature: Create MySQL tables from relational definitions
CREATE TABLE `user_deleted` (
`at` datetime NOT NULL,
`user_id` int(11) NOT NULL,
- UNIQUE KEY `ui_e8701ad48ba05a91604e480dd60899a3` (`user_id`),
+ UNIQUE KEY `ud_ui_e8701ad48ba05a91604e480dd60899a3` (`user_id`),
CONSTRAINT `user_deleted_users_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@@ -118,7 +118,7 @@ Feature: Create MySQL tables from relational definitions
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
- UNIQUE KEY `i_b80bb7740288fda1f201890375a60c8f` (`id`)
+ UNIQUE KEY `u_i_b80bb7740288fda1f201890375a60c8f` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
"""
@@ -148,7 +148,7 @@ Feature: Create MySQL tables from relational definitions
`at` datetime NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
- UNIQUE KEY `fn_ln_453236cc5833e48a53bb6efb24da3d77` (`first_name`,`last_name`),
+ UNIQUE KEY `ud_fn_ln_453236cc5833e48a53bb6efb24da3d77` (`first_name`,`last_name`),
CONSTRAINT `user_deleted_users_fk` FOREIGN KEY (`first_name`, `last_name`) REFERENCES `users` (`first_name`, `last_name`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@@ -163,7 +163,7 @@ Feature: Create MySQL tables from relational definitions
CREATE TABLE `users` (
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
- UNIQUE KEY `fn_ln_453236cc5833e48a53bb6efb24da3d77` (`first_name`,`last_name`)
+ UNIQUE KEY `u_fn_ln_453236cc5833e48a53bb6efb24da3d77` (`first_name`,`last_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
"""
@@ -195,15 +195,15 @@ Feature: Create MySQL tables from relational definitions
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`user_id` int(11) NOT NULL,
- UNIQUE KEY `i_b80bb7740288fda1f201890375a60c8f` (`id`),
+ UNIQUE KEY `t_i_b80bb7740288fda1f201890375a60c8f` (`id`),
KEY `things_users_fk` (`user_id`),
CONSTRAINT `things_users_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
- UNIQUE KEY `i_b80bb7740288fda1f201890375a60c8f` (`id`)
+ UNIQUE KEY `u_i_b80bb7740288fda1f201890375a60c8f` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
"""
@@ -234,14 +234,14 @@ Feature: Create MySQL tables from relational definitions
`name` varchar(255) NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
- UNIQUE KEY `fn_ln_n_b7f37fdab28b11c9e42cccaee91cd8a3` (`first_name`,`last_name`,`name`),
+ UNIQUE KEY `t_fn_ln_n_b7f37fdab28b11c9e42cccaee91cd8a3` (`first_name`,`last_name`,`name`),
CONSTRAINT `things_users_fk` FOREIGN KEY (`first_name`, `last_name`) REFERENCES `users` (`first_name`, `last_name`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `users` (
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
- UNIQUE KEY `fn_ln_453236cc5833e48a53bb6efb24da3d77` (`first_name`,`last_name`)
+ UNIQUE KEY `u_fn_ln_453236cc5833e48a53bb6efb24da3d77` (`first_name`,`last_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
"""
@@ -280,14 +280,14 @@ Feature: Create MySQL tables from relational definitions
CREATE TABLE `parts` (
`pno` varchar(255) NOT NULL,
`name` varchar(255) NOT NULL,
- UNIQUE KEY `p_a640dd405e21ee73d9ad0c1153971c0f` (`pno`)
+ UNIQUE KEY `p_p_a640dd405e21ee73d9ad0c1153971c0f` (`pno`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `shipments` (
`qty` int(11) NOT NULL,
`sno` varchar(255) NOT NULL,
`pno` varchar(255) NOT NULL,
- UNIQUE KEY `s_p_c2051a7c46108e2d1104c78f78c9862e` (`sno`,`pno`),
+ UNIQUE KEY `s_s_p_c2051a7c46108e2d1104c78f78c9862e` (`sno`,`pno`),
KEY `shipments_parts_fk` (`pno`),
CONSTRAINT `shipments_parts_fk` FOREIGN KEY (`pno`) REFERENCES `parts` (`pno`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `shipments_suppliers_fk` FOREIGN KEY (`sno`) REFERENCES `suppliers` (`sno`) ON DELETE NO ACTION ON UPDATE NO ACTION
@@ -296,7 +296,7 @@ Feature: Create MySQL tables from relational definitions
CREATE TABLE `suppliers` (
`sno` varchar(255) NOT NULL,
`name` varchar(255) NOT NULL,
- UNIQUE KEY `s_96466301bed4aeef20378fe7bb5277e6` (`sno`)
+ UNIQUE KEY `s_s_96466301bed4aeef20378fe7bb5277e6` (`sno`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
"""
View
2 lib/orel/relation/namer.rb
@@ -46,7 +46,7 @@ def unique_key_name(attribute_names)
part[0,1]
end.join
end
- full_name = [short_names, Digest::MD5.hexdigest(attribute_names.join('::'))].join('_')
+ full_name = [@name.split('_').map { |part| part[0,1] }.join, short_names, Digest::MD5.hexdigest(attribute_names.join('::'))].join('_')
full_name[0,64].to_sym
end
View
2 spec/relation/namer_spec.rb
@@ -21,7 +21,7 @@
subject.foreign_key_name(:id).should == :user_id
end
specify "a unique key name" do
- subject.unique_key_name([:first_name, :last_name]).should == ('fn_ln_' + Digest::MD5.hexdigest('first_name::last_name')).to_sym
+ subject.unique_key_name([:first_name, :last_name]).should == ('u_fn_ln_' + Digest::MD5.hexdigest('first_name::last_name')).to_sym
end
specify "a foreign key constraint name" do
pending

0 comments on commit a044690

Please sign in to comment.