legacy_data 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +49 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/examples/j2ee_petstore.sql +512 -0
- data/generators/models_from_tables/USAGE +6 -0
- data/generators/models_from_tables/models_from_tables_generator.rb +43 -0
- data/generators/models_from_tables/templates/model.rb +31 -0
- data/legacy_data.gemspec +69 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +61 -0
- data/lib/legacy_data/schema.rb +155 -0
- data/lib/legacy_data/table_class_name_mapper.rb +52 -0
- data/lib/legacy_data/table_definition.rb +41 -0
- data/lib/legacy_data.rb +4 -0
- data/spec/legacy_data/schema_spec.rb +179 -0
- data/spec/legacy_data/table_class_name_mapper_spec.rb +91 -0
- data/spec/legacy_data/table_definition_spec.rb +73 -0
- data/spec/spec_helper.rb +15 -0
- metadata +97 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Alex Rothenberg
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,49 @@
|
|
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_for_all
|
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.
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "legacy_data"
|
8
|
+
gem.summary = %Q{Create ActiveRecord models from an existing database}
|
9
|
+
gem.description = %Q{Create ActiveRecord models from an existing database}
|
10
|
+
gem.email = "alex@alexrothenberg.com"
|
11
|
+
gem.homepage = "http://github.com/alexrothenberg/legacy_data"
|
12
|
+
gem.authors = ["Alex Rothenberg"]
|
13
|
+
gem.add_development_dependency "rspec"
|
14
|
+
gem.add_dependency('activerecord')
|
15
|
+
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'spec/rake/spectask'
|
24
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
25
|
+
spec.libs << 'lib' << 'spec'
|
26
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
end
|
28
|
+
|
29
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
+
spec.rcov = true
|
33
|
+
spec.rcov_opts = ['--exclude spec,gems', '--sort coverage']
|
34
|
+
end
|
35
|
+
|
36
|
+
task :spec => :check_dependencies
|
37
|
+
|
38
|
+
task :default => :spec
|
39
|
+
|
40
|
+
require 'rake/rdoctask'
|
41
|
+
Rake::RDocTask.new do |rdoc|
|
42
|
+
if File.exist?('VERSION')
|
43
|
+
version = File.read('VERSION')
|
44
|
+
else
|
45
|
+
version = ""
|
46
|
+
end
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "legacy_data #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|