GithubHelp home page GithubHelp logo

Handle id sequences with care about polo HOT 9 OPEN

ifttt avatar ifttt commented on May 20, 2024
Handle id sequences with care

from polo.

Comments (9)

bessey avatar bessey commented on May 20, 2024 1

Indeed, this is one of the parts of Brillo that would probably fit better in Polo. It doesn't seem like the API would be affected at all either, since you already have a notion of DB specific adapters in Polo.

Potentially we'd just need something like

https://github.com/IFTTT/polo/blob/master/lib/polo/sql_translator.rb#L23

    def to_sql
      case @configuration.on_duplicate_strategy
      when :ignore
        @adapter.ignore_transform(inserts, records)
      when :override
        @adapter.on_duplicate_key_update(inserts, records)
      else inserts
--    end
++    end + @adapter.table_footer(record.class.arel_table)
    end

from polo.

nettofarah avatar nettofarah commented on May 20, 2024

hey, @volkanunsal. Long time no PR 😂. We missed you!

This is an interesting idea.
Though I must say this is pretty PostgreSQL specific, so I'm not sure how it fits in the scope of Polo.

At the same time, I think this is something we could try to squeeze in the postgres adapter.
What do you think?

Wanna take a stab at it?

from polo.

volkanunsal avatar volkanunsal commented on May 20, 2024

@nettofarah Ha, ok, I'll give it a try.

from polo.

 avatar commented on May 20, 2024

This is a feature I would also find very useful

from polo.

nettofarah avatar nettofarah commented on May 20, 2024

Yeah, I was thinking about this today.
I think we could write a class for data ingestion.

We could add an import method to Polo that you could run in development/test.
That method could then delegate to some adapter specific classes.

What do you guys think?

from polo.

 avatar commented on May 20, 2024

Depends on if you want to bake this into the default Polo.explore for postgres or not. If we always want the 'ALTER SEQUENCE' statement in the end, then you can just modify the existing #ignore_transform so it tacks on the 'ALTER SEQUENCE' statement at the end.

I'm already doing something similar:

File.open('filename') do |f|
   f << Polo.explore(klass, ids).join(";\n")
   f << ";\nALTER SEQUENCE #{klass.table_name}_id_seq RESTART WITH #{ids.max+1};\n"
end

from polo.

bessey avatar bessey commented on May 20, 2024

You can see how we handle this in Brillo (a Polo wrapper with some extra conventions) here

from polo.

nettofarah avatar nettofarah commented on May 20, 2024

@bessey maybe we can join forces and try to bring this feature over to Polo?

from polo.

nettofarah avatar nettofarah commented on May 20, 2024

niice! I like that.
We could even be a little extra defensive and do something like:

if @adapter.respond_to?(:table_footer)
  ...
end

from polo.

Related Issues (20)

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.