Giter VIP home page Giter VIP logo

ibm_db_bug's Introduction

ibm_db Foreign Key bug example

Bug

This app reproduces ibmdb/ruby-ibmdb#52, where invalid foreign key constraints are added to schema.rb after migrating.

Reproducing

  1. Clone this repository, which uses ibm_db-3.0.1 on rails-4.2.5.

  2. Create a config/database.yml configuration appropriate for your local setup. Include schema: IBM_DB_BUG in the database configuration for isolation and consistency with this example. Example:

    development:
      adapter: ibm_db
      host: "127.0.0.1"
      username: "user"
      password: "pass"
      database: "database"
      schema: IBM_DB_BUG
  3. Run migrations: rake db:migrate. In addition to running successfully, your schema.rb should have no significant changes.

  4. Manually create this valid foreign key constraint:

    ALTER TABLE "IBM_DB_BUG"."AUDIT_DETAILS"
            ADD CONSTRAINT "FK_AUDDTL_ID" FOREIGN KEY
                    ("AUDIT_ID")
            REFERENCES "IBM_DB_BUG"."AUDITS"
                    ("ID")
            ON DELETE CASCADE
            ON UPDATE RESTRICT
            ENFORCED
            ENABLE QUERY OPTIMIZATION;
  5. Run rake db:migrate again to update schema.rb.

Actual Behavior

schema.rb contains:

add_foreign_key "AUDIT_DETAILS", "AUDITS", column: "AUDIT_ID", primary_key: "ID", name: "FK_AUDDTL_ID", on_update: :cascade, on_delete: :restrict

Note that the actions in schema.rb are swapped from the actual constraint actions:

on_update: :cascade, on_delete: :restrict
ON DELETE CASCADE
ON UPDATE RESTRICT

Expected Behavior

The same line in schema.rb contains these actions

on_update: :restrict, on_delete: :cascade

Cleanup

Remove database artifacts introduced by this app:

DROP TABLE IBM_DB_BUG.AUDIT_DETAILS;
DROP TABLE IBM_DB_BUG.AUDITS;
CALL SYSPROC.ADMIN_DROP_SCHEMA('IBM_DB_BUG', NULL, 'ERRORSCHEMA', 'ERRORTABLE');
DROP TABLE ERRORSCHEMA.ERRORTABLE;

ibm_db_bug's People

Contributors

nilbus avatar

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.