kemen_foreigner 0.0.4 → 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,17 @@ module Foreigner
12
12
 
13
13
  execute "ALTER TABLE #{quote_table_name(table)} DROP CONSTRAINT #{quote_column_name(foreign_key_name)}"
14
14
  end
15
-
15
+
16
+ def add_primary_key(table,options)
17
+ constraint_name = "pk_#{table}_#{options[:column]}"
18
+ execute "alter table #{table} add constraint #{constraint_name} primary key (#{options[:column]})"
19
+ end
20
+
21
+ def remove_primary_key(table, options)
22
+ constraint_name = "pk_#{table}_#{options[:column]}"
23
+ execute "alter table #{table} drop constraint #{constraint_name}"
24
+ end
25
+
16
26
  def foreign_keys(table_name)
17
27
  fk_info = select_all %{
18
28
  SELECT tc.constraint_name as name
@@ -10,12 +10,13 @@ module Foreigner
10
10
  foreign_key_name = foreign_key_name(from_table, column, options)
11
11
  primary_key = options[:primary_key] || "id"
12
12
  dependency = dependency_sql(options[:dependent])
13
-
13
+
14
14
  sql =
15
15
  "ALTER TABLE #{quote_table_name(from_table)} " +
16
16
  "ADD CONSTRAINT #{quote_column_name(foreign_key_name)} " +
17
17
  "FOREIGN KEY (#{quote_column_name(column)}) " +
18
18
  "REFERENCES #{quote_table_name(ActiveRecord::Migrator.proper_table_name(to_table))}(#{primary_key})"
19
+ sql << " ON UPDATE CASCADE" if(primary_key.to_sym == :name)
19
20
  sql << " #{dependency}" if dependency.present?
20
21
  sql << " #{options[:options]}" if options[:options]
21
22
 
@@ -27,7 +28,7 @@ module Foreigner
27
28
  if options[:name]
28
29
  options[:name]
29
30
  else
30
- "#{table}_#{column}_fk"
31
+ "fk_#{table}_#{column}"
31
32
  end
32
33
  end
33
34
 
metadata CHANGED
@@ -1,32 +1,23 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: kemen_foreigner
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 4
9
- version: 0.0.4
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Cloned by Matthew Higgins
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-01-26 00:00:00 +01:00
18
- default_executable:
12
+ date: 2012-11-09 00:00:00.000000000Z
19
13
  dependencies: []
20
-
21
- description: ""
22
- email: ""
14
+ description: ''
15
+ email: ''
23
16
  executables: []
24
-
25
17
  extensions: []
26
-
27
- extra_rdoc_files:
18
+ extra_rdoc_files:
28
19
  - README.rdoc
29
- files:
20
+ files:
30
21
  - MIT-LICENSE
31
22
  - Rakefile
32
23
  - README.rdoc
@@ -40,41 +31,28 @@ files:
40
31
  - lib/kemen_foreigner.rb
41
32
  - test/helper.rb
42
33
  - test/mysql_adapter_test.rb
43
- has_rdoc: true
44
- homepage: ""
34
+ homepage: ''
45
35
  licenses: []
46
-
47
36
  post_install_message:
48
37
  rdoc_options: []
49
-
50
- require_paths:
38
+ require_paths:
51
39
  - lib
52
- required_ruby_version: !ruby/object:Gem::Requirement
40
+ required_ruby_version: !ruby/object:Gem::Requirement
53
41
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- segments:
58
- - 1
59
- - 8
60
- - 6
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
61
45
  version: 1.8.6
62
- required_rubygems_version: !ruby/object:Gem::Requirement
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
47
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- segments:
68
- - 1
69
- - 3
70
- - 5
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
71
51
  version: 1.3.5
72
52
  requirements: []
73
-
74
53
  rubyforge_project: kemen_foreigner
75
- rubygems_version: 1.3.7
54
+ rubygems_version: 1.8.11
76
55
  signing_key:
77
56
  specification_version: 3
78
57
  summary: Foreign keys for Rails
79
58
  test_files: []
80
-