hunterae / dumpable Goto Github PK
View Code? Open in Web Editor NEWLet Rails dump out your SQL
License: MIT License
Let Rails dump out your SQL
License: MIT License
dumpable/lib/dumpable/dumper.rb
Line 80 in cf9d475
ActiveRecord::Base.connection.quote
?
dumpable/lib/dumpable/dumper.rb
Line 73 in cf9d475
keys = key_values.collect{ |item| ActiveRecord::Base.connection.quote_column_name(item[0]) }.join(", ")
And what's rarely an issue but still, quote the table name: table_name = ActiveRecord::Base.connection.quote_table_name(object.class.table_name)
This also increases support for other databases.
belongs_to
asscociation does not work for me. I have redefined foreign_key
.
rails ~> 5.2
pg ~> 0.21.0
# app/models/example_category.rb
class ExampleCategory < ApplicationRecord
has_many :examples
end
# app/models/example.rb
class Example < ApplicationRecord
belongs_to :category, class_name: 'ExampleCategory', foreign_key: :example_category_id
end
Example.reflect_on_association(:category).association_foreign_key # => 'category_id'
Example.reflect_on_association(:category).foreign_key # => example_category_id
This callout breaks getting of association data:
dumpable/lib/dumpable/dumper.rb
Line 51 in cf9d475
I tested this with Ruby 2.4.3 and Rails 5.2.0.
When running dumpable with the following command:
Dumpable.dump(Model, Model, ..., :file => "#{Rails.root.join('db', 'dump.sql')}")
A Datetime column is exported as follows:
2018-05-15 16:54:54 UTC
However the " UTC" is not allowed when importing back into Mysql.
Please consider the following fix within Dumpable::Dumper
Line 81:
case value.class.to_s
when "Time"
"'#{value.strftime("%Y-%m-%d %H:%M:%S")}'"
when 'ActiveSupport::TimeWithZone'
"'#{value.strftime("%Y-%m-%d %H:%M:%S")}'"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.