composite_primary_keys 0.8.6 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/History.txt +9 -0
  2. data/Manifest.txt +37 -0
  3. data/README.txt +34 -9
  4. data/README_DB2.txt +33 -0
  5. data/Rakefile +8 -119
  6. data/init.rb +2 -0
  7. data/lib/adapter_helper/base.rb +63 -0
  8. data/lib/adapter_helper/mysql.rb +13 -0
  9. data/lib/adapter_helper/oracle.rb +13 -0
  10. data/lib/adapter_helper/postgresql.rb +13 -0
  11. data/lib/adapter_helper/sqlite3.rb +13 -0
  12. data/lib/composite_primary_keys.rb +2 -2
  13. data/lib/composite_primary_keys/associations.rb +53 -28
  14. data/lib/composite_primary_keys/base.rb +4 -1
  15. data/lib/composite_primary_keys/connection_adapters/ibm_db_adapter.rb +21 -0
  16. data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +1 -1
  17. data/lib/composite_primary_keys/migration.rb +13 -0
  18. data/lib/composite_primary_keys/version.rb +2 -2
  19. data/loader.rb +24 -0
  20. data/local/database_connections.rb.sample +10 -0
  21. data/local/paths.rb.sample +2 -0
  22. data/local/tasks.rb.sample +2 -0
  23. data/scripts/console.rb +25 -0
  24. data/tasks/activerecord_selection.rake +43 -0
  25. data/tasks/databases.rake +10 -0
  26. data/tasks/databases/mysql.rake +30 -0
  27. data/tasks/databases/oracle.rake +15 -0
  28. data/tasks/databases/postgresql.rake +26 -0
  29. data/tasks/databases/sqlite3.rake +28 -0
  30. data/tasks/deployment.rake +22 -0
  31. data/tasks/local_setup.rake +13 -0
  32. data/tasks/website.rake +18 -0
  33. data/test/README_tests.txt +67 -0
  34. data/test/abstract_unit.rb +2 -4
  35. data/test/connections/native_ibm_db/connection.rb +23 -0
  36. data/test/connections/native_mysql/connection.rb +8 -13
  37. data/test/connections/native_oracle/connection.rb +8 -11
  38. data/test/connections/native_postgresql/connection.rb +3 -9
  39. data/test/connections/native_sqlite/connection.rb +4 -5
  40. data/test/fixtures/comment.rb +5 -0
  41. data/test/fixtures/comments.yml +14 -0
  42. data/test/fixtures/db_definitions/db2-create-tables.sql +92 -0
  43. data/test/fixtures/db_definitions/db2-drop-tables.sql +13 -0
  44. data/test/fixtures/db_definitions/mysql.sql +24 -0
  45. data/test/fixtures/db_definitions/oracle.drop.sql +6 -0
  46. data/test/fixtures/db_definitions/oracle.sql +28 -1
  47. data/test/fixtures/db_definitions/postgresql.sql +24 -0
  48. data/test/fixtures/db_definitions/sqlite.sql +21 -0
  49. data/test/fixtures/department.rb +5 -0
  50. data/test/fixtures/departments.yml +3 -0
  51. data/test/fixtures/employee.rb +4 -0
  52. data/test/fixtures/employees.yml +9 -0
  53. data/test/fixtures/hack.rb +6 -0
  54. data/test/fixtures/hacks.yml +2 -0
  55. data/test/fixtures/product.rb +3 -2
  56. data/test/fixtures/streets.yml +11 -1
  57. data/test/fixtures/suburb.rb +2 -0
  58. data/test/fixtures/suburbs.yml +6 -1
  59. data/test/fixtures/user.rb +1 -0
  60. data/test/test_associations.rb +29 -5
  61. data/test/test_delete.rb +23 -2
  62. data/test/test_polymorphic.rb +24 -0
  63. data/tmp/test.db +0 -0
  64. data/website/index.html +2 -2
  65. data/website/version-raw.js +1 -1
  66. data/website/version.js +1 -1
  67. metadata +43 -3
data/History.txt CHANGED
@@ -1,3 +1,12 @@
1
+ == 0.9.0 2007-09-28
2
+
3
+ * Added support for polymorphs [thx nerdrew]
4
+ * init.rb file so gem can be installed as a plugin for Rails [thx nerdrew]
5
+ * Added ibm_db support [thx K Venkatasubramaniyan]
6
+ * Support for cleaning dependents [thx K Venkatasubramaniyan]
7
+ * Rafactored db rake tasks into namespaces
8
+ * Added namespaced tests (e.g. mysql:test for test_mysql)
9
+
1
10
  == 0.8.6 / 2007-6-12
