schema_generator 0.1.0 → 0.2.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.
Files changed (2) hide show
  1. data/schema_generator.rb +76 -66
  2. metadata +2 -2
data/schema_generator.rb CHANGED
@@ -69,6 +69,10 @@ module ActiveRecord
69
69
 
70
70
  def dbmigrate_save
71
71
  end
72
+
73
+ def define_read_method(symbol, attr_name, column)
74
+ #nothing
75
+ end
72
76
 
73
77
  class << self
74
78
  alias_method :old_find, :find
@@ -81,7 +85,7 @@ module ActiveRecord
81
85
  def dbmigrate_create(attributes = nil)
82
86
  DBMigrator::Database.new_data(self,attributes)
83
87
  end
84
-
88
+
85
89
  end
86
90
  end
87
91
 
@@ -127,6 +131,7 @@ module ActiveRecord
127
131
  def self.remove_index(tablename,name)
128
132
  DBMigrator::Database.indexes.delete_if {|i| i.table == tablename and i.name == name}
129
133
  end
134
+
130
135
  end
131
136
  end
132
137
 
@@ -208,95 +213,100 @@ module DBMigrator
208
213
  end
209
214
 
210
215
  def self.dump(databasename)
211
- @@commandstring=''
212
- case databasename
213
- when 'postgresql'
214
- @@dbdriver = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.new(nil)
215
- when 'mysql'
216
- @@dbdriver = ActiveRecord::ConnectionAdapters::MysqlAdapter.new(nil,nil)
217
- when 'sqlite'
218
- @@dbdriver = ActiveRecord::ConnectionAdapters::SQLiteAdapter.new(nil)
219
- else
220
- raise 'Unknown driver'
221
- end
222
-
223
- class << @@dbdriver
224
- def execute(sql,name = nil)
225
- DBMigrator::Database.execute(sql,name)
216
+ begin
217
+ @@commandstring=''
218
+ case databasename
219
+ when 'postgresql'
220
+ @@dbdriver = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.new(nil)
221
+ when 'mysql'
222
+ @@dbdriver = ActiveRecord::ConnectionAdapters::MysqlAdapter.new(nil,nil)
223
+ when 'sqlite'
224
+ @@dbdriver = ActiveRecord::ConnectionAdapters::SQLiteAdapter.new(nil)
225
+ else
226
+ raise 'Unknown driver'
226
227
  end
227
228
 
228
- def columns(tablename,name = nil)
229
- table = DBMigrator::Database.tables.find {|t| t.name.to_s == tablename}
230
- table.fields.collect {|f| ActiveRecord::ConnectionAdapters::Column.new(f.name.to_s, nil, f.type)}
231
- end
229
+ class << @@dbdriver
230
+ def execute(sql,name = nil)
231
+ DBMigrator::Database.execute(sql,name)
232
+ end
232
233
 
233
- def insert(sql, name = nil, pk = nil, id_value = nil)
234
- execute(sql, name = nil)
235
- end
234
+ def columns(tablename,name = nil)
235
+ table = DBMigrator::Database.tables.find {|t| t.name.to_s == tablename}
236
+ table.fields.collect {|f| ActiveRecord::ConnectionAdapters::Column.new(f.name.to_s, nil, f.type)}
237
+ end
236
238
 
237
- def rollback_db_transaction; end
238
- def begin_db_transaction; end
239
- def commit_db_transaction; end
239
+ def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
240
+ execute(sql, name = nil)
241
+ end
242
+
243
+ def rollback_db_transaction; end
244
+ def begin_db_transaction; end
245
+ def commit_db_transaction; end
240
246
 
