Code Monkey home page Code Monkey logo

Comments (4)

ankane avatar ankane commented on June 25, 2024

Hey @volkanunsal, thanks for the proposal 👍 Can you add an example of a migration that should raise an error, and as well as one that does it properly?

from strong_migrations.

volkanunsal avatar volkanunsal commented on June 25, 2024

I don't quite know how to express the correct way of doing it. The way to alter a constraint requires knowing the name of the constraint, but that name is generated by Rails, and not easily accessible to the programmer.

Here is an attempt to show what I mean:

wrong

class AddReferenceToProject < ActiveRecord::Migration[5.1]
  def change
    add_foreign_key :users, :projects
  end
end

right

class AddReferenceToProject < ActiveRecord::Migration[5.1]
  def change
    # Naming our own foreign key. Is there a better way?
    add_foreign_key :users, :projects, name: 'foobar'
    execute("ALTER TABLE users ALTER CONSTRAINT foobar DEFERRABLE INITIALLY IMMEDIATE;")
  end
end

from strong_migrations.

ankane avatar ankane commented on June 25, 2024

Hey @volkanunsal, thanks for following up. I don't know if this practice is common, so don't think it makes sense to add right now. I'd like to add support for custom rules at some point, which could allow you to create your own warning around this.

from strong_migrations.

ankane avatar ankane commented on June 25, 2024

fwiw, just added a way to write custom checks

from strong_migrations.

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.