2
11
 
3
12
  * 1 emergency fix due to Rails Core change
data/Manifest.txt CHANGED
@@ -1,35 +1,70 @@
1
1
  History.txt
2
2
  Manifest.txt
3
3
  README.txt
4
+ README_DB2.txt
4
5
  Rakefile
6
+ init.rb
5
7
  install.rb
8
+ lib/adapter_helper/base.rb
9
+ lib/adapter_helper/mysql.rb
10
+ lib/adapter_helper/oracle.rb
11
+ lib/adapter_helper/postgresql.rb
12
+ lib/adapter_helper/sqlite3.rb
6
13
  lib/composite_primary_keys.rb
7
14
  lib/composite_primary_keys/associations.rb
8
15
  lib/composite_primary_keys/base.rb
9
16
  lib/composite_primary_keys/calculations.rb
10
17
  lib/composite_primary_keys/composite_arrays.rb
18
+ lib/composite_primary_keys/connection_adapters/ibm_db_adapter.rb
11
19
  lib/composite_primary_keys/connection_adapters/oracle_adapter.rb
12
20
  lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
13
21
  lib/composite_primary_keys/fixtures.rb
22
+ lib/composite_primary_keys/migration.rb
14
23
  lib/composite_primary_keys/reflection.rb
15
24
  lib/composite_primary_keys/version.rb
25
+ loader.rb
26
+ local/database_connections.rb.sample
27
+ local/paths.rb.sample
28
+ local/tasks.rb.sample
29
+ scripts/console.rb
16
30
  scripts/txt2html
17
31
  scripts/txt2js
32
+ tasks/activerecord_selection.rake
33
+ tasks/databases.rake
34
+ tasks/databases/mysql.rake
35
+ tasks/databases/oracle.rake
36
+ tasks/databases/postgresql.rake
37
+ tasks/databases/sqlite3.rake
38
+ tasks/deployment.rake
39
+ tasks/local_setup.rake
40
+ tasks/website.rake
41
+ test/README_tests.txt
18
42
  test/abstract_unit.rb
19
43
  test/composite_arrays_test.rb
44
+ test/connections/native_ibm_db/connection.rb
20
45
  test/connections/native_mysql/connection.rb
21
46
  test/connections/native_oracle/connection.rb
22
47
  test/connections/native_postgresql/connection.rb
23
48
  test/connections/native_sqlite/connection.rb
24
49
  test/fixtures/article.rb
25
50
  test/fixtures/articles.yml
51
+ test/fixtures/comment.rb
52
+ test/fixtures/comments.yml
53
+ test/fixtures/db_definitions/db2-create-tables.sql
54
+ test/fixtures/db_definitions/db2-drop-tables.sql
26
55
  test/fixtures/db_definitions/mysql.sql
27
56
  test/fixtures/db_definitions/oracle.drop.sql
28
57
  test/fixtures/db_definitions/oracle.sql
29
58
  test/fixtures/db_definitions/postgresql.sql
30
59
  test/fixtures/db_definitions/sqlite.sql
60
+ test/fixtures/department.rb
61
+ test/fixtures/departments.yml
62
+ test/fixtures/employee.rb
63
+ test/fixtures/employees.yml
31
64
  test/fixtures/group.rb
32
65
  test/fixtures/groups.yml
66
+ test/fixtures/hack.rb
67
+ test/fixtures/hacks.yml
33
68
  test/fixtures/membership.rb
34
69
  test/fixtures/membership_status.rb
35
70
  test/fixtures/membership_statuses.yml
@@ -63,9 +98,11 @@ test/test_find.rb
63
98
  test/test_ids.rb
64
99
  test/test_miscellaneous.rb
65
100
  test/test_pagination.rb
101
+ test/test_polymorphic.rb
66
102
  test/test_santiago.rb
67
103
  test/test_tutorial_examle.rb
68
104
  test/test_update.rb
105
+ tmp/test.db
69
106
  website/index.html
70
107
  website/index.txt
71
108
  website/javascripts/rounded_corners_lite.inc.js
data/README.txt CHANGED
@@ -1,16 +1,41 @@
1
+ = Composite Primary Keys for ActiveRecords
2
+
3
+ == Summary
1
4
 
2
- Composite Primary Keys for ActiveRecords
3
- Summary:
4
5
  ActiveRecords/Rails famously doesn't support composite primary keys.
