database-model-generator 0.6.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c7a39c7334cf104518e8ecab58a57ea7baa2b34c4a12048b45b0df7d2cf56368
4
+ data.tar.gz: 9bb0bd52e6de9ff30f54a609a5c96db968aac877cc00824ba789b3aa3c4eeff0
5
+ SHA512:
6
+ metadata.gz: 15c94ddcedc209de09dad9c27f2655a2d163e3df51bdb21051526cbbe60b0effa8569eeb5168de27f11845ddf4b39a68927b985619eac53196e154867bc26d30
7
+ data.tar.gz: 5fe097a00ba3151aa4ab21048b245ee26163e19e26daa2a05fd24131355bc296823d7e40a5040563797ae0722d9aa15505072bf1f1e611e555133d2295cb3668
checksums.yaml.gz.sig ADDED
@@ -0,0 +1,3 @@
1
+ t��®�A�H��s�:/��̸NM��"���_PR�V�U� ��|ށK�&�
2
+ ����6�u���rÍ��(nVA��L�����k����������Wة���qdP}(�����E�̚w�#$����W�Œ�����ˮVNݼ�� �������y��>�I��PN-�i��*Hͣ,�´��7ܜ�"��0�6�N#k���iKûN��ֆ��B"���y��g`6,��U����hҊ=��P�`��RD��ږ(�[�軩�
3
+ �݂4�-�y�+J$@j���*(l.Xg
data/CHANGES.md ADDED
@@ -0,0 +1,59 @@
1
+ ## 0.6.0 - 24-Jul-2025
2
+ * Renamed from oracle-model-generator to database-model-generator.
3
+ * Added enum support.
4
+ * Added polymorphic association support.
5
+
6
+ ## 0.5.0 - 22-Jul-2025
7
+ * Added docker related files, so you can now fire up an Oracle container and
8
+ run the specs against that.
9
+ * Replaced test-unit with rspec.
10
+ * Changed the license to Apache-2.0.
11
+
12
+ ## 0.4.1 - 1-Feb-2016
13
+ * This gem is now signed.
14
+ * Updated the gem related tasks in the Rakefile.
15
+ * Added an oracle-model-generator.rb file for convenience.
16
+
17
+ ## 0.4.0 - 7-Nov-2014
18
+ * Added support for minitest test file output.
19
+
20
+ ## 0.3.2 - 6-Nov-2014
21
+ * Removed explicit references to Rails 3 in documentation. It's now simply
22
+ Rails 2, or Rails 3 or higher.
23
+ * Some minor updates in generated test file text, as test-unit 2 no longer
24
+ requires the require workaround.
25
+ * Updates to Rakefile and gemspec.
26
+
27
+ ## 0.3.1 - 3-Apr-2012
28
+ * Added the --class option that allows you to specify the model name on the
29
+ command line. Thanks go to Daniel Luna for the patch (plus some minor fixes).
30
+
31
+ ## 0.3.0 - 12-May-2011
32
+ * Added automatic test generation. In addition to the active record model file,
33
+ a test file will be generated that includes a series of stock tests that
34
+ are based on the model's validations. At the moment only test-unit is
35
+ supported, but I'll eventually add rspec.
36
+ * Added the -x/--tests command line option for the new test generation feature.
37
+ * The dependencies method now returns an array of dependencies for the given
38
+ table or view.
39
+ * The table method has been altered. It now returns just the plain, uppercased
40
+ name of the table. A new method called 'model' now returns the active record
41
+ model name.
42
+ * The default output file name will now chop any trailing 's' characters.
43
+ * More tests and comments added.
44
+
45
+ ## 0.2.1 - 3-May-2011
46
+ * Fixed a bug where the omg binary blew up if you didn't have the dbi-dbrc
47
+ library installed. It's supposed to be optional. Thanks go to Jason Roth
48
+ for the spot.
49
+
50
+ ## 0.2.0 - 8-Mar-2011
51
+ * Added the -r/--rails command line option. By default the omg binary will
52
+ now generate Rails 3 style validations. If you want Rails 2 validations,
53
+ specify "-r 2" on the command line.
54
+ * The numericality validations are now more strict, and will match the
55
+ scale and precision exactly as defined instead of rounding to the nearest
56
+ whole number, for Rails 3 anyway.
57
+
58
+ ## 0.1.0 - 6-Oct-2010
59
+ * Initial release.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
data/MANIFEST.md ADDED
@@ -0,0 +1,10 @@
1
+ CHANGES.md
2
+ MANIFEST.md
3
+ README.md
4
+ oracle-model-generator.gemspec
5
+ Rakefile
6
+ bin/omg
7
+ certs/djberg96_pub.pem
8
+ lib/oracle-model-generator.rb
9
+ lib/oracle/model/generator.rb
10
+ test/test_oracle_model_generator.rb
data/README.md ADDED
@@ -0,0 +1,186 @@
1
+ ## Description
2
+ A library for generating an ActiveRecord model from an existing database table.
3
+
4
+ Currently supports both Oracle and SQL Server databases.
5
+
6
+ This will install a "dmg" (Database Model Generator) executable that you can
7
+ use from the command line.
8
+
9
+ ## Renamed
10
+ Originally called "oracle-model-generator" and put into the dust bin, I've
11
+ decided to revive this library with the help of AI. Specifically, I've added
12
+ SQLServer support, and plan to Postgres support.
13
+
14
+ I also plan on lots of improvements, and some general refactoring.
15
+
16
+ ## Synopsis
17
+ Using the command line tool:
18
+
19
+ ### Oracle:
20
+ `dmg -T oracle -d your_database -t locations -u some_user -p some_password`
21
+
22
+ ### SQL Server:
23
+ `dmg -T sqlserver -s localhost -d your_database -t locations -u sa -p your_password`
24
+
25
+ ### Auto-detection:
26
+ `dmg -d your_database -t locations -u some_user -p some_password` # Oracle (default)
27
+ `dmg -s localhost -d your_database -t locations -u sa -p password` # SQL Server (detected)
28
+
29
+ The above command results in a file called "location.rb". This is an
30
+ ActiveRecord model declaration, with all validations, primary keys,
31
+ table name and belongs_to relationships defined.
32
+
33
+ If your LOCATIONS table looks like this:
34
+
35
+ ```sql
36
+ create table locations(
37
+ location_id number(4,0) primary key,
38
+ street_address varchar2(40),
39
+ postal_code varchar2(12),
40
+ city varchar2(30) not null
41
+ state_province varchar2(25),
42
+ country_id CHAR(2),
43
+ constraint "LOC_C_ID_FK" FOREIGN KEY (country_id)
44
+ references COUNTRIES (country_id)
45
+ )
46
+ ```
47
+
48
+ The dmg library will generate this:
49
+
50
+ ```ruby
51
+ class Location < ActiveRecord::Base
52
+ set_table_name :locations
53
+ set_primary_key :location_id
54
+
55
+ # Table relationships
56
+
57
+ belongs_to :countries
58
+
59
+ # Validations
60
+
61
+ validates :location_id, :presence => true, :numericality => {
62
+ :less_than_or_equal_to => 9999,
63
+ :greater_than_or_equal_to => -9999,
64
+ :only_integer => true
65
+ }
66
+
67
+ validates :street_address, :length => {:maximum => 40}
68
+ validates :postal_code, :length => {:maximum => 12}
69
+ validates :city, :length => {:maximum => 30}, :presence => true
70
+ validates :state_province, :length => {:maximum => 25}
71
+ validates :country_id, :length => {:maximum => 2}
72
+ end
73
+ ```
74
+
75
+ It will also generate a corresponding test file using test-unit 2 by default.
76
+ For the above example you will see some tests like this:
77
+
78
+ ```ruby
79
+ class TC_Location < Test::Unit::TestCase
80
+ def setup
81
+ @location = Location.new
82
+ end
83
+
84
+ test 'table name is locations' do
85
+ assert_equal('locations', Location.table_name)
86
+ end
87
+
88
+ test 'primary key is location_id' do
89
+ assert_equal('location_id', Location.primary_key)
90
+ end
91
+
92
+ test 'location_id basic functionality' do
93
+ assert_respond_to(@location, :location_id)
94
+ assert_nothing_raised{ @location.location_id }
95
+ assert_kind_of(Numeric, @location.location_id)
96
+ end
97
+
98
+ test 'location_id must be a number' do
99
+ @location.location_id = 'test_string'
100
+ assert_false(@location.valid?)
101
+ assert_true(@location.errors[:location_id].include?('is not a number'))
102
+ end
103
+
104
+ test 'location_id cannot exceed the value 9999' do
105
+ @location.location_id = 10000
106
+ assert_false(@location.valid?)
107
+ assert_true(@location.errors[:location_id].include?('must be less than or equal to 9999'))
108
+ end
109
+
110
+ # ... and so on.
111
+ end
112
+ ```
113
+
114
+ ## Requirements
115
+ * getopt
116
+ * One of the following gems, depending on which vendor you're using.
117
+
118
+ ### Oracle
119
+ * ruby-oci8
120
+
121
+ ### SQLServer
122
+ * tiny_tds
123
+
124
+ ## Running the specs
125
+ ### Oracle:
126
+ Run `cd docker/oracle && docker-compose run --rm oracle-model-generator bundle exec rspec`.
127
+
128
+ You may need to use sudo. No guarantees on MacOS because of known issues
129
+ with database client libraries.
130
+
131
+ ### SQL Server:
132
+ Run `cd docker/sqlserver && ./test.sh` to start SQL Server, then run tests.
133
+
134
+ Again, no guarantees on MacOS.
135
+
136
+ ## Optional Libraries
137
+ If you want to be able to avoid specifying a username and password on the
138
+ command line then you will need the `dbi-dbrc` library.
139
+
140
+ If you want your models to support multiple primary keys, then you will
141
+ need to install the `composite_primary_keys` library.
142
+
143
+ If you want date format validations, then you will need to install the
144
+ `validates_timeliness` library.
145
+
146
+ ## Database Support
147
+ * **Oracle**: Full support via ruby-oci8
148
+ * **SQL Server**: Full support via tiny_tds
149
+ * **Auto-detection**: Automatically detects database type based on connection parameters
150
+
151
+ ## Author's Comments
152
+ Originally focused only on Oracle, this library has been expanded to support
153
+ SQL Server as well. The architecture now supports multiple database vendors,
154
+ and I will probably add Postgres support in the future.
155
+
156
+ ## Current Features
157
+ * **Multi-database support**: Oracle and SQL Server
158
+ * **Auto-detection**: Automatically detects database type
159
+ * **Index recommendations**: Suggests optimal indexes for your tables
160
+ * **Multiple test frameworks**: Supports test-unit, minitest, and rspec
161
+ * **Docker support**: Complete Docker environments for testing both databases
162
+
163
+ ## Future Plans (originally)
164
+ * Add support for views.
165
+
166
+ ## Acknowlegements
167
+ Thanks go to Daniel Luna for his --class patch.
168
+
169
+ ## Known Issues
170
+ None known. If you find any issues, please report them on the github project
171
+ page at http://www.github.com/djberg96/database-model-generator.
172
+
173
+ ## Warranty
174
+ This package is provided "as is" and without any express or
175
+ implied warranties, including, without limitation, the implied
176
+ warranties of merchantability and fitness for a particular purpose.
177
+
178
+ ## Copyright
179
+ (C) 2010-2025 Daniel J. Berger
180
+ All Rights Reserved
181
+
182
+ ## License
183
+ Apache-2.0
184
+
185
+ ## Author
186
+ Daniel J. Berger
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ require 'rake'
2
+ require 'rake/clean'
3
+ require 'rspec/core/rake_task'
4
+
5
+ CLEAN.include("**/*.gem", "**/*.rbc", "**/*.log", "**/*.lock")
6
+
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.pattern = 'spec/**/*_spec.rb'
9
+ t.rspec_opts = ['--format', 'documentation', '--color']
10
+ end
11
+
12
+ desc 'Run RSpec tests'
13
+ task :rspec => :spec
14
+
15
+ namespace 'gem' do
16
+ desc 'Create the database-model-generator gem'
17
+ task :create => :clean do
18
+ require 'rubygems/package'
19
+ spec = Gem::Specification.load('database-model-generator.gemspec')
20
+ spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
21
+ Gem::Package.build(spec)
22
+ end
23
+
24
+ desc 'Install the database-model-generator gem'
25
+ task :install => [:create] do
26
+ file = Dir["database-model-generator*.gem"].last
27
+ sh "gem install -l #{file}"
28
+ end
29
+ end
30
+
31
+ # Set default task to run both test suites
32
+ task :default => [:spec]