GithubHelp home page GithubHelp logo

dumpable's People

Contributors

hunterae avatar radomirz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dumpable's Issues

Association with belongs_to does not work

Summary

belongs_to asscociation does not work for me. I have redefined foreign_key.

Reproduce

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:

object.send("#{reflection.association_foreign_key}=", object.id + @id_padding)

Wrong Timestamp on Export

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")}'"

Use ActiveRecord::Base.connection.quote

def dump_value_string(value)

Can be replaced by ActiveRecord::Base.connection.quote?

keys = key_values.collect{ |item| "`#{item[0]}`" }.join(", ")

Can be replaced by
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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.