241
- # This is for the schema code, so we don't have security to worry about
242
- # This implementation might be attackable, but it won't generally fail
243
- # on reasonable strings.
244
- def quote_string(string)
245
- string.gsub(/\'/,"''")
247
+ # This is for the schema code, so we don't have security to worry about
248
+ # This implementation might be attackable, but it won't generally fail
249
+ # on reasonable strings.
250
+ def quote_string(string)
251
+ string.gsub(/\'/,"''")
252
+ end
246
253
  end
247
- end
248
254
 
249
- @@commandstring += "-- tables \n\n"
255
+ @@commandstring += "-- tables \n\n"
250
256
 
251
- tables.sort_by {|t| t.name.to_s}.each do |table|
252
- dbdriver.create_table table.name, table.options do |t|
253
- table.fields.each do |f|
254
- t.column f.name, f.type, f.options
257
+ tables.sort_by {|t| t.name.to_s}.each do |table|
258
+ dbdriver.create_table table.name, table.options do |t|
259
+ table.fields.each do |f|
260
+ t.column f.name, f.type, f.options
261
+ end
255
262
  end
256
263
  end
257
- end
258
264
 
259
- @@commandstring += "\n-- indexes \n\n" if indexes.size > 0
265
+ @@commandstring += "\n-- indexes \n\n" if indexes.size > 0
260
266
 
261
- indexes.sort_by {|t| t.table.to_s}.each do |index|
262
- dbdriver.add_index index.table, index.name.to_s
263
- end
267
+ indexes.sort_by {|t| t.table.to_s}.each do |index|
268
+ dbdriver.add_index index.table, index.name.to_s
269
+ end
264
270
 
265
- class << ActiveRecord::Base
266
- def retrieve_connection
267
- DBMigrator::Database.dbdriver
271
+ class << ActiveRecord::Base
272
+ def retrieve_connection
273
+ DBMigrator::Database.dbdriver
274
+ end
268
275
  end
269
- end
270
276
 
271
- enable_db
277
+ enable_db
272
278
 
273
- ActiveRecord::Base.class_eval do
274
- def attributes_from_column_definition
275
- tables = DBMigrator::Database.tables
276
- table = tables.find {|t| t.name.to_s == self.class.table_name}
277
- table.fields.inject({}) do |a,f|
278
- a[f.name.to_s]=nil
279
- a
279
+ ActiveRecord::Base.class_eval do
280
+ def attributes_from_column_definition
281
+ tables = DBMigrator::Database.tables
282
+ table = tables.find {|t| t.name.to_s == self.class.table_name}
283
+ table.fields.inject({}) do |a,f|
284
+ a[f.name.to_s]=nil
285
+ a
286
+ end
280
287
  end
281
288
  end
282
- end
283
289
 
284
- @@commandstring += "\n-- data \n\n" if @@data.size > 0
290
+ @@commandstring += "\n-- data \n\n" if @@data.size > 0
285
291
 
286
- @@data.each do |data|
287
- data.table.create(data.data)
288
- end
292
+ @@data.each do |data|
293
+ data.table.create(data.data)
294
+ end
289
295
 
290
- @@commandstring += "\n-- schema version meta-info \n\n"
296
+ @@commandstring += "\n-- schema version meta-info \n\n"
291
297
 
292
- dbdriver.create_table :schema_info, :id => false do |t|
293
- t.column :version, :integer
294
- end
298
+ dbdriver.create_table :schema_info, :id => false do |t|
299
+ t.column :version, :integer
300
+ end
295
301
 
296
- dbdriver.execute "insert into schema_info (version) values (#{version})"
302
+ dbdriver.execute "insert into schema_info (version) values (#{version})"
297
303
 
298
- disable_db
299
- @@commandstring
304
+ disable_db
305
+ @@commandstring
306
+ rescue => err
307
+ STDERR.puts "Error: #{err}"
308
+ STDERR.puts " #{err.backtrace.join("\n")}"
309
+ end
300
310
  end
301
311
 
302
312
  def self.reformat_create_table(sql)
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: 0.1.0
7
- date: 2005-09-02 00:00:00 -07:00
6
+ version: 0.2.0
7
+ date: 2005-10-24 00:00:00 -07: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."