schema_generator 1.0.1 → 1.0.2
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/README +37 -11
- data/schema_generator.rb +10 -4
- data/templates/schema.oracle.sql +8 -0
- data/templates/schema.sqlserver.sql +8 -0
- metadata +4 -2
data/README
CHANGED
@@ -1,41 +1,67 @@
|
|
1
|
-
Schema Generator
|
1
|
+
Schema Generator v1.0.2
|
2
2
|
by Scott Laird, scott@sigkill.org
|
3
3
|
http://scottstuff.net
|
4
4
|
|
5
|
-
This is a SQL schema generator for Rails.
|
5
|
+
This is a SQL schema generator for Rails. It slurps up all of the migration
|
6
|
+
files in db/migrate and turns them into a single SQL schema file for each
|
7
|
+
supported database type. The schema files contains table definitions, indexes,
|
8
|
+
and any seed data created by Model.create() calls in the migrations.
|
6
9
|
|
7
10
|
Supported databases:
|
8
11
|
* MySQL
|
9
12
|
* PostgreSQL
|
10
13
|
* SQLite
|
14
|
+
* SQLServer
|
15
|
+
|
11
16
|
|
12
17
|
Usage
|
13
18
|
-----
|
14
19
|
|
15
|
-
To use, run './scripts/generate schema' on any Rails project.
|
20
|
+
To use, run './scripts/generate schema' on any Rails project. This will
|
21
|
+
produce five files:
|
16
22
|
|
17
23
|
* db/schema.mysql.sql
|
18
24
|
* db/schema.postgresql.sql
|
19
25
|
* db/schema.sqlite.sql
|
26
|
+
* db/schema.sqlserver.sql
|
27
|
+
* db/schema.rb
|
20
28
|
|
21
|
-
If these files already exist, then Rails will prompt you before overwriting
|
29
|
+
If these files already exist, then Rails will prompt you before overwriting
|
30
|
+
them.
|
22
31
|
|
23
|
-
If your Rails project already has migrations to build its entire schema from
|
32
|
+
If your Rails project already has migrations to build its entire schema from
|
33
|
+
scratch, then this will work right off the bat. If not, you may wish to create
|
34
|
+
a db/migrate/0_initial_schema.rb migration and use it to create your initial
|
35
|
+
schema using the usual migration create_table methods.
|
24
36
|
|
25
|
-
You can see an example in Typo (http://typo.leetsoft.com).
|
37
|
+
You can see an example in Typo (http://typo.leetsoft.com). This generator was
|
38
|
+
written to reduce the pain involved in creating new migrations for Typo,
|
39
|
+
because each migration required an equivalent change to 3 different
|
40
|
+
hand-edited static schema files, which was usually an error-prone process,
|
41
|
+
because no one user tests all three DB types. Now we can just use
|
42
|
+
'./script/generate schema' and be done with it.
|
26
43
|
|
27
44
|
|
28
45
|
Supported Migration Actions
|
29
46
|
---------------------------
|
30
47
|
|
31
|
-
This generator currently supports create_table, add_column, drop_column,
|
32
|
-
|
33
|
-
|
48
|
+
This generator currently supports create_table, add_column, drop_column,
|
49
|
+
change_column, rename_column, add_index, drop_index, and model .create and
|
50
|
+
.update_all calls. Any model find calls will immediately return an empty
|
51
|
+
array; this allows data migration blocks in migration files to be safely
|
52
|
+
ignored.
|
34
53
|
|
35
54
|
|
36
55
|
Debugging and Troubleshooting
|
37
56
|
-----------------------------
|
38
57
|
|
39
|
-
This generator reaches deep into the guts of Rails; it has to make several
|
58
|
+
This generator reaches deep into the guts of Rails; it has to make several
|
59
|
+
changes to the DB drivers and ActiveRecord::Base in order to work. This means
|
60
|
+
that it may have issues with future Rails releases. It has been tested with
|
61
|
+
1.0.0, and previous versions broke twice on different 1.0RC releases. All of
|
62
|
+
these changes are made on the fly using open classes, so installing this
|
63
|
+
generator will not break any outside code--the modifications are only active
|
64
|
+
while the generator is running.
|
40
65
|
|
41
|
-
If you have any other problems, please mail me at scott@sigkill.org or post a
|
66
|
+
If you have any other problems, please mail me at scott@sigkill.org or post a
|
67
|
+
comment on http://scottstuff.net/.
|
data/schema_generator.rb
CHANGED
@@ -39,7 +39,7 @@ class SchemaGenerator < Rails::Generator::Base
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def load_migration(migration_number)
|
42
|
-
globname = "db/migrate
|
42
|
+
globname = "db/migrate/{,0,00}#{migration_number}_*.rb"
|
43
43
|
file = Pathname.glob(globname).to_a.first.to_s
|
44
44
|
return nil unless file =~/\.rb$/
|
45
45
|
|
@@ -57,9 +57,11 @@ class SchemaGenerator < Rails::Generator::Base
|
|
57
57
|
record do |m|
|
58
58
|
m.directory File.join('db')
|
59
59
|
|
60
|
-
m.template 'schema.postgresql.sql', File.join('db', "schema.postgresql.sql")
|
61
60
|
m.template 'schema.mysql.sql', File.join('db', "schema.mysql.sql")
|
61
|
+
# m.template 'schema.oracle.sql', File.join('db', "schema.oracle.sql")
|
62
|
+
m.template 'schema.postgresql.sql', File.join('db', "schema.postgresql.sql")
|
62
63
|
m.template 'schema.sqlite.sql', File.join('db', "schema.sqlite.sql")
|
64
|
+
m.template 'schema.sqlserver.sql', File.join('db', "schema.sqlserver.sql")
|
63
65
|
m.template 'schema.rb', File.join('db', "schema.rb")
|
64
66
|
end
|
65
67
|
end
|
@@ -253,12 +255,16 @@ module DBMigrator
|
|
253
255
|
begin
|
254
256
|
@@commandstring=''
|
255
257
|
case databasename
|
256
|
-
when 'postgresql'
|
257
|
-
@@dbdriver = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.new(nil,nil)
|
258
258
|
when 'mysql'
|
259
259
|
@@dbdriver = ActiveRecord::ConnectionAdapters::MysqlAdapter.new(FakeMySQLConnection.new,nil,nil,{})
|
260
|
+
when 'oracle'
|
261
|
+
@@dbdriver = ActiveRecord::ConnectionAdapters::OCIAdapter.new(nil,nil)
|
262
|
+
when 'postgresql'
|
263
|
+
@@dbdriver = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.new(nil,nil)
|
260
264
|
when 'sqlite'
|
261
265
|
@@dbdriver = ActiveRecord::ConnectionAdapters::SQLiteAdapter.new(nil,nil)
|
266
|
+
when 'sqlserver'
|
267
|
+
@@dbdriver = ActiveRecord::ConnectionAdapters::SQLServerAdapter.new(nil,nil)
|
262
268
|
else
|
263
269
|
raise 'Unknown driver'
|
264
270
|
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
-- This file is autogenerated by the Rail schema generator, using
|
2
|
+
-- the schema defined in db/migration/*.rb
|
3
|
+
--
|
4
|
+
-- Do not edit this file. Instead, add a new migration using
|
5
|
+
-- ./script/generate migration <name>, and then run
|
6
|
+
-- ./script/generate schema
|
7
|
+
|
8
|
+
<%= DBMigrator::Database.dump('oracle') %>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
-- This file is autogenerated by the Rail schema generator, using
|
2
|
+
-- the schema defined in db/migration/*.rb
|
3
|
+
--
|
4
|
+
-- Do not edit this file. Instead, add a new migration using
|
5
|
+
-- ./script/generate migration <name>, and then run
|
6
|
+
-- ./script/generate schema
|
7
|
+
|
8
|
+
<%= DBMigrator::Database.dump('sqlserver') %>
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: schema_generator
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0.
|
7
|
-
date:
|
6
|
+
version: 1.0.2
|
7
|
+
date: 2006-01-05 00:00:00 -08:00
|
8
8
|
summary: "The rails schema generator generates complete SQL schemas from a collection of
|
9
9
|
rails migrations. It currently produces one schema file each for MySQL,
|
10
10
|
PostgreSQL, and SQLite."
|
@@ -32,9 +32,11 @@ authors:
|
|
32
32
|
- Scott Laird
|
33
33
|
files:
|
34
34
|
- templates/schema.mysql.sql
|
35
|
+
- templates/schema.oracle.sql
|
35
36
|
- templates/schema.postgresql.sql
|
36
37
|
- templates/schema.rb
|
37
38
|
- templates/schema.sqlite.sql
|
39
|
+
- templates/schema.sqlserver.sql
|
38
40
|
- schema_generator.rb
|
39
41
|
- README
|
40
42
|
test_files: []
|