Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation of Time#to_s(:db) #163

Open
ddoherty03 opened this issue Sep 30, 2023 · 1 comment
Open

Deprecation of Time#to_s(:db) #163

ddoherty03 opened this issue Sep 30, 2023 · 1 comment

Comments

@ddoherty03
Copy link

I am getting the following deprecation warning when using SeedDump.dump(MyClass, import: true):

DEPRECATION WARNING: Time#to_s(:db) is deprecated. Please use Time#to_fs(:db) instead.

It appears to stem from line 42 of dump_methods, which uses it for Date, DateTime, and Time values.

Any chance of a quick fix on this?

@khalilgharbaoui
Copy link

This is my quick fix if you are using rails:

  1. add an initilaizer:
config/initializers/seed_dump_fix_deprecation.rb
  1. paste this in there:
module SeedDumpFixDeprecation
  def value_to_s(value)
    value = case value
            when BigDecimal, IPAddr
              value.to_s
            when Date, Time, DateTime
              value.to_fs(:db)
            when Range
              range_to_string(value)
            when ->(v) { v.class.ancestors.map(&:to_s).include?('RGeo::Feature::Instance') }
              value.to_s
            else
              value
            end

    value.inspect
  end
end

SeedDump::DumpMethods.prepend SeedDumpFixDeprecation
  1. profit
  2. when fixed in gem remove the initializer and your good to go 😌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants