Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## hackery for tables in the database that do not have standard auto-incrementing PK's or no PK at all
- def tables_with_no_auto_inc_pk_hackery(stream)
- tables_without_pk = {
- 'os_names' => [
- 'os_name',
- "\tt.string \"os_name\", :limit => 15, :null => false"
- ],
- 'os_families' => [
- 'os_family_name',
- "\tt.string \"os_family_name\", :limit => 31, :null => false"
- ]
- }
- fake_stream = StringIO.new
- tables_without_no_auto_inc_pk_hackery(fake_stream)
- fake_stream.rewind
- fake_stream.lines.each do |line|
- if ( line =~ /create_table "(\w*)".*do \|\w+\|/ )
- table_name = $1
- if(tables_without_pk.key? table_name)
- incorrect_pk = tables_without_pk[table_name][0]
- columns_to_inject = tables_without_pk[table_name][1]
- if(line.gsub!(/:primary_key => "#{incorrect_pk}"/,':id => false').nil?)
- raise "Table #{table_name} failed tables_without_no_auto_inc_pk_hackery. Could not match incorrect PK #{incorrect_pk}"
- end
- stream.puts(line)
- stream.puts(columns_to_inject)
- end
- end
- end
- stream
- end
- alias_method_chain :header, :details
- alias_method_chain :tables, :rvn_hackery
- alias_method_chain :tables, :no_auto_inc_pk_hackery
Add Comment
Please, Sign In to add comment