legacy_data 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/README.md +88 -0
  2. data/VERSION +1 -1
  3. data/examples/README +11 -0
  4. data/examples/generated/blog_mysql/comment.rb +1 -3
  5. data/examples/generated/blog_mysql/post.rb +1 -3
  6. data/examples/generated/blog_mysql/tag.rb +1 -3
  7. data/examples/generated/blog_sqlite3/comment.rb +1 -3
  8. data/examples/generated/blog_sqlite3/post.rb +1 -3
  9. data/examples/generated/blog_sqlite3/tag.rb +1 -3
  10. data/examples/generated/drupal_mysql/access.rb +1 -1
  11. data/examples/generated/drupal_mysql/action.rb +1 -2
  12. data/examples/generated/drupal_mysql/actions_aid.rb +1 -1
  13. data/examples/generated/drupal_mysql/authmap.rb +1 -1
  14. data/examples/generated/drupal_mysql/batch.rb +1 -1
  15. data/examples/generated/drupal_mysql/block.rb +1 -2
  16. data/examples/generated/drupal_mysql/blocks_role.rb +1 -2
  17. data/examples/generated/drupal_mysql/box.rb +1 -2
  18. data/examples/generated/drupal_mysql/cache.rb +1 -1
  19. data/examples/generated/drupal_mysql/cache_block.rb +1 -1
  20. data/examples/generated/drupal_mysql/cache_filter.rb +1 -1
  21. data/examples/generated/drupal_mysql/cache_form.rb +1 -1
  22. data/examples/generated/drupal_mysql/cache_menu.rb +1 -1
  23. data/examples/generated/drupal_mysql/cache_page.rb +1 -1
  24. data/examples/generated/drupal_mysql/cache_update.rb +1 -1
  25. data/examples/generated/drupal_mysql/comment.rb +1 -2
  26. data/examples/generated/drupal_mysql/filter.rb +1 -2
  27. data/examples/generated/drupal_mysql/filter_format.rb +1 -2
  28. data/examples/generated/drupal_mysql/flood.rb +1 -1
  29. data/examples/generated/drupal_mysql/history.rb +1 -1
  30. data/examples/generated/drupal_mysql/menu_custom.rb +1 -1
  31. data/examples/generated/drupal_mysql/menu_link.rb +1 -2
  32. data/examples/generated/drupal_mysql/menu_router.rb +1 -1
  33. data/examples/generated/drupal_mysql/node.rb +1 -1
  34. data/examples/generated/drupal_mysql/node_access.rb +1 -1
  35. data/examples/generated/drupal_mysql/node_comment_statistic.rb +1 -2
  36. data/examples/generated/drupal_mysql/node_counter.rb +1 -1
  37. data/examples/generated/drupal_mysql/node_revision.rb +1 -2
  38. data/examples/generated/drupal_mysql/node_type.rb +1 -1
  39. data/examples/generated/drupal_mysql/permission.rb +1 -1
  40. data/examples/generated/drupal_mysql/role.rb +1 -1
  41. data/examples/generated/drupal_mysql/session.rb +1 -2
  42. data/examples/generated/drupal_mysql/system.rb +1 -1
  43. data/examples/generated/drupal_mysql/term_data.rb +1 -1
  44. data/examples/generated/drupal_mysql/term_hierarchy.rb +1 -1
  45. data/examples/generated/drupal_mysql/term_node.rb +1 -1
  46. data/examples/generated/drupal_mysql/term_relation.rb +1 -1
  47. data/examples/generated/drupal_mysql/term_synonym.rb +1 -1
  48. data/examples/generated/drupal_mysql/uploaded_files.rb +1 -1
  49. data/examples/generated/drupal_mysql/url_alias.rb +1 -1
  50. data/examples/generated/drupal_mysql/user.rb +1 -2
  51. data/examples/generated/drupal_mysql/users_role.rb +1 -2
  52. data/examples/generated/drupal_mysql/variable.rb +1 -1
  53. data/examples/generated/drupal_mysql/vocabulary.rb +1 -1
  54. data/examples/generated/drupal_mysql/vocabulary_node_type.rb +1 -2
  55. data/examples/generated/drupal_mysql/watchdog.rb +1 -1
  56. data/examples/generated/j2ee_petstore_mysql/address.rb +1 -1
  57. data/examples/generated/j2ee_petstore_mysql/category.rb +1 -1
  58. data/examples/generated/j2ee_petstore_mysql/id_gen.rb +1 -1
  59. data/examples/generated/j2ee_petstore_mysql/item.rb +1 -1
  60. data/examples/generated/j2ee_petstore_mysql/product.rb +1 -1
  61. data/examples/generated/j2ee_petstore_mysql/seller_contact_info.rb +1 -1
  62. data/examples/generated/j2ee_petstore_mysql/tag.rb +1 -1
  63. data/examples/generated/j2ee_petstore_mysql/tag_item.rb +0 -1
  64. data/examples/generated/j2ee_petstore_mysql/ziplocation.rb +1 -1
  65. data/examples/generated/j2ee_petstore_oracle/address.rb +1 -1
  66. data/examples/generated/j2ee_petstore_oracle/category.rb +1 -1
  67. data/examples/generated/j2ee_petstore_oracle/id_gen.rb +1 -1
  68. data/examples/generated/j2ee_petstore_oracle/item.rb +1 -1
  69. data/examples/generated/j2ee_petstore_oracle/product.rb +1 -1
  70. data/examples/generated/j2ee_petstore_oracle/sellercontactinfo.rb +1 -1
  71. data/examples/generated/j2ee_petstore_oracle/tag.rb +1 -1
  72. data/examples/generated/j2ee_petstore_oracle/ziplocation.rb +1 -1
  73. data/examples/generated/j2ee_petstore_sqlite3/address.rb +1 -1
  74. data/examples/generated/j2ee_petstore_sqlite3/category.rb +1 -1
  75. data/examples/generated/j2ee_petstore_sqlite3/id_gen.rb +1 -1
  76. data/examples/generated/j2ee_petstore_sqlite3/item.rb +1 -1
  77. data/examples/generated/j2ee_petstore_sqlite3/product.rb +1 -1
  78. data/examples/generated/j2ee_petstore_sqlite3/seller_contact_info.rb +1 -1
  79. data/examples/generated/j2ee_petstore_sqlite3/tag.rb +1 -1
  80. data/examples/generated/j2ee_petstore_sqlite3/ziplocation.rb +1 -1
  81. data/generators/models_from_tables/templates/model.rb +3 -3
  82. data/legacy_data.gemspec +5 -4
  83. data/lib/legacy_data/table_class_name_mapper.rb +2 -1
  84. data/spec/expected/post.rb +1 -3
  85. metadata +5 -4
  86. data/README.rdoc +0 -49
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # Legacy Data
2
+
3
+ Getting started on a Rails project with a large existing database can be daunting. How to you extract all the information that's
4
+ encoded in the database? Do you have to understand the entire data model before you get started? The `models_from_tables` generator
5
+ in the `legacy_data` gem can help! This generator looks into your existing database and generates ActiveRecord models based on the
6
+ information encoded in it.
7
+
8
+
9
+ ## How to use it
10
+
11
+ - To generate an ActiveRecord model for each table in the database just type
12
+
13
+ `script/generate script/generate models_from_tables`
14
+
15
+ - If you don't want all tables in the database tell it which table to model
16
+
17
+ `script/generate script/generate models_from_tables --table-name comments`
18
+
19
+ This uses any foreign_key constraints in the database to spider the database and model the comments table and all associated tables.
20
+
21
+ - If you *really* only want the comments table tell it not to follow any foreign_keys
22
+
23
+ `script/generate script/generate models_from_tables --table-name comments --skip-associated`
24
+
25
+ - If you use [factory girl](http://github.com/thoughtbot/factory_girl) it will generate a simple factory for each model it generates
26
+
27
+ `script/generate script/generate models_from_tables --table-name comments --with-factories`
28
+
29
+ (You do need to install the plugin `gem install legacy_data` as long as http://gemcutter.org is one of your gem sources)
30
+
31
+ ### Examples
32
+
33
+ Several examples come with the gem source in the [examples](http://github.com/alexrothenberg/legacy_data/tree/master/examples/) folder. These include
34
+
35
+ - A simple blog database tested with MySQL and Sqlite3
36
+ - The Drupal 6.14 database tested with MySQL
37
+ - The J2EE Petstore example tested with MySQL, Sqlite3 and Oracle
38
+
39
+ ## What kind of information can it extract from the database?
40
+
41
+ ### Associations
42
+
43
+ If the database contains foreign_key constraints it uses them to build `has_many` or `belongs_to` associations
44
+ in your ActiveRecord models
45
+
46
+ ### Validation constraints
47
+
48
+ It will generate the following types of validation constraints in your models
49
+
50
+ - **validates_uniqueness_of** - For columns where the database has an index that enforces uniqueness
51
+ - **validates_presence_of** - When the database column is non-nullable
52
+ - **validates_inclusion_of** - For non-nullable boolean columns and custom constraints with a SQL rule "flag IN ('Y', 'N')"
53
+ - **validates_numericality_of** - For integer columns (nullable and non-nullable)
54
+ - **custom validation** - For custom SQL validation rules in the database it puts a placeholder in your model with the original SQL for you to translate into Ruby
55
+
56
+ ###Non-Rails naming conventions
57
+
58
+ Since the database is existing it's likely that it doesn't follow Rails naming conventions. Not to worry as the generator will
59
+ put the non-standard name into the generated models if it needs to.
60
+
61
+ What kinds of non-standard names can it generate?
62
+
63
+ Let's look at a sample output
64
+
65
+ <pre><code>
66
+ class Post < ActiveRecord::Base
67
+
68
+ set_table_name :tbpost
69
+ set_primary_key :postid
70
+
71
+ # Relationships
72
+ has_many :comments, :foreign_key => :postid
73
+
74
+ # Constraints
75
+ validates_presence_of :title, :body
76
+
77
+ end
78
+ </code></pre>
79
+
80
+ - **Class Names** - It named the model *Post* instead of the Rails convention *Tbpost*. The generator could not do this itself but knowing the conventions will often not apply to legacy databases it pauses after spidering the database giving you a chance to override the table to class name mapping. It generates a yaml file `app/models/table_mappings.yml` where you can verify or change any class name before proceeding to generate the models.
81
+ - **Table Names** - It overrode the table name since the actual name *tbpost* does not match the Rails naming convention *posts*
82
+ - **Primary Keys** - It overrode the primary key since the actual column *postid* does not match the Rails naming convention *id*
83
+ - **Foreign Keys** - It overrode the foreign key on the comment table to be *postid* instead of the Rails naming convention *id*
84
+
85
+
86
+ # Copyright
87
+
88
+ Copyright (c) 2009 Alex Rothenberg. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.9
1
+ 0.1.10
data/examples/README ADDED
@@ -0,0 +1,11 @@
1
+ This directory contains examples showing what the generator can do.
2
+ The generator is validated against these examples when its functional test suite is run.
3
+
4
+ There are 3 examples
5
+
6
+ * A simple blog database tested with MySQL and Sqlite3
7
+ * The Drupal 6.14 database tested with MySQL
8
+ * The J2EE Petstore example tested with MySQL, Sqlite3 and Oracle
9
+
10
+ They have been tested with MySQL, Sqlite3 and Oracle and the pregenerated output is available in the
11
+ generated directory with the example and database name part of the subdirectory name.
@@ -1,7 +1,5 @@
1
1
  class Comment < ActiveRecord::Base
2
-
3
-
4
-
2
+
5
3
  # Relationships
6
4
  belongs_to :post, :dependent => :destroy, :foreign_key => :post_id
7
5
 
@@ -1,7 +1,5 @@
1
1
  class Post < ActiveRecord::Base
2
-
3
-
4
-
2
+
5
3
  # Relationships
6
4
  has_and_belongs_to_many :tags, :association_foreign_key => :tag_id, :foreign_key => :post_id, :join_table => :post_tags
7
5
 
@@ -1,7 +1,5 @@
1
1
  class Tag < ActiveRecord::Base
2
-
3
-
4
-
2
+
5
3
  # Relationships
6
4
  has_and_belongs_to_many :posts, :association_foreign_key => :post_id, :foreign_key => :tag_id, :join_table => :post_tags
7
5
 
@@ -1,7 +1,5 @@
1
1
  class Comment < ActiveRecord::Base
2
-
3
-
4
-
2
+
5
3
  # Relationships
6
4
 
7
5
 
@@ -1,7 +1,5 @@
1
1
  class Post < ActiveRecord::Base
2
-
3
-
4
-
2
+
5
3
  # Relationships
6
4
 
7
5
 
@@ -1,7 +1,5 @@
1
1
  class Tag < ActiveRecord::Base
2
-
3
-
4
-
2
+
5
3
  # Relationships
6
4
 
7
5
 
@@ -1,7 +1,7 @@
1
1
  class Access < ActiveRecord::Base
2
2
  set_table_name :access
3
3
  set_primary_key :aid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,6 @@
1
1
  class Action < ActiveRecord::Base
2
-
3
2
  set_primary_key :aid
4
-
3
+
5
4
  # Relationships
6
5
 
7
6
 
@@ -1,7 +1,7 @@
1
1
  class ActionsAid < ActiveRecord::Base
2
2
  set_table_name :actions_aid
3
3
  set_primary_key :aid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Authmap < ActiveRecord::Base
2
2
  set_table_name :authmap
3
3
  set_primary_key :aid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Batch < ActiveRecord::Base
2
2
  set_table_name :batch
3
3
  set_primary_key :bid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,6 @@
1
1
  class Block < ActiveRecord::Base
2
-
3
2
  set_primary_key :bid
4
-
3
+
5
4
  # Relationships
6
5
 
7
6
 
@@ -1,7 +1,6 @@
1
1
  class BlocksRole < ActiveRecord::Base
2
-
3
2
  set_primary_key :no_primary_key
4
-
3
+
5
4
  # Relationships
6
5
 
7
6
 
@@ -1,7 +1,6 @@
1
1
  class Box < ActiveRecord::Base
2
-
3
2
  set_primary_key :bid
4
-
3
+
5
4
  # Relationships
6
5
 
7
6
 
@@ -1,7 +1,7 @@
1
1
  class Cache < ActiveRecord::Base
2
2
  set_table_name :cache
3
3
  set_primary_key :cid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class CacheBlock < ActiveRecord::Base
2
2
  set_table_name :cache_block
3
3
  set_primary_key :cid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class CacheFilter < ActiveRecord::Base
2
2
  set_table_name :cache_filter
3
3
  set_primary_key :cid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class CacheForm < ActiveRecord::Base
2
2
  set_table_name :cache_form
3
3
  set_primary_key :cid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class CacheMenu < ActiveRecord::Base
2
2
  set_table_name :cache_menu
3
3
  set_primary_key :cid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class CachePage < ActiveRecord::Base
2
2
  set_table_name :cache_page
3
3
  set_primary_key :cid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class CacheUpdate < ActiveRecord::Base
2
2
  set_table_name :cache_update
3
3
  set_primary_key :cid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,6 @@
1
1
  class Comment < ActiveRecord::Base
2
-
3
2
  set_primary_key :cid
4
-
3
+
5
4
  # Relationships
6
5
 
7
6
 
@@ -1,7 +1,6 @@
1
1
  class Filter < ActiveRecord::Base
2
-
3
2
  set_primary_key :fid
4
-
3
+
5
4
  # Relationships
6
5
 
7
6
 
@@ -1,7 +1,6 @@
1
1
  class FilterFormat < ActiveRecord::Base
2
-
3
2
  set_primary_key :format
4
-
3
+
5
4
  # Relationships
6
5
 
7
6
 
@@ -1,7 +1,7 @@
1
1
  class Flood < ActiveRecord::Base
2
2
  set_table_name :flood
3
3
  set_primary_key :fid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class History < ActiveRecord::Base
2
2
  set_table_name :history
3
3
  set_primary_key :no_primary_key
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class MenuCustom < ActiveRecord::Base
2
2
  set_table_name :menu_custom
3
3
  set_primary_key :menu_name
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,6 @@
1
1
  class MenuLink < ActiveRecord::Base
2
-
3
2
  set_primary_key :mlid
4
-
3
+
5
4
  # Relationships
6
5
 
7
6
 
@@ -1,7 +1,7 @@
1
1
  class MenuRouter < ActiveRecord::Base
2
2
  set_table_name :menu_router
3
3
  set_primary_key :path
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Node < ActiveRecord::Base
2
2
  set_table_name :node
3
3
  set_primary_key :nid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class NodeAccess < ActiveRecord::Base
2
2
  set_table_name :node_access
3
3
  set_primary_key :no_primary_key
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,6 @@
1
1
  class NodeCommentStatistic < ActiveRecord::Base
2
-
3
2
  set_primary_key :nid
4
-
3
+
5
4
  # Relationships
6
5
 
7
6
 
@@ -1,7 +1,7 @@
1
1
  class NodeCounter < ActiveRecord::Base
2
2
  set_table_name :node_counter
3
3
  set_primary_key :nid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,6 @@
1
1
  class NodeRevision < ActiveRecord::Base
2
-
3
2
  set_primary_key :vid
4
-
3
+
5
4
  # Relationships
6
5
 
7
6
 
@@ -1,7 +1,7 @@
1
1
  class NodeType < ActiveRecord::Base
2
2
  set_table_name :node_type
3
3
  set_primary_key :type
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Permission < ActiveRecord::Base
2
2
  set_table_name :permission
3
3
  set_primary_key :pid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Role < ActiveRecord::Base
2
2
  set_table_name :role
3
3
  set_primary_key :rid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,6 @@
1
1
  class Session < ActiveRecord::Base
2
-
3
2
  set_primary_key :sid
4
-
3
+
5
4
  # Relationships
6
5
 
7
6
 
@@ -1,7 +1,7 @@
1
1
  class System < ActiveRecord::Base
2
2
  set_table_name :system
3
3
  set_primary_key :filename
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class TermData < ActiveRecord::Base
2
2
  set_table_name :term_data
3
3
  set_primary_key :tid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class TermHierarchy < ActiveRecord::Base
2
2
  set_table_name :term_hierarchy
3
3
  set_primary_key :no_primary_key
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class TermNode < ActiveRecord::Base
2
2
  set_table_name :term_node
3
3
  set_primary_key :no_primary_key
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class TermRelation < ActiveRecord::Base
2
2
  set_table_name :term_relation
3
3
  set_primary_key :trid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class TermSynonym < ActiveRecord::Base
2
2
  set_table_name :term_synonym
3
3
  set_primary_key :tsid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class UploadedFiles < ActiveRecord::Base
2
2
  set_table_name :files
3
3
  set_primary_key :fid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class UrlAlias < ActiveRecord::Base
2
2
  set_table_name :url_alias
3
3
  set_primary_key :pid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,6 @@
1
1
  class User < ActiveRecord::Base
2
-
3
2
  set_primary_key :uid
4
-
3
+
5
4
  # Relationships
6
5
 
7
6
 
@@ -1,7 +1,6 @@
1
1
  class UsersRole < ActiveRecord::Base
2
-
3
2
  set_primary_key :no_primary_key
4
-
3
+
5
4
  # Relationships
6
5
 
7
6
 
@@ -1,7 +1,7 @@
1
1
  class Variable < ActiveRecord::Base
2
2
  set_table_name :variable
3
3
  set_primary_key :name
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Vocabulary < ActiveRecord::Base
2
2
  set_table_name :vocabulary
3
3
  set_primary_key :vid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,6 @@
1
1
  class VocabularyNodeType < ActiveRecord::Base
2
-
3
2
  set_primary_key :no_primary_key
4
-
3
+
5
4
  # Relationships
6
5
 
7
6
 
@@ -1,7 +1,7 @@
1
1
  class Watchdog < ActiveRecord::Base
2
2
  set_table_name :watchdog
3
3
  set_primary_key :wid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Address < ActiveRecord::Base
2
2
  set_table_name :address
3
3
  set_primary_key :addressid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Category < ActiveRecord::Base
2
2
  set_table_name :category
3
3
  set_primary_key :categoryid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class IdGen < ActiveRecord::Base
2
2
  set_table_name :id_gen
3
3
  set_primary_key :gen_key
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Item < ActiveRecord::Base
2
2
  set_table_name :item
3
3
  set_primary_key :itemid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Product < ActiveRecord::Base
2
2
  set_table_name :product
3
3
  set_primary_key :productid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class SellerContactInfo < ActiveRecord::Base
2
2
  set_table_name :sellercontactinfo
3
3
  set_primary_key :contactinfoid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Tag < ActiveRecord::Base
2
2
  set_table_name :tag
3
3
  set_primary_key :tagid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,6 @@
1
1
  class TagItem < ActiveRecord::Base
2
2
  set_table_name :tag_item
3
3
 
4
-
5
4
  # Relationships
6
5
 
7
6
 
@@ -1,7 +1,7 @@
1
1
  class Ziplocation < ActiveRecord::Base
2
2
  set_table_name :ziplocation
3
3
  set_primary_key :zipcode
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Address < ActiveRecord::Base
2
2
  set_table_name :address
3
3
  set_primary_key :addressid
4
-
4
+
5
5
  # Relationships
6
6
  has_many :items, :foreign_key => :address_addressid
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Category < ActiveRecord::Base
2
2
  set_table_name :category
3
3
  set_primary_key :categoryid
4
-
4
+
5
5
  # Relationships
6
6
  has_many :products, :foreign_key => :categoryid
7
7
 
@@ -1,7 +1,7 @@
1
1
  class IdGen < ActiveRecord::Base
2
2
  set_table_name :id_gen
3
3
  set_primary_key :gen_key
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Item < ActiveRecord::Base
2
2
  set_table_name :item
3
3
  set_primary_key :itemid
4
-
4
+
5
5
  # Relationships
6
6
  belongs_to :address, :foreign_key => :address_addressid
7
7
  belongs_to :product, :foreign_key => :productid
@@ -1,7 +1,7 @@
1
1
  class Product < ActiveRecord::Base
2
2
  set_table_name :product
3
3
  set_primary_key :productid
4
-
4
+
5
5
  # Relationships
6
6
  has_many :items, :foreign_key => :productid
7
7
  belongs_to :category, :foreign_key => :categoryid
@@ -1,7 +1,7 @@
1
1
  class Sellercontactinfo < ActiveRecord::Base
2
2
  set_table_name :sellercontactinfo
3
3
  set_primary_key :contactinfoid
4
-
4
+
5
5
  # Relationships
6
6
  has_many :items, :foreign_key => :contactinfo_contactinfoid
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Tag < ActiveRecord::Base
2
2
  set_table_name :tag
3
3
  set_primary_key :tagid
4
-
4
+
5
5
  # Relationships
6
6
  has_and_belongs_to_many :items, :association_foreign_key => :itemid, :foreign_key => :tagid, :join_table => :tag_item
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Ziplocation < ActiveRecord::Base
2
2
  set_table_name :ziplocation
3
3
  set_primary_key :zipcode
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Address < ActiveRecord::Base
2
2
  set_table_name :address
3
3
  set_primary_key :addressid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Category < ActiveRecord::Base
2
2
  set_table_name :category
3
3
  set_primary_key :categoryid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class IdGen < ActiveRecord::Base
2
2
  set_table_name :id_gen
3
3
  set_primary_key :gen_key
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Item < ActiveRecord::Base
2
2
  set_table_name :item
3
3
  set_primary_key :itemid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Product < ActiveRecord::Base
2
2
  set_table_name :product
3
3
  set_primary_key :productid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class SellerContactInfo < ActiveRecord::Base
2
2
  set_table_name :sellercontactinfo
3
3
  set_primary_key :contactinfoid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Tag < ActiveRecord::Base
2
2
  set_table_name :tag
3
3
  set_primary_key :tagid
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Ziplocation < ActiveRecord::Base
2
2
  set_table_name :ziplocation
3
3
  set_primary_key :zipcode
4
-
4
+
5
5
  # Relationships
6
6
 
7
7
 
@@ -1,7 +1,7 @@
1
1
  class <%= definition.class_name -%> < ActiveRecord::Base
2
- <%= "set_table_name #{definition.table_name.downcase.to_sym.inspect}" if definition.unconventional_table_name? %>
3
- <%= "set_primary_key #{definition.primary_key.to_sym.inspect}" if definition.unconventional_primary_key? %>
4
-
2
+ <%= " set_table_name #{definition.table_name.downcase.to_sym.inspect}\n" if definition.unconventional_table_name? -%>
3
+ <%= " set_primary_key #{definition.primary_key.to_sym.inspect}\n" if definition.unconventional_primary_key? -%>
4
+
5
5
  # Relationships
6
6
  <%= definition.relationships_to_s %>
7
7
 
data/legacy_data.gemspec CHANGED
@@ -5,24 +5,25 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{legacy_data}
8
- s.version = "0.1.9"
8
+ s.version = "0.1.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex Rothenberg"]
12
- s.date = %q{2009-10-21}
12
+ s.date = %q{2009-11-05}
13
13
  s.description = %q{Create ActiveRecord models from an existing database}
14
14
  s.email = %q{alex@alexrothenberg.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.md"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
21
  ".gitignore",
22
22
  "LICENSE",
23
- "README.rdoc",
23
+ "README.md",
24
24
  "Rakefile",
25
25
  "VERSION",
26
+ "examples/README",
26
27
  "examples/blog_migration.rb",
27
28
  "examples/create_j2ee_petstore.sql",
28
29
  "examples/delete_j2ee_petstore.sql",
@@ -34,7 +34,8 @@ module LegacyData
34
34
  save_dictionary
35
35
  self.class.log <<-MSG
36
36
  Done analyzing the tables.
37
- Please review the class names shown above. If any do not look correct (for example it did not separate the words with CamelCase) please supply the correct mappings by editing the file #{LegacyData::TableClassNameMapper.dictionary_file_name}.
37
+ Automatic class names written to '#{LegacyData::TableClassNameMapper.dictionary_file_name}'
38
+ Since the database probably does not follow Rails naming conventions you should take a look at the class names and update them in that file.
38
39
  Once you're done hit <enter> to continue generating the models"
39
40
  MSG
40
41
  gets
@@ -1,7 +1,5 @@
1
1
  class Post < ActiveRecord::Base
2
-
3
-
4
-
2
+
5
3
  # Relationships
6
4
  has_many :comments, :foreign_key => :comment_id
7
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legacy_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Rothenberg
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-21 00:00:00 -04:00
12
+ date: 2009-11-05 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -50,14 +50,15 @@ extensions: []
50
50
 
51
51
  extra_rdoc_files:
52
52
  - LICENSE
53
- - README.rdoc
53
+ - README.md
54
54
  files:
55
55
  - .document
56
56
  - .gitignore
57
57
  - LICENSE
58
- - README.rdoc
58
+ - README.md
59
59
  - Rakefile
60
60
  - VERSION
61
+ - examples/README
61
62
  - examples/blog_migration.rb
62
63
  - examples/create_j2ee_petstore.sql
63
64
  - examples/delete_j2ee_petstore.sql
data/README.rdoc DELETED
@@ -1,49 +0,0 @@
1
- = legacy_data
2
-
3
- How can you start a rails project on top of a large legacy database ... use the legacy_data plugin.
4
-
5
- What if the database doesn't follow Rails/ActiveRecord naming conventions? ... not a problem
6
- What if there are a lot of tables? ... not a problem
7
- What about all the information contained in the database already (relationships, constraints, etc) ... they are extracted into your models
8
-
9
- Usage: script/generate models_from_tables [options]
10
- table-name [ARG] Only generate models for tables starting with
11
- table-naming-convention [ARG]
12
- Naming convention for tables in the database. Only the wildcard is used when generating the model name
13
-
14
- Examples:
15
- * script/generate script/generate models_from_tables --table-naming-convention=tb*
16
- Generate a model for each table in the database. The tables all start with a tb (i.e. table 'tbperson' will generate the model 'person')
17
- * script/generate script/generate models_from_tables --table-name tbperson
18
- Generate a model for the 'tbperson' table in the database and all associated tables. has_many and belongs_to will be generated in the models
19
-
20
- == Usage
21
-
22
- * Create a new rails project with the admin data plugin
23
- rails my_application -m http://gist.github.com/188172.txt
24
- * Configure your application to connect to your existing Oracle database. Get the connect connect string from your dba (something like: user/password@server.example.com:1541/sid.world) and edit your config/database.yml
25
- development:
26
- adapter: oracle_enhanced
27
- database: my.oracle.server.com:1541/my_database.world
28
- username: user_name
29
- password: my_secret_password
30
- * Generate models for all existing tables
31
- script/generate models_from_tables
32
- * Take a look
33
- script/server
34
- http://localhost:3000/admin_data
35
-
36
- == Note on Patches/Pull Requests
37
-
38
- * Fork the project.
39
- * Make your feature addition or bug fix.
40
- * Add tests for it. This is important so I don't break it in a
41
- future version unintentionally.
42
- * Commit, do not mess with rakefile, version, or history.
43
- (if you want to have your own version, that is fine but
44
- bump version in a commit by itself I can ignore when I pull)
45
- * Send me a pull request. Bonus points for topic branches.
46
-
47
- == Copyright
48
-
49
- Copyright (c) 2009 Alex Rothenberg. See LICENSE for details.