Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migration in rails turns varchar with 1 character to boolean

I have an oracle database. In the database there are no booleans. But after I migrated to rails, the VARCHARS with 1 character became boolean. How do I turn it to varchar again? Btw my database is oracle 10g and I'm using the latest version of ruby and rails.

 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 INTM_NO                                   NOT NULL NUMBER(12)
 INTM_NAME                                 NOT NULL VARCHAR2(240)
 CO_INTM_TYPE                              NOT NULL VARCHAR2(5)
 INTM_TYPE                                 NOT NULL VARCHAR2(2)
 TIN                                       NOT NULL VARCHAR2(20)
 CORP_TAG                                  NOT NULL VARCHAR2(1)
 SPECIAL_RATE                              NOT NULL VARCHAR2(1)
 LIC_TAG                                   NOT NULL VARCHAR2(1)
 MAIL_ADDR1                                NOT NULL VARCHAR2(50)
 MAIL_ADDR2                                         VARCHAR2(50)
 MAIL_ADDR3                                         VARCHAR2(50)
 BILL_ADDR1                                NOT NULL VARCHAR2(50)
 BILL_ADDR2                                         VARCHAR2(50)
 BILL_ADDR3                                         VARCHAR2(50)
 ISS_CD                                             VARCHAR2(2)
 PHONE_NO                                           VARCHAR2(40)
 BIRTHDATE                                          DATE
 CONTACT_PERS                                       VARCHAR2(50)
 DESIGNATION                                        VARCHAR2(5)
 PARENT_INTM_NO                                     NUMBER(12)
 CA_NO                                              VARCHAR2(15)
 LF_TAG                                             VARCHAR2(1)
 CO_INTM_NO                                         NUMBER(12)
 REF_INTM_CD                                        VARCHAR2(10)
 PAYT_TERMS                                         VARCHAR2(3)
 EFF_DATE                                           DATE
 EXPIRY_DATE                                        DATE
 USER_ID                                   NOT NULL VARCHAR2(8)
 LAST_UPDATE                               NOT NULL DATE
 REMARKS                                            VARCHAR2(4000)
 CPI_REC_NO                                         NUMBER(12)
 CPI_BRANCH_CD                                      VARCHAR2(2)
 WTAX_RATE                                          NUMBER(5,3)
 ACTIVE_TAG                                NOT NULL VARCHAR2(1)
 WHTAX_ID                                           NUMBER(5)
 INPUT_VAT_RATE                                     NUMBER(5,3)
 PRNT_INTM_TIN_SW                          NOT NULL VARCHAR2(1)
 OLD_INTM_NO                                        NUMBER(12)
 CA_DATE                                            DATE
 NICKNAME                                           VARCHAR2(40)
 CP_NO                                              VARCHAR2(40)
 EMAIL_ADD                                          VARCHAR2(50)
 FAX_NO                                             VARCHAR2(40)
 HOME_ADD                                           VARCHAR2(150)
 MASTER_INTM_NO                                     NUMBER(12)
 SUN_NO                                             VARCHAR2(40)
 SMART_NO                                           VARCHAR2(40)
 GLOBE_NO                                           VARCHAR2(40)
 PIN_CODE                                           VARCHAR2(6)

this is the table in the schema

create_table "giis_intermediary", comment: "Intermediary (agent) information", primary_key: "intm_no", force: :cascade do |t|
    t.string  "intm_name",        limit: 240,                           null: false
    t.string  "co_intm_type",     limit: 5,                             null: false
    t.string  "intm_type",        limit: 2,                             null: false
    t.string  "tin",              limit: 20,                            null: false
    t.boolean "corp_tag",                                               null: false
    t.boolean "special_rate",                                           null: false
    t.boolean "lic_tag",                                                null: false
    t.string  "mail_addr1",       limit: 50,                            null: false
    t.string  "mail_addr2",       limit: 50,                                         
    t.string  "mail_addr3",       limit: 50,                                        
    t.string  "bill_addr1",       limit: 50,                            null: false
    t.string  "bill_addr2",       limit: 50,                                        
    t.string  "bill_addr3",       limit: 50,                                         
    t.string  "iss_cd",           limit: 2,                                          
    t.string  "phone_no",         limit: 40,                                        
    t.date    "birthdate",                                                         
    t.string  "contact_pers",     limit: 50,                                        
    t.string  "designation",      limit: 5
    t.integer "parent_intm_no",   limit: 12,   precision: 12,                     
    t.string  "ca_no",            limit: 15
    t.boolean "lf_tag"
    t.integer "co_intm_no",       limit: 12,   precision: 12
    t.string  "ref_intm_cd",      limit: 10
    t.string  "payt_terms",       limit: 3
    t.date    "eff_date"
    t.date    "expiry_date"
    t.string  "user_id",          limit: 8,                             null: false
    t.date    "last_update",                                            null: false
    t.string  "remarks",          limit: 4000
    t.integer "cpi_rec_no",       limit: 12,   precision: 12
    t.string  "cpi_branch_cd",    limit: 2
    t.decimal "wtax_rate",                     precision: 5,  scale: 3
    t.boolean "active_tag",                                             null: false
    t.integer "whtax_id",         limit: 5,    precision: 5
    t.decimal "input_vat_rate",                precision: 5,  scale: 3
    t.boolean "prnt_intm_tin_sw",                                       null: false
    t.integer "old_intm_no",      limit: 12,   precision: 12
    t.date    "ca_date"
    t.string  "nickname",         limit: 40
    t.string  "cp_no",            limit: 40
    t.string  "email_add",        limit: 50
    t.string  "fax_no",           limit: 40
    t.string  "home_add",         limit: 150
    t.integer "master_intm_no",   limit: 12,   precision: 12
    t.string  "sun_no",           limit: 40
    t.string  "smart_no",         limit: 40
    t.string  "globe_no",         limit: 40
    t.string  "pin_code",         limit: 6
  end

update: I looked at the oracle enhanced adapter gem at github and found these

# if emulate_booleans_from_strings then store booleans in VARCHAR2
      NATIVE_DATABASE_TYPES_BOOLEAN_STRINGS = NATIVE_DATABASE_TYPES.dup.merge(
        boolean: { name: "VARCHAR2", limit: 1 }
      )

Oracle enhanced adapter has a default to change a varchar that have only 1 character to a boolean.

like image 835
Cj Monteclaro Avatar asked Nov 08 '22 02:11

Cj Monteclaro


1 Answers

The issue you are having is with the adapter.

As Oracle does not have a native boolean datatype, the activerecord-oracle_enhanced-adapter will, by default, attempt to convert certain values in specific fields to boolean. Fields ending _yn, for example, are automatically converted to boolean. Additionally, VARCHARS with a limit of one are treated as boolean.

You can fix this by changing the settings in config/initializers/oracle.rb:

ActiveSupport.on_load(:active_record) do
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do
   self.emulate_booleans_from_strings = false
  end
end
like image 157
Brian Avatar answered Nov 15 '22 05:11

Brian