5
- For 2 years there has been no support for this aspect of legacy databases.
6
- This project will be a fully-featured solution and I welcome use cases and
7
- legacy DB schema samples to help make the project work with as many common
8
- legacy environments as possible.
6
+ This RubyGem extends the activerecord gem to provide CPK support.
7
+
8
+ == Installation
9
+
10
+ gem install composite_primary_keys
11
+
12
+ == Usage
13
+
14
+ require 'composite_primary_keys'
15
+ class ProductVariation
16
+ set_primary_keys :product_id, :variation_seq
17
+ end
18
+
19
+ pv = ProductVariation.find(345, 12)
20
+
21
+ It even supports composite foreign keys for associations.
22
+
23
+ See http://compositekeys.rubyforge.org for more.
24
+
25
+ == Running Tests
26
+
27
+ See test/README.tests.txt
28
+
29
+ == Url
9
30
 
10
- Url:
11
31
  http://compositekeys.rubyforge.org
12
32
 
13
- Questions and Discussion:
33
+ == Questions, Discussion and Contributions
34
+
14
35
  http://groups.google.com/compositekeys
15
36
 
16
- Written by Dr Nic Williams, drnicwilliams@gmail
37
+ == Author
38
+
39
+ Written by Dr Nic Williams, drnicwilliams@gmail
40
+ Contributions by many!
41
+
data/README_DB2.txt ADDED
@@ -0,0 +1,33 @@
1
+ Composite Primary key support for db2
2
+
3
+ == Driver Support ==
4
+
5
+ DB2 support requires the IBM_DB driver provided by http://rubyforge.org/projects/rubyibm/
6
+ project. Install using gem install ibm_db. Tested against version 0.60 of the driver.
7
+ This rubyforge project appears to be permenant location for the IBM adapter.
8
+ Older versions of the driver available from IBM Alphaworks will not work.
9
+
10
+ == Driver Bug and workaround provided as part of this plugin ==
11
+
12
+ Unlike the basic quote routine available for Rails AR, the DB2 adapter's quote
13
+ method doesn't return " column_name = 1 " when string values (integers in string type variable)
14
+ are passed for quoting numeric column. Rather it returns "column_name = '1'.
15
+ DB2 doesn't accept single quoting numeric columns in SQL. Currently, as part of
16
+ this plugin a fix is provided for the DB2 adapter since this plugin does
17
+ pass string values like this. Perhaps a patch should be sent to the DB2 adapter
18
+ project for a permanant fix.
19
+
20
+ == Database Setup ==
21
+
22
+ Database must be manually created using a separate command. Read the rake task
23
+ for creating tables and change the db name, user and passwords accordingly.
24
+
25
+ == Tested Database Server version ==
26
+
27
+ This is tested against DB2 v9.1 in Ubuntu Feisty Fawn (7.04)
28
+
29
+ == Tested Database Client version ==
30
+
31
+ This is tested against DB2 v9.1 in Ubuntu Feisty Fawn (7.04)
32
+
33
+
data/Rakefile CHANGED
@@ -15,14 +15,17 @@ AUTHOR = "Dr Nic Williams"
15
15
  EMAIL = "drnicwilliams@gmail.com"
16
16
  DESCRIPTION = "Composite key support for ActiveRecords"
17
17
  GEM_NAME = "composite_primary_keys" # what ppl will type to install your gem
18
- config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
19
- RUBYFORGE_USERNAME = config["username"]
18
+ if File.exists?("~/.rubyforge/user-config.yml")
19
+ # TODO this should prob go in a local/ file
20
+ config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
21
+ RUBYFORGE_USERNAME = config["username"]
22
+ end
20
23
  RUBYFORGE_PROJECT = "compositekeys"
21
24
  HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
22
25
 
23
26
  REV = nil #File.read(".svn/entries")[/committed-rev="(\d+)"/, 1] rescue nil
24
27
  VERS = ENV['VERSION'] || (CompositePrimaryKeys::VERSION::STRING + (REV ? ".#{REV}" : ""))
25
- CLEAN.include ['**/.*.sw?', '*.gem', '.config','debug.log','*.db','logfile','.DS_Store', '.project']
28
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config','debug.log','*.db','logfile','log/**/*','**/.DS_Store', '.project']
26
29
  RDOC_OPTS = ['--quiet', '--title', "newgem documentation",
27
30
  "--opname", "index.html",
28
31
  "--line-numbers",
@@ -57,120 +60,6 @@ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\n\n")
57
60
  PATH = RUBYFORGE_PROJECT
58
61
  hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
59
62
 
63
+ PROJECT_ROOT = File.expand_path(".")
60
64
 
61
- # UNTESTED - firebird sqlserver sqlserver_odbc db2 sybase openbase
62
- for adapter in %w( mysql sqlite oracle postgresql )
63
- Rake::TestTask.new("test_#{adapter}") { |t|
64
- t.libs << "test" << "test/connections/native_#{adapter}"
65
- t.pattern = "test/test_*.rb"
66
- t.verbose = true
67
- }
68
- end
69
-
70
- SCHEMA_PATH = File.join(File.dirname(__FILE__), *%w(test fixtures db_definitions))
71
-
72
- desc 'Build the MySQL test databases'
73
- task :build_mysql_databases do
74
- puts File.join(SCHEMA_PATH, 'mysql.sql')
75
- socket = '/Applications/MAMP/tmp/mysql/mysql.sock'
76
- user = 'root'
77
- sh %{ mysqladmin -u #{user} -S #{socket} -p create "#{GEM_NAME}_unittest" }
78
- sh %{ mysql -u #{user} -S #{socket} -p "#{GEM_NAME}_unittest" < #{File.join(SCHEMA_PATH, 'mysql.sql')} }
79
- end
80
-
81
- desc 'Drop the MySQL test databases'
82
- task :drop_mysql_databases do
83
- socket = '/Applications/MAMP/tmp/mysql/mysql.sock'
84
- user = 'root'
85
- sh %{ mysqladmin -u #{user} -S #{socket} -p -f drop "#{GEM_NAME}_unittest" }
86
- end
87
-
88
- desc 'Rebuild the MySQL test databases'
89
-
90
- task :rebuild_mysql_databases => [:drop_mysql_databases, :build_mysql_databases]
91
-
92
- desc 'Build the sqlite test databases'
93
- task :build_sqlite_databases do
94
- file = File.join(SCHEMA_PATH, 'sqlite.sql')
95
- cmd = "sqlite3 test.db < #{file}"
96
- puts cmd
97
- sh %{ #{cmd} }
98
- end
99
-
100
- desc 'Drop the sqlite test databases'
101
- task :drop_sqlite_databases do
102
- sh %{ rm -f test.db }
103
- end
104
-
105
- desc 'Rebuild the sqlite test databases'
106
- task :rebuild_sqlite_databases => [:drop_sqlite_databases, :build_sqlite_databases]
107
-
108
- desc 'Build the PostgreSQL test databases'
109
- task :build_postgresql_databases do
110
- sh %{ createdb "#{GEM_NAME}_unittest" }
111
- sh %{ psql "#{GEM_NAME}_unittest" -f #{File.join(SCHEMA_PATH, 'postgresql.sql')} }
112
- end
113
-
114
- desc 'Drop the PostgreSQL test databases'
115
- task :drop_postgresql_databases do
116
- sh %{ dropdb "#{GEM_NAME}_unittest" }
117
- end
118
-
119
- desc 'Rebuild the PostgreSQL test databases'
120
- task :rebuild_postgresql_databases => [:drop_postgresql_databases, :build_postgresql_databases]
121
-
122
- desc 'Build the Oracle test databases'
123
- task :build_oracle_databases do
124
- puts File.join(SCHEMA_PATH, 'oracle.sql')
125
- sh %( sqlplus holstdl/holstdl@test < #{File.join(SCHEMA_PATH, 'oracle.sql')} )
126
- end
127
-
128
- desc 'Drop the Oracle test databases'
129
- task :drop_oracle_databases do
130
- sh %( sqlplus holstdl/holstdl@test < #{File.join(SCHEMA_PATH, 'oracle.drop.sql')} )
131
- end
132
-
133
- desc 'Rebuild the Oracle test databases'
134
- task :rebuild_oracle_databases => [:drop_oracle_databases, :build_oracle_databases]
135
-
136
- desc 'Generate website files'
137
- task :website_generate do
138
- sh %{ ruby scripts/txt2html website/index.txt > website/index.html }
139
- sh %{ ruby scripts/txt2js website/version.txt > website/version.js }
140
- sh %{ ruby scripts/txt2js website/version-raw.txt > website/version-raw.js }
141
- end
142
-
143
- desc 'Upload website files to rubyforge'
144
- task :website_upload do
145
- config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
146
- host = "#{config["username"]}@rubyforge.org"
147
- remote_dir = "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}/"
148
- local_dir = 'website'
149
- sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
150
- end
151
-
152
- desc 'Generate and upload website files'
153
- task :website => [:website_generate, :website_upload, :publish_docs]
154
-
155
- desc 'Release the website and new gem version'
156
- task :deploy => [:check_version, :website, :release] do
157
- puts "Remember to create SVN tag:"
158
- puts "svn copy svn+ssh://#{RUBYFORGE_USERNAME}@rubyforge.org/var/svn/#{PATH}/trunk " +
159
- "svn+ssh://#{RUBYFORGE_USERNAME}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
160
- puts "Suggested comment:"
161
- puts "Tagging release #{CHANGES}"
162
- end
163
-
164
- desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
165
- task :local_deploy => [:website_generate, :install_gem]
166
-
167
- task :check_version do
168
- unless ENV['VERSION']
169
- puts 'Must pass a VERSION=x.y.z release version'
170
- exit
171
- end
172
- unless ENV['VERSION'] == VERS
173
- puts "Please update your version.rb to match the release version, currently #{VERS}"
174
- exit
175
- end
176
- end
65
+ require 'loader'
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ # Include hook code here
2
+ require_dependency 'composite_primary_keys'
@@ -0,0 +1,63 @@
1
+ module AdapterHelper
2
+ class Base
3
+ class << self
4
+ attr_accessor :adapter
5
+
6
+ def load_connection_from_env(adapter)
7
+ self.adapter = adapter
8
+ unless ENV['cpk_adapters']
9
+ puts error_msg_setup_helper
10
+ exit
11
+ end
12
+
13
+ all_specs = YAML.load(ENV['cpk_adapters'])
14
+ unless spec = all_specs[adapter]
15
+ puts error_msg_adapter_helper
16
+ exit
17
+ end
18
+ spec[:adapter] = adapter
19
+ spec
20
+ end
21
+
22
+ def error_msg_setup_helper
23
+ <<-EOS
24
+ Setup Helper:
25
+ CPK now has a place for your individual testing configuration.
26
+ That is, instead of hardcoding it in the Rakefile and test/connections files,
27
+ there is now a local/database_connections.rb file that is NOT in the
28
+ repository. Your personal DB information (username, password etc) can
29
+ be stored here without making it difficult to submit patches etc.
30
+
31
+ Installation:
32
+ i) cp locals/database_connections.rb.sample locals/database_connections.rb
33
+ ii) For #{adapter} connection details see "Adapter Setup Helper" below.
34
+ iii) Rerun this task
35
+
36
+ #{error_msg_adapter_helper}
37
+
38
+ Current ENV:
39
+ #{ENV.inspect}
40
+ EOS
41
+ end
42
+
43
+ def error_msg_adapter_helper
44
+ <<-EOS
45
+ Adapter Setup Helper:
46
+ To run #{adapter} tests, you need to setup your #{adapter} connections.
47
+ In your local/database_connections.rb file, within the ENV['cpk_adapter'] hash, add:
48
+ "#{adapter}" => { adapter settings }
49
+
50
+ That is, it will look like:
51
+ ENV['cpk_adapters'] = {
52
+ "#{adapter}" => {
53
+ :adapter => "#{adapter}",
54
+ :username => "root",
55
+ :password => "root",
56
+ # ...
57
+ }
58
+ }.to_yaml
59
+ EOS
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), 'base')
2
+
3
+ module AdapterHelper
4
+ class MySQL < Base
5
+ class << self
6
+ def load_connection_from_env
7
+ spec = super('mysql')
8
+ spec[:database] ||= 'composite_primary_keys_unittest'
9
+ spec
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), 'base')
2
+
3
+ module AdapterHelper
4
+ class Oracle < Base
5
+ class << self
6
+ def load_connection_from_env
7
+ spec = super('oracle')
8
+ spec[:database] ||= 'composite_primary_keys_unittest'
9
+ spec
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), 'base')
2
+
3
+ module AdapterHelper
4
+ class Postgresql < Base
5
+ class << self
6
+ def load_connection_from_env
7
+ spec = super('postgresql')
8
+ spec[:database] ||= 'composite_primary_keys_unittest'
9
+ spec
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), 'base')
2
+
3
+ module AdapterHelper
4
+ class Sqlite3 < Base
5
+ class << self
6
+ def load_connection_from_env
7
+ spec = super('sqlite3')
8
+ spec[:dbfile] ||= "tmp/test.db"
9
+ spec
10
+ end
11
+ end
12
+ end
13
+ end