magic_model_generator 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +0 -0
- data/README +3 -0
- data/Rakefile +96 -0
- data/examples/singleview/account.rb +94 -0
- data/examples/singleview/account_history.rb +21 -0
- data/examples/singleview/account_reservation.rb +26 -0
- data/examples/singleview/account_type.rb +54 -0
- data/examples/singleview/account_type_aging.rb +17 -0
- data/examples/singleview/account_type_variable.rb +8 -0
- data/examples/singleview/address.rb +8 -0
- data/examples/singleview/address_format.rb +49 -0
- data/examples/singleview/address_history.rb +28 -0
- data/examples/singleview/adjustment.rb +97 -0
- data/examples/singleview/adjustment_batch.rb +42 -0
- data/examples/singleview/adjustment_invoice.rb +17 -0
- data/examples/singleview/adjustment_type.rb +54 -0
- data/examples/singleview/adjustment_type_variable.rb +8 -0
- data/examples/singleview/archive_lock_t.rb +11 -0
- data/examples/singleview/archive_result.rb +15 -0
- data/examples/singleview/archive_type.rb +31 -0
- data/examples/singleview/archive_type_table_list.rb +15 -0
- data/examples/singleview/atai_error_name.rb +7 -0
- data/examples/singleview/atlanta_form.rb +23 -0
- data/examples/singleview/atlanta_form_field.rb +12 -0
- data/examples/singleview/atlanta_group.rb +285 -0
- data/examples/singleview/atlanta_help_entry.rb +32 -0
- data/examples/singleview/atlanta_operator.rb +356 -0
- data/examples/singleview/atlanta_profile.rb +47 -0
- data/examples/singleview/atlanta_profile_func_map.rb +8 -0
- data/examples/singleview/atlanta_profile_group_map.rb +10 -0
- data/examples/singleview/atlanta_profile_role_map.rb +8 -0
- data/examples/singleview/atlanta_profile_wf_map.rb +10 -0
- data/examples/singleview/atlanta_role.rb +23 -0
- data/examples/singleview/atlanta_table_partition.rb +39 -0
- data/examples/singleview/attribute_type.rb +75 -0
- data/examples/singleview/attribute_type_variable.rb +8 -0
- data/examples/singleview/bill_run.rb +93 -0
- data/examples/singleview/bill_run_operation.rb +54 -0
- data/examples/singleview/bill_run_type.rb +39 -0
- data/examples/singleview/bill_run_type_status.rb +12 -0
- data/examples/singleview/bill_run_type_task.rb +12 -0
- data/examples/singleview/cache.rb +23 -0
- data/examples/singleview/cache_field.rb +13 -0
- data/examples/singleview/can_act_charge.rb +16 -0
- data/examples/singleview/charge.rb +67 -0
- data/examples/singleview/charge_category.rb +45 -0
- data/examples/singleview/charge_output_defn.rb +13 -0
- data/examples/singleview/charge_output_defn_history.rb +22 -0
- data/examples/singleview/charge_output_defn_var.rb +10 -0
- data/examples/singleview/configuration_attr_type.rb +22 -0
- data/examples/singleview/configuration_attribute.rb +11 -0
- data/examples/singleview/configuration_item.rb +26 -0
- data/examples/singleview/configuration_item_type.rb +29 -0
- data/examples/singleview/contract.rb +35 -0
- data/examples/singleview/contract_history.rb +48 -0
- data/examples/singleview/contract_type.rb +58 -0
- data/examples/singleview/contract_type_product.rb +11 -0
- data/examples/singleview/conversion_rate.rb +14 -0
- data/examples/singleview/currency.rb +118 -0
- data/examples/singleview/currency_history.rb +28 -0
- data/examples/singleview/customer_contact.rb +12 -0
- data/examples/singleview/customer_node.rb +166 -0
- data/examples/singleview/customer_node_bill_run.rb +12 -0
- data/examples/singleview/customer_node_charge_cat.rb +22 -0
- data/examples/singleview/customer_node_correspond.rb +12 -0
- data/examples/singleview/customer_node_da.rb +11 -0
- data/examples/singleview/customer_node_da_array.rb +35 -0
- data/examples/singleview/customer_node_history.rb +86 -0
- data/examples/singleview/customer_node_inv_format.rb +33 -0
- data/examples/singleview/customer_node_type.rb +89 -0
- data/examples/singleview/customer_node_type_cc.rb +18 -0
- data/examples/singleview/customer_node_type_da.rb +8 -0
- data/examples/singleview/customer_node_type_var.rb +8 -0
- data/examples/singleview/customer_query.rb +80 -0
- data/examples/singleview/customer_query_progress.rb +20 -0
- data/examples/singleview/customer_query_type.rb +49 -0
- data/examples/singleview/customer_query_type_var.rb +8 -0
- data/examples/singleview/delete_cascade.rb +13 -0
- data/examples/singleview/delete_cascade_group.rb +21 -0
- data/examples/singleview/delete_constraint.rb +9 -0
- data/examples/singleview/derived_attribute.rb +32 -0
- data/examples/singleview/derived_attribute_array.rb +32 -0
- data/examples/singleview/derived_attribute_history.rb +41 -0
- data/examples/singleview/derived_attribute_index.rb +13 -0
- data/examples/singleview/derived_attribute_value.rb +19 -0
- data/examples/singleview/dil.rb +18 -0
- data/examples/singleview/dil_history.rb +24 -0
- data/examples/singleview/dil_reference.rb +9 -0
- data/examples/singleview/dil_validation_t.rb +6 -0
- data/examples/singleview/dil_variable.rb +10 -0
- data/examples/singleview/dunning_t.rb +14 -0
- data/examples/singleview/entity_mapping.rb +11 -0
- data/examples/singleview/entity_remap.rb +22 -0
- data/examples/singleview/entity_validation.rb +70 -0
- data/examples/singleview/entity_validation_list.rb +15 -0
- data/examples/singleview/entity_validation_variable.rb +8 -0
- data/examples/singleview/equipment.rb +28 -0
- data/examples/singleview/equipment_history.rb +62 -0
- data/examples/singleview/equipment_type.rb +57 -0
- data/examples/singleview/equipment_type_variable.rb +8 -0
- data/examples/singleview/error_group.rb +18 -0
- data/examples/singleview/error_message.rb +65 -0
- data/examples/singleview/evs_address_equiv.rb +17 -0
- data/examples/singleview/evs_alias.rb +12 -0
- data/examples/singleview/evs_attribute_type_key.rb +7 -0
- data/examples/singleview/evt_equipment_changeover.rb +9 -0
- data/examples/singleview/expression_list.rb +27 -0
- data/examples/singleview/expression_list_value.rb +17 -0
- data/examples/singleview/fac_group_compatibility.rb +11 -0
- data/examples/singleview/fac_group_instance.rb +19 -0
- data/examples/singleview/fac_group_instance_hist.rb +16 -0
- data/examples/singleview/facility.rb +9 -0
- data/examples/singleview/facility_group.rb +21 -0
- data/examples/singleview/facility_group_history.rb +21 -0
- data/examples/singleview/foreign_key.rb +9 -0
- data/examples/singleview/function_defn.rb +16 -0
- data/examples/singleview/function_defn_history.rb +35 -0
- data/examples/singleview/function_role.rb +24 -0
- data/examples/singleview/function_role_map.rb +10 -0
- data/examples/singleview/gl_code.rb +65 -0
- data/examples/singleview/gl_code_history.rb +20 -0
- data/examples/singleview/gl_upload.rb +10 -0
- data/examples/singleview/icon.rb +64 -0
- data/examples/singleview/inv_loop_t.rb +4 -0
- data/examples/singleview/inv_report_accounts_t.rb +25 -0
- data/examples/singleview/invoice.rb +134 -0
- data/examples/singleview/invoice_contents.rb +14 -0
- data/examples/singleview/invoice_format.rb +31 -0
- data/examples/singleview/invoice_format_history.rb +29 -0
- data/examples/singleview/invoice_message.rb +17 -0
- data/examples/singleview/invoice_message_history.rb +31 -0
- data/examples/singleview/invoice_message_variable.rb +10 -0
- data/examples/singleview/invoice_receivable_type.rb +13 -0
- data/examples/singleview/invoice_type.rb +23 -0
- data/examples/singleview/invoice_type_history.rb +26 -0
- data/examples/singleview/invoice_type_variable.rb +10 -0
- data/examples/singleview/isp_email_address.rb +17 -0
- data/examples/singleview/licence_current_values.rb +12 -0
- data/examples/singleview/menu_role_map.rb +10 -0
- data/examples/singleview/normalised_event.rb +119 -0
- data/examples/singleview/normalised_event_error.rb +91 -0
- data/examples/singleview/normalised_event_file.rb +75 -0
- data/examples/singleview/normalised_event_ft.rb +18 -0
- data/examples/singleview/normalised_event_ft_hist.rb +25 -0
- data/examples/singleview/normalised_event_ft_var.rb +10 -0
- data/examples/singleview/normalised_event_type.rb +54 -0
- data/examples/singleview/output_device.rb +37 -0
- data/examples/singleview/output_method.rb +32 -0
- data/examples/singleview/output_method_type.rb +38 -0
- data/examples/singleview/output_select.rb +17 -0
- data/examples/singleview/payment.rb +102 -0
- data/examples/singleview/payment_batch.rb +43 -0
- data/examples/singleview/payment_invoice.rb +17 -0
- data/examples/singleview/payment_item.rb +15 -0
- data/examples/singleview/payment_type.rb +57 -0
- data/examples/singleview/payment_type_variable.rb +8 -0
- data/examples/singleview/person.rb +60 -0
- data/examples/singleview/person_history.rb +69 -0
- data/examples/singleview/person_type.rb +39 -0
- data/examples/singleview/plan_table.rb +27 -0
- data/examples/singleview/product.rb +45 -0
- data/examples/singleview/product_compatibility.rb +13 -0
- data/examples/singleview/product_derived_attribute.rb +10 -0
- data/examples/singleview/product_facility_group.rb +16 -0
- data/examples/singleview/product_group.rb +12 -0
- data/examples/singleview/product_group_history.rb +20 -0
- data/examples/singleview/product_history.rb +35 -0
- data/examples/singleview/product_in_product_group.rb +12 -0
- data/examples/singleview/product_instance.rb +41 -0
- data/examples/singleview/product_instance_equip.rb +21 -0
- data/examples/singleview/product_instance_history.rb +37 -0
- data/examples/singleview/product_instance_service.rb +17 -0
- data/examples/singleview/product_payment_item.rb +19 -0
- data/examples/singleview/product_service_type.rb +32 -0
- data/examples/singleview/product_service_type_equip.rb +20 -0
- data/examples/singleview/product_subtotal.rb +14 -0
- data/examples/singleview/product_tariff.rb +16 -0
- data/examples/singleview/racr_clec_t1.rb +12 -0
- data/examples/singleview/racr_clec_t2.rb +12 -0
- data/examples/singleview/racr_clec_t3.rb +28 -0
- data/examples/singleview/racr_t.rb +29 -0
- data/examples/singleview/ragd_clec_t.rb +47 -0
- data/examples/singleview/ragd_t.rb +28 -0
- data/examples/singleview/rapc_t.rb +27 -0
- data/examples/singleview/rdfd_cmn_t.rb +17 -0
- data/examples/singleview/rdfd_t.rb +16 -0
- data/examples/singleview/receivable_type.rb +49 -0
- data/examples/singleview/receivable_type_history.rb +25 -0
- data/examples/singleview/reference_code.rb +17 -0
- data/examples/singleview/reference_type.rb +32 -0
- data/examples/singleview/release_info.rb +10 -0
- data/examples/singleview/report_reference_type.rb +14 -0
- data/examples/singleview/report_reference_type_defs.rb +12 -0
- data/examples/singleview/reprocessed_file.rb +32 -0
- data/examples/singleview/rgp_file.rb +22 -0
- data/examples/singleview/rgp_normalised_event.rb +78 -0
- data/examples/singleview/rmag_t.rb +32 -0
- data/examples/singleview/rpmr_t.rb +27 -0
- data/examples/singleview/rpsi_t.rb +24 -0
- data/examples/singleview/rser_t.rb +13 -0
- data/examples/singleview/rshu_cmn_t.rb +31 -0
- data/examples/singleview/schedule.rb +91 -0
- data/examples/singleview/schedule_task_type.rb +43 -0
- data/examples/singleview/service.rb +88 -0
- data/examples/singleview/service_bill_run_t.rb +12 -0
- data/examples/singleview/service_charge_category.rb +22 -0
- data/examples/singleview/service_da.rb +11 -0
- data/examples/singleview/service_da_array.rb +35 -0
- data/examples/singleview/service_duplicate.rb +4 -0
- data/examples/singleview/service_history.rb +59 -0
- data/examples/singleview/service_type.rb +54 -0
- data/examples/singleview/service_type_cc.rb +18 -0
- data/examples/singleview/service_type_da.rb +8 -0
- data/examples/singleview/service_type_equip_type.rb +11 -0
- data/examples/singleview/subtotal.rb +48 -0
- data/examples/singleview/subtotal_history.rb +59 -0
- data/examples/singleview/subtotal_rating_delta.rb +20 -0
- data/examples/singleview/subtotal_rating_value.rb +21 -0
- data/examples/singleview/subtotal_term.rb +16 -0
- data/examples/singleview/subtotal_value.rb +18 -0
- data/examples/singleview/summary_of_change.rb +31 -0
- data/examples/singleview/summary_of_change_ev.rb +18 -0
- data/examples/singleview/summary_of_change_view.rb +22 -0
- data/examples/singleview/t2_anumber_france.rb +22 -0
- data/examples/singleview/t2_anumber_italy.rb +22 -0
- data/examples/singleview/t2_anumber_netherlands.rb +24 -0
- data/examples/singleview/t2_anumber_portugal.rb +22 -0
- data/examples/singleview/t2_anumber_spain.rb +22 -0
- data/examples/singleview/t2_anumber_switzerland.rb +24 -0
- data/examples/singleview/t2_bankreference_austria.rb +7 -0
- data/examples/singleview/t2_bankreference_belgium.rb +6 -0
- data/examples/singleview/t2_bankreference_france.rb +7 -0
- data/examples/singleview/t2_bankreference_germany.rb +7 -0
- data/examples/singleview/t2_bankreference_italy.rb +7 -0
- data/examples/singleview/t2_bankreference_portugal.rb +7 -0
- data/examples/singleview/t2_cc_provrequests.rb +19 -0
- data/examples/singleview/t2_emf_info.rb +12 -0
- data/examples/singleview/t2_ev_column_label_mapping.rb +9 -0
- data/examples/singleview/t2_historytable.rb +26 -0
- data/examples/singleview/t2_inv_revoked_invoice.rb +11 -0
- data/examples/singleview/t2_inv_suppress_invoice.rb +13 -0
- data/examples/singleview/t2_national_number_plan.rb +8 -0
- data/examples/singleview/t2_pay_statement.rb +28 -0
- data/examples/singleview/t2_prov_req_action.rb +22 -0
- data/examples/singleview/t2_prov_request.rb +32 -0
- data/examples/singleview/t2_rep_brr_t.rb +19 -0
- data/examples/singleview/t2_rep_trr_t.rb +19 -0
- data/examples/singleview/t2_rep_ubr_t.rb +19 -0
- data/examples/singleview/t2_taxclass.rb +8 -0
- data/examples/singleview/t2_zipcode_austria.rb +8 -0
- data/examples/singleview/t2_zipcode_france.rb +8 -0
- data/examples/singleview/t2_zipcode_germany.rb +8 -0
- data/examples/singleview/t2_zipcode_hungary.rb +8 -0
- data/examples/singleview/t2_zipcode_luxembourg.rb +8 -0
- data/examples/singleview/t2_zipcode_netherlands.rb +8 -0
- data/examples/singleview/t2_zipcode_portugal.rb +9 -0
- data/examples/singleview/t2_zipcode_spain.rb +8 -0
- data/examples/singleview/t2_zipcode_switzerland.rb +8 -0
- data/examples/singleview/table_import_order.rb +6 -0
- data/examples/singleview/tariff.rb +51 -0
- data/examples/singleview/tariff_charge.rb +33 -0
- data/examples/singleview/tariff_charge_defn.rb +18 -0
- data/examples/singleview/tariff_condition_defn.rb +19 -0
- data/examples/singleview/tariff_history.rb +70 -0
- data/examples/singleview/tariff_recurring.rb +36 -0
- data/examples/singleview/task_queue.rb +130 -0
- data/examples/singleview/task_queue_result.rb +10 -0
- data/examples/singleview/template.rb +18 -0
- data/examples/singleview/template_history.rb +30 -0
- data/examples/singleview/template_reference.rb +9 -0
- data/examples/singleview/template_variable.rb +10 -0
- data/examples/singleview/trt_clec_treatment.rb +13 -0
- data/examples/singleview/variable_defn.rb +48 -0
- data/examples/singleview/variable_defn_dependency.rb +11 -0
- data/examples/singleview/variable_defn_direct.rb +15 -0
- data/examples/singleview/variable_defn_history.rb +22 -0
- data/examples/singleview/work_force.rb +25 -0
- data/examples/singleview/xpsi_addr_val_commtax21.rb +24 -0
- data/examples/singleview/xpsi_addr_val_msag.rb +24 -0
- data/examples/singleview/xpsi_addr_val_zip.rb +14 -0
- data/examples/singleview/xpsi_ne_batch.rb +20 -0
- data/examples/singleview/xpsi_product_batch.rb +18 -0
- data/examples/singleview/xpsi_product_status.rb +14 -0
- data/examples/singleview/xpsi_tax_error.rb +34 -0
- data/examples/singleview/xpsi_trt_revoke.rb +68 -0
- data/examples/singleview/xpsi_trt_revoke_prod_inst.rb +12 -0
- data/examples/singleview/xpsi_update_capture.rb +35 -0
- data/lib/activerecord/base.rb +12 -0
- data/lib/hash_tricks.rb +21 -0
- data/lib/magic_model_generator.rb +8 -0
- data/lib/magic_model_generator/schema.rb +205 -0
- data/lib/magic_model_generator/validations.rb +48 -0
- data/lib/magic_model_generator/version.rb +9 -0
- data/lib/rails/generator/dynamic_named_base.rb +99 -0
- data/lib/rails/generator/manifest.rb +8 -0
- data/magic_model_generator.rb +88 -0
- data/templates/model.rb +3 -0
- data/test/magic_model_generator_test.rb +11 -0
- data/test/test_helper.rb +2 -0
- metadata +366 -0
@@ -0,0 +1,11 @@
|
|
1
|
+
class VariableDefnDependency < ActiveRecord::Base
|
2
|
+
belongs_to :variable_defn, :class_name => 'VariableDefn', :foreign_key => :variable_defn_id
|
3
|
+
validates_presence_of :variable_defn_id
|
4
|
+
validates_numericality_of :variable_defn_id, :allow_nil => false, :only_integer => true
|
5
|
+
validates_presence_of :effective_start_date
|
6
|
+
validates_presence_of :effective_end_date
|
7
|
+
validates_presence_of :dependent_variable_defn_id
|
8
|
+
validates_numericality_of :dependent_variable_defn_id, :allow_nil => false, :only_integer => true
|
9
|
+
validates_presence_of :dependency_count
|
10
|
+
validates_numericality_of :dependency_count, :allow_nil => false, :only_integer => true
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class VariableDefnDirect < ActiveRecord::Base
|
2
|
+
belongs_to :variable_defn, :class_name => 'VariableDefn', :foreign_key => :variable_defn_id
|
3
|
+
validates_presence_of :variable_defn_id
|
4
|
+
validates_numericality_of :variable_defn_id, :allow_nil => false, :only_integer => true
|
5
|
+
validates_presence_of :effective_start_date
|
6
|
+
validates_presence_of :effective_end_date
|
7
|
+
validates_presence_of :last_modified
|
8
|
+
validates_presence_of :view_name
|
9
|
+
validates_length_of :view_name, :allow_nil => false, :maximum => 30
|
10
|
+
validates_presence_of :column_name
|
11
|
+
validates_length_of :column_name, :allow_nil => false, :maximum => 30
|
12
|
+
validates_presence_of :column_nr
|
13
|
+
validates_numericality_of :column_nr, :allow_nil => false, :only_integer => true
|
14
|
+
validates_length_of :description, :allow_nil => true, :maximum => 255
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class VariableDefnHistory < ActiveRecord::Base
|
2
|
+
belongs_to :variable_defn, :class_name => 'VariableDefn', :foreign_key => :variable_defn_id
|
3
|
+
belongs_to :atlanta_operator, :class_name => 'AtlantaOperator', :foreign_key => :atlanta_operator_id
|
4
|
+
belongs_to :atlanta_group, :class_name => 'AtlantaGroup', :foreign_key => :atlanta_group_id
|
5
|
+
validates_presence_of :variable_defn_id
|
6
|
+
validates_numericality_of :variable_defn_id, :allow_nil => false, :only_integer => true
|
7
|
+
validates_presence_of :variable_defn_name
|
8
|
+
validates_length_of :variable_defn_name, :allow_nil => false, :maximum => 73
|
9
|
+
validates_presence_of :last_modified
|
10
|
+
validates_numericality_of :atlanta_operator_id, :allow_nil => true, :only_integer => true
|
11
|
+
validates_numericality_of :atlanta_group_id, :allow_nil => true, :only_integer => true
|
12
|
+
validates_presence_of :effective_start_date
|
13
|
+
validates_presence_of :effective_end_date
|
14
|
+
validates_presence_of :data_type_code
|
15
|
+
validates_numericality_of :data_type_code, :allow_nil => false, :only_integer => true
|
16
|
+
validates_presence_of :variable_type_code
|
17
|
+
validates_numericality_of :variable_type_code, :allow_nil => false, :only_integer => true
|
18
|
+
validates_presence_of :context_code
|
19
|
+
validates_numericality_of :context_code, :allow_nil => false, :only_integer => true
|
20
|
+
validates_presence_of :application_env_code
|
21
|
+
validates_numericality_of :application_env_code, :allow_nil => false, :only_integer => true
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class WorkForce < ActiveRecord::Base
|
2
|
+
belongs_to :work_force, :class_name => 'WorkForce', :foreign_key => :work_force_id
|
3
|
+
belongs_to :atlanta_operator, :class_name => 'AtlantaOperator', :foreign_key => :atlanta_operator_id
|
4
|
+
belongs_to :atlanta_group, :class_name => 'AtlantaGroup', :foreign_key => :atlanta_group_id
|
5
|
+
has_many :atlanta_profile_wf_maps, :class_name => 'AtlantaProfileWfMap', :foreign_key => :work_force_id
|
6
|
+
has_many :customer_query_progresses, :class_name => 'CustomerQueryProgress', :foreign_key => :work_force_id
|
7
|
+
has_many :work_forces, :class_name => 'WorkForce', :foreign_key => :work_force_id
|
8
|
+
has_many :atlanta_profiles, :through => atlanta_profile_wf_maps
|
9
|
+
has_many :customer_queries, :through => customer_query_progresses
|
10
|
+
has_many :atlanta_operators, :through => customer_query_progresses
|
11
|
+
has_many :atlanta_groups, :through => work_forces
|
12
|
+
has_many :atlanta_operators, :through => work_forces
|
13
|
+
validates_presence_of :work_force_id
|
14
|
+
validates_numericality_of :work_force_id, :allow_nil => false, :only_integer => true
|
15
|
+
validates_presence_of :work_force_name
|
16
|
+
validates_length_of :work_force_name, :allow_nil => false, :maximum => 30
|
17
|
+
validates_presence_of :description
|
18
|
+
validates_length_of :description, :allow_nil => false, :maximum => 255
|
19
|
+
validates_presence_of :last_modified
|
20
|
+
validates_presence_of :atlanta_operator_id
|
21
|
+
validates_numericality_of :atlanta_operator_id, :allow_nil => false, :only_integer => true
|
22
|
+
validates_presence_of :atlanta_group_id
|
23
|
+
validates_numericality_of :atlanta_group_id, :allow_nil => false, :only_integer => true
|
24
|
+
validates_length_of :version_str, :allow_nil => true, :maximum => 255
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class XpsiAddrValCommtax21 < ActiveRecord::Base
|
2
|
+
validates_presence_of :state_abbrev
|
3
|
+
validates_length_of :state_abbrev, :allow_nil => false, :maximum => 2
|
4
|
+
validates_presence_of :county_name_uppercase
|
5
|
+
validates_length_of :county_name_uppercase, :allow_nil => false, :maximum => 15
|
6
|
+
validates_presence_of :city_name_uppercase
|
7
|
+
validates_length_of :city_name_uppercase, :allow_nil => false, :maximum => 25
|
8
|
+
validates_presence_of :zip_begin
|
9
|
+
validates_length_of :zip_begin, :allow_nil => false, :maximum => 5
|
10
|
+
validates_presence_of :zip_end
|
11
|
+
validates_length_of :zip_end, :allow_nil => false, :maximum => 5
|
12
|
+
validates_presence_of :seqnr
|
13
|
+
validates_numericality_of :seqnr, :allow_nil => false, :only_integer => true
|
14
|
+
validates_presence_of :geocode
|
15
|
+
validates_length_of :geocode, :allow_nil => false, :maximum => 12
|
16
|
+
validates_presence_of :authority_code
|
17
|
+
validates_numericality_of :authority_code, :allow_nil => false, :only_integer => true
|
18
|
+
validates_presence_of :state_name
|
19
|
+
validates_length_of :state_name, :allow_nil => false, :maximum => 20
|
20
|
+
validates_presence_of :county_name
|
21
|
+
validates_length_of :county_name, :allow_nil => false, :maximum => 15
|
22
|
+
validates_presence_of :city_name
|
23
|
+
validates_length_of :city_name, :allow_nil => false, :maximum => 25
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class XpsiAddrValMsag < ActiveRecord::Base
|
2
|
+
validates_presence_of :street_name_uppercase
|
3
|
+
validates_length_of :street_name_uppercase, :allow_nil => false, :maximum => 48
|
4
|
+
validates_presence_of :community_name_uppercase
|
5
|
+
validates_length_of :community_name_uppercase, :allow_nil => false, :maximum => 32
|
6
|
+
validates_presence_of :state_abbrev
|
7
|
+
validates_length_of :state_abbrev, :allow_nil => false, :maximum => 2
|
8
|
+
validates_presence_of :low_number
|
9
|
+
validates_length_of :low_number, :allow_nil => false, :maximum => 8
|
10
|
+
validates_presence_of :high_number
|
11
|
+
validates_length_of :high_number, :allow_nil => false, :maximum => 8
|
12
|
+
validates_presence_of :seqnr
|
13
|
+
validates_numericality_of :seqnr, :allow_nil => false, :only_integer => true
|
14
|
+
validates_length_of :prefix_dir, :allow_nil => true, :maximum => 2
|
15
|
+
validates_length_of :postfix_dir, :allow_nil => true, :maximum => 2
|
16
|
+
validates_presence_of :street_name
|
17
|
+
validates_length_of :street_name, :allow_nil => false, :maximum => 48
|
18
|
+
validates_length_of :street_suffix, :allow_nil => true, :maximum => 8
|
19
|
+
validates_length_of :odd_even_ind, :allow_nil => true, :maximum => 1
|
20
|
+
validates_presence_of :community_name
|
21
|
+
validates_length_of :community_name, :allow_nil => false, :maximum => 32
|
22
|
+
validates_length_of :esn, :allow_nil => true, :maximum => 5
|
23
|
+
validates_length_of :exchange, :allow_nil => true, :maximum => 4
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class XpsiAddrValZip < ActiveRecord::Base
|
2
|
+
validates_presence_of :state_abbrev
|
3
|
+
validates_length_of :state_abbrev, :allow_nil => false, :maximum => 2
|
4
|
+
validates_presence_of :county_name_uppercase
|
5
|
+
validates_length_of :county_name_uppercase, :allow_nil => false, :maximum => 15
|
6
|
+
validates_presence_of :city_name_uppercase
|
7
|
+
validates_length_of :city_name_uppercase, :allow_nil => false, :maximum => 25
|
8
|
+
validates_presence_of :zip_begin
|
9
|
+
validates_length_of :zip_begin, :allow_nil => false, :maximum => 5
|
10
|
+
validates_presence_of :zip_end
|
11
|
+
validates_length_of :zip_end, :allow_nil => false, :maximum => 5
|
12
|
+
validates_presence_of :seqnr
|
13
|
+
validates_numericality_of :seqnr, :allow_nil => false, :only_integer => true
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class XpsiNeBatch < ActiveRecord::Base
|
2
|
+
belongs_to :xpsi_ne_batch, :class_name => 'XpsiNeBatch', :foreign_key => :xpsi_ne_batch_id
|
3
|
+
belongs_to :error_message, :class_name => 'ErrorMessage', :foreign_key => :error_message_id
|
4
|
+
has_many :xpsi_ne_batches, :class_name => 'XpsiNeBatch', :foreign_key => :xpsi_ne_batch_id
|
5
|
+
has_many :error_messages, :through => xpsi_ne_batches
|
6
|
+
validates_presence_of :xpsi_ne_batch_id
|
7
|
+
validates_numericality_of :xpsi_ne_batch_id, :allow_nil => false, :only_integer => true
|
8
|
+
validates_presence_of :source
|
9
|
+
validates_length_of :source, :allow_nil => false, :maximum => 80
|
10
|
+
validates_presence_of :create_date
|
11
|
+
validates_numericality_of :sequence_number, :allow_nil => true, :only_integer => true
|
12
|
+
validates_presence_of :ne_filename
|
13
|
+
validates_length_of :ne_filename, :allow_nil => false, :maximum => 255
|
14
|
+
validates_numericality_of :error_message_id, :allow_nil => true, :only_integer => true
|
15
|
+
validates_length_of :error_message, :allow_nil => true, :maximum => 255
|
16
|
+
validates_presence_of :revoke_ind_code
|
17
|
+
validates_numericality_of :revoke_ind_code, :allow_nil => false, :only_integer => true
|
18
|
+
validates_presence_of :event_count
|
19
|
+
validates_numericality_of :event_count, :allow_nil => false, :only_integer => true
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class XpsiProductBatch < ActiveRecord::Base
|
2
|
+
belongs_to :product_instance, :class_name => 'ProductInstance', :foreign_key => :product_instance_id
|
3
|
+
validates_presence_of :product_instance_id
|
4
|
+
validates_numericality_of :product_instance_id, :allow_nil => false, :only_integer => true
|
5
|
+
validates_presence_of :effective_date
|
6
|
+
validates_presence_of :entity_type
|
7
|
+
validates_length_of :entity_type, :allow_nil => false, :maximum => 255
|
8
|
+
validates_presence_of :entity_id
|
9
|
+
validates_numericality_of :entity_id, :allow_nil => false, :only_integer => true
|
10
|
+
validates_numericality_of :svcda_id, :allow_nil => true, :only_integer => true
|
11
|
+
validates_numericality_of :seq_nr, :allow_nil => true, :only_integer => true
|
12
|
+
validates_presence_of :entity_status
|
13
|
+
validates_numericality_of :entity_status, :allow_nil => false, :only_integer => true
|
14
|
+
validates_numericality_of :old_entity_status, :allow_nil => true, :only_integer => true
|
15
|
+
validates_presence_of :entity_action
|
16
|
+
validates_numericality_of :entity_action, :allow_nil => false, :only_integer => true
|
17
|
+
validates_length_of :addn_info, :allow_nil => true, :maximum => 1999
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class XpsiProductStatus < ActiveRecord::Base
|
2
|
+
belongs_to :product_instance, :class_name => 'ProductInstance', :foreign_key => :product_instance_id
|
3
|
+
validates_presence_of :product_instance_id
|
4
|
+
validates_numericality_of :product_instance_id, :allow_nil => false, :only_integer => true
|
5
|
+
validates_presence_of :effective_date
|
6
|
+
validates_presence_of :entity_type
|
7
|
+
validates_length_of :entity_type, :allow_nil => false, :maximum => 255
|
8
|
+
validates_presence_of :entity_id
|
9
|
+
validates_numericality_of :entity_id, :allow_nil => false, :only_integer => true
|
10
|
+
validates_numericality_of :svcda_id, :allow_nil => true, :only_integer => true
|
11
|
+
validates_numericality_of :seq_nr, :allow_nil => true, :only_integer => true
|
12
|
+
validates_presence_of :entity_status
|
13
|
+
validates_numericality_of :entity_status, :allow_nil => false, :only_integer => true
|
14
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class XpsiTaxError < ActiveRecord::Base
|
2
|
+
belongs_to :xpsi_tax_error, :class_name => 'XpsiTaxError', :foreign_key => :xpsi_tax_error_id
|
3
|
+
belongs_to :normalised_event, :class_name => 'NormalisedEvent', :foreign_key => :normalised_event_id
|
4
|
+
belongs_to :service, :class_name => 'Service', :foreign_key => :service_id
|
5
|
+
belongs_to :customer_node, :class_name => 'CustomerNode', :foreign_key => :customer_node_id
|
6
|
+
belongs_to :error_message, :class_name => 'ErrorMessage', :foreign_key => :error_message_id
|
7
|
+
belongs_to :adjustment, :class_name => 'Adjustment', :foreign_key => :adjustment_id
|
8
|
+
has_many :xpsi_tax_errors, :class_name => 'XpsiTaxError', :foreign_key => :xpsi_tax_error_id
|
9
|
+
has_many :customer_nodes, :through => xpsi_tax_errors
|
10
|
+
has_many :adjustments, :through => xpsi_tax_errors
|
11
|
+
has_many :error_messages, :through => xpsi_tax_errors
|
12
|
+
has_many :services, :through => xpsi_tax_errors
|
13
|
+
has_many :normalised_events, :through => xpsi_tax_errors
|
14
|
+
validates_presence_of :xpsi_tax_error_id
|
15
|
+
validates_numericality_of :xpsi_tax_error_id, :allow_nil => false, :only_integer => true
|
16
|
+
validates_presence_of :normalised_event_id
|
17
|
+
validates_numericality_of :normalised_event_id, :allow_nil => false, :only_integer => true
|
18
|
+
validates_numericality_of :service_id, :allow_nil => true, :only_integer => true
|
19
|
+
validates_numericality_of :customer_node_id, :allow_nil => true, :only_integer => true
|
20
|
+
validates_presence_of :tax_module_code
|
21
|
+
validates_numericality_of :tax_module_code, :allow_nil => false, :only_integer => true
|
22
|
+
validates_length_of :tax_module_return_value, :allow_nil => true, :maximum => 40
|
23
|
+
validates_numericality_of :tax_type_code, :allow_nil => true, :only_integer => true
|
24
|
+
validates_length_of :tax_key, :allow_nil => true, :maximum => 255
|
25
|
+
validates_numericality_of :amount, :allow_nil => true
|
26
|
+
validates_presence_of :adjust_ind
|
27
|
+
validates_numericality_of :adjust_ind, :allow_nil => false, :only_integer => true
|
28
|
+
validates_presence_of :error_message_id
|
29
|
+
validates_numericality_of :error_message_id, :allow_nil => false, :only_integer => true
|
30
|
+
validates_presence_of :error_message
|
31
|
+
validates_length_of :error_message, :allow_nil => false, :maximum => 255
|
32
|
+
validates_numericality_of :adjustment_id, :allow_nil => true, :only_integer => true
|
33
|
+
validates_presence_of :error_date
|
34
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
class XpsiTrtRevoke < ActiveRecord::Base
|
2
|
+
belongs_to :adjustment, :class_name => 'Adjustment', :foreign_key => :adjustment_id
|
3
|
+
validates_presence_of :task_id
|
4
|
+
validates_numericality_of :task_id, :allow_nil => false, :only_integer => true
|
5
|
+
validates_presence_of :effective_date
|
6
|
+
validates_presence_of :cq_customer_query_id
|
7
|
+
validates_numericality_of :cq_customer_query_id, :allow_nil => false, :only_integer => true
|
8
|
+
validates_presence_of :qp_progress_seqnr
|
9
|
+
validates_numericality_of :qp_progress_seqnr, :allow_nil => false, :only_integer => true
|
10
|
+
validates_length_of :revoke_function, :allow_nil => true, :maximum => 255
|
11
|
+
validates_numericality_of :letter_type, :allow_nil => true, :only_integer => true
|
12
|
+
validates_length_of :products_suspended, :allow_nil => true, :maximum => 255
|
13
|
+
validates_numericality_of :adjustment_id, :allow_nil => true, :only_integer => true
|
14
|
+
validates_length_of :general_1, :allow_nil => true, :maximum => 255
|
15
|
+
validates_length_of :general_2, :allow_nil => true, :maximum => 255
|
16
|
+
validates_length_of :general_3, :allow_nil => true, :maximum => 255
|
17
|
+
validates_length_of :general_4, :allow_nil => true, :maximum => 255
|
18
|
+
validates_length_of :general_5, :allow_nil => true, :maximum => 255
|
19
|
+
validates_length_of :general_6, :allow_nil => true, :maximum => 255
|
20
|
+
validates_length_of :general_7, :allow_nil => true, :maximum => 255
|
21
|
+
validates_length_of :general_8, :allow_nil => true, :maximum => 255
|
22
|
+
validates_length_of :general_9, :allow_nil => true, :maximum => 255
|
23
|
+
validates_length_of :general_10, :allow_nil => true, :maximum => 255
|
24
|
+
validates_presence_of :cq_last_modified
|
25
|
+
validates_numericality_of :cq_customer_node_id, :allow_nil => true, :only_integer => true
|
26
|
+
validates_presence_of :cq_atlanta_group_id
|
27
|
+
validates_numericality_of :cq_atlanta_group_id, :allow_nil => false, :only_integer => true
|
28
|
+
validates_presence_of :cq_atlanta_operator_id
|
29
|
+
validates_numericality_of :cq_atlanta_operator_id, :allow_nil => false, :only_integer => true
|
30
|
+
validates_presence_of :cq_query_status_code
|
31
|
+
validates_numericality_of :cq_query_status_code, :allow_nil => false, :only_integer => true
|
32
|
+
validates_numericality_of :cq_query_resolution_code, :allow_nil => true, :only_integer => true
|
33
|
+
validates_numericality_of :cq_query_work_force_id, :allow_nil => true, :only_integer => true
|
34
|
+
validates_numericality_of :cq_progress_seqnr, :allow_nil => true, :only_integer => true
|
35
|
+
validates_presence_of :cq_open_date
|
36
|
+
validates_presence_of :cq_response_due_date
|
37
|
+
validates_presence_of :cq_next_callback_date
|
38
|
+
validates_presence_of :cq_resolution_due_date
|
39
|
+
validates_length_of :cq_query_text, :allow_nil => true, :maximum => 2000
|
40
|
+
validates_length_of :cq_resolution_text, :allow_nil => true, :maximum => 2000
|
41
|
+
validates_length_of :cq_general_1, :allow_nil => true, :maximum => 255
|
42
|
+
validates_length_of :cq_general_2, :allow_nil => true, :maximum => 255
|
43
|
+
validates_length_of :cq_general_3, :allow_nil => true, :maximum => 255
|
44
|
+
validates_length_of :cq_general_4, :allow_nil => true, :maximum => 255
|
45
|
+
validates_length_of :cq_general_5, :allow_nil => true, :maximum => 255
|
46
|
+
validates_length_of :cq_general_6, :allow_nil => true, :maximum => 255
|
47
|
+
validates_length_of :cq_general_7, :allow_nil => true, :maximum => 255
|
48
|
+
validates_length_of :cq_general_8, :allow_nil => true, :maximum => 255
|
49
|
+
validates_length_of :cq_general_9, :allow_nil => true, :maximum => 255
|
50
|
+
validates_length_of :cq_general_10, :allow_nil => true, :maximum => 255
|
51
|
+
validates_presence_of :qp_last_modified
|
52
|
+
validates_numericality_of :qp_open_query_ind_code, :allow_nil => true, :only_integer => true
|
53
|
+
validates_presence_of :qp_work_force_id
|
54
|
+
validates_numericality_of :qp_work_force_id, :allow_nil => false, :only_integer => true
|
55
|
+
validates_presence_of :qp_open_date
|
56
|
+
validates_presence_of :qp_response_due_date
|
57
|
+
validates_length_of :qp_progress_text, :allow_nil => true, :maximum => 2000
|
58
|
+
validates_length_of :qp_action_text, :allow_nil => true, :maximum => 2000
|
59
|
+
validates_presence_of :qp_atlanta_operator_id
|
60
|
+
validates_numericality_of :qp_atlanta_operator_id, :allow_nil => false, :only_integer => true
|
61
|
+
validates_length_of :qp_resolution_text, :allow_nil => true, :maximum => 2000
|
62
|
+
validates_length_of :cda_index1_value, :allow_nil => true, :maximum => 255
|
63
|
+
validates_length_of :cda_result1_value, :allow_nil => true, :maximum => 255
|
64
|
+
validates_length_of :cda_result2_value, :allow_nil => true, :maximum => 255
|
65
|
+
validates_length_of :cda_result3_value, :allow_nil => true, :maximum => 255
|
66
|
+
validates_length_of :cda_result4_value, :allow_nil => true, :maximum => 255
|
67
|
+
validates_length_of :cda_result5_value, :allow_nil => true, :maximum => 255
|
68
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class XpsiTrtRevokeProdInst < ActiveRecord::Base
|
2
|
+
belongs_to :product_instance, :class_name => 'ProductInstance', :foreign_key => :product_instance_id
|
3
|
+
validates_presence_of :task_id
|
4
|
+
validates_numericality_of :task_id, :allow_nil => false, :only_integer => true
|
5
|
+
validates_presence_of :effective_date
|
6
|
+
validates_presence_of :cq_customer_query_id
|
7
|
+
validates_numericality_of :cq_customer_query_id, :allow_nil => false, :only_integer => true
|
8
|
+
validates_presence_of :qp_progress_seqnr
|
9
|
+
validates_numericality_of :qp_progress_seqnr, :allow_nil => false, :only_integer => true
|
10
|
+
validates_presence_of :product_instance_id
|
11
|
+
validates_numericality_of :product_instance_id, :allow_nil => false, :only_integer => true
|
12
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class XpsiUpdateCapture < ActiveRecord::Base
|
2
|
+
belongs_to :xpsi_update_capture, :class_name => 'XpsiUpdateCapture', :foreign_key => :xpsi_update_capture_id
|
3
|
+
belongs_to :task_queue, :class_name => 'TaskQueue', :foreign_key => :task_queue_id
|
4
|
+
has_many :xpsi_update_captures, :class_name => 'XpsiUpdateCapture', :foreign_key => :xpsi_update_capture_id
|
5
|
+
has_many :task_queues, :through => xpsi_update_captures
|
6
|
+
validates_presence_of :xpsi_update_capture_id
|
7
|
+
validates_numericality_of :xpsi_update_capture_id, :allow_nil => false, :only_integer => true
|
8
|
+
validates_presence_of :capture_type_code
|
9
|
+
validates_numericality_of :capture_type_code, :allow_nil => false, :only_integer => true
|
10
|
+
validates_presence_of :last_modified
|
11
|
+
validates_presence_of :effective_extract_date
|
12
|
+
validates_presence_of :seqnr
|
13
|
+
validates_numericality_of :seqnr, :allow_nil => false, :only_integer => true
|
14
|
+
validates_numericality_of :task_queue_id, :allow_nil => true, :only_integer => true
|
15
|
+
validates_length_of :general_1, :allow_nil => true, :maximum => 255
|
16
|
+
validates_length_of :general_2, :allow_nil => true, :maximum => 255
|
17
|
+
validates_length_of :general_3, :allow_nil => true, :maximum => 255
|
18
|
+
validates_length_of :general_4, :allow_nil => true, :maximum => 255
|
19
|
+
validates_length_of :general_5, :allow_nil => true, :maximum => 255
|
20
|
+
validates_length_of :general_6, :allow_nil => true, :maximum => 255
|
21
|
+
validates_length_of :general_7, :allow_nil => true, :maximum => 255
|
22
|
+
validates_length_of :general_8, :allow_nil => true, :maximum => 255
|
23
|
+
validates_length_of :general_9, :allow_nil => true, :maximum => 255
|
24
|
+
validates_length_of :general_10, :allow_nil => true, :maximum => 255
|
25
|
+
validates_length_of :general_11, :allow_nil => true, :maximum => 255
|
26
|
+
validates_length_of :general_12, :allow_nil => true, :maximum => 255
|
27
|
+
validates_length_of :general_13, :allow_nil => true, :maximum => 255
|
28
|
+
validates_length_of :general_14, :allow_nil => true, :maximum => 255
|
29
|
+
validates_length_of :general_15, :allow_nil => true, :maximum => 255
|
30
|
+
validates_length_of :general_16, :allow_nil => true, :maximum => 255
|
31
|
+
validates_length_of :general_17, :allow_nil => true, :maximum => 255
|
32
|
+
validates_length_of :general_18, :allow_nil => true, :maximum => 255
|
33
|
+
validates_length_of :general_19, :allow_nil => true, :maximum => 255
|
34
|
+
validates_length_of :general_20, :allow_nil => true, :maximum => 255
|
35
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#TODO: Use :dependent for FK cascade?
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
class Base
|
5
|
+
class << self
|
6
|
+
public
|
7
|
+
def get_unique_index_columns
|
8
|
+
self.connection.indexes(self.table_name, "#{self.name} Indexes").select { |index| index.unique && index.columns.size == 1 }.map{ |index| index.columns.first }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/hash_tricks.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
class Hash
|
2
|
+
# lets through the keys in the argument
|
3
|
+
# >> {:one => 1, :two => 2, :three => 3}.pass(:one)
|
4
|
+
# => {:one=>1}
|
5
|
+
def pass(*keys)
|
6
|
+
tmp = self.clone
|
7
|
+
keys = keys[0] if keys[0].is_a? Array
|
8
|
+
tmp.delete_if {|k,v| ! keys.include?(k) }
|
9
|
+
tmp
|
10
|
+
end
|
11
|
+
|
12
|
+
def merge_with_prefix(prefix, hash)
|
13
|
+
merged = clone
|
14
|
+
hash.each {|key, value| merged.merge!("#{prefix}_#{key}" => value)}
|
15
|
+
merged
|
16
|
+
end
|
17
|
+
|
18
|
+
def merge_with_prefix!(prefix, hash)
|
19
|
+
hash.each {|key, value| merge!("#{prefix}_#{key}" => value)}
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,205 @@
|
|
1
|
+
require 'pp'
|
2
|
+
module MagicModelsGenerator
|
3
|
+
|
4
|
+
class Schema
|
5
|
+
class << self
|
6
|
+
cattr_accessor :superklass,
|
7
|
+
:belongs_to_associations,
|
8
|
+
:has_some_associations,
|
9
|
+
:has_many_through_associations
|
10
|
+
|
11
|
+
@@models = nil
|
12
|
+
|
13
|
+
def logger
|
14
|
+
@@logger ||= MagicModelsGenerator.logger
|
15
|
+
end
|
16
|
+
|
17
|
+
def models
|
18
|
+
load_schema if @@models.nil?
|
19
|
+
@@models
|
20
|
+
end
|
21
|
+
|
22
|
+
def tables
|
23
|
+
load_schema if @@tables.nil?
|
24
|
+
@@tables
|
25
|
+
end
|
26
|
+
|
27
|
+
def table_names
|
28
|
+
load_schema if @@table_names.nil?
|
29
|
+
@@table_names
|
30
|
+
end
|
31
|
+
|
32
|
+
def fks_on_table(table_name)
|
33
|
+
load_schema if @@models.nil?
|
34
|
+
@@fks_by_table[table_name.to_s] || []
|
35
|
+
end
|
36
|
+
|
37
|
+
# active record only support 2 column link tables, otherwise use a model table, has_many and through
|
38
|
+
def is_link_table?(table_name)
|
39
|
+
load_schema if @@models.nil?
|
40
|
+
return @@link_tables[table_name] if ! @@link_tables[table_name].nil?
|
41
|
+
column_names = @conn.columns(table_name).map{|x| x.name }
|
42
|
+
@@link_tables[table_name] = ! column_names.include?("id") && column_names.length == 2 && column_names.select { |x| x =~ /_id$/ } == column_names
|
43
|
+
return @@link_tables[table_name]
|
44
|
+
end
|
45
|
+
|
46
|
+
def link_tables_for_class(klass)
|
47
|
+
load_schema if @@models.nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
def load_schema
|
51
|
+
return if ! @@models.nil?
|
52
|
+
@@superklass ||= ActiveRecord::Base
|
53
|
+
raise "No database connection" if !(@conn = @@superklass.connection)
|
54
|
+
|
55
|
+
@@models = ModelHash.new
|
56
|
+
@@tables = Hash.new
|
57
|
+
@@fks_by_table = Hash.new
|
58
|
+
@@link_tables = Hash.new
|
59
|
+
@@belongs_to_associations = Hash.new
|
60
|
+
@@has_some_associations = Hash.new
|
61
|
+
@@has_many_through_associations = Hash.new
|
62
|
+
|
63
|
+
@@table_names = @conn.tables.sort
|
64
|
+
|
65
|
+
# Work out which tables are in the model and which aren't
|
66
|
+
@@table_names.each do |table_name|
|
67
|
+
|
68
|
+
# a model table then...
|
69
|
+
model_class_name = ActiveRecord::Base.class_name(table_name)
|
70
|
+
logger.debug "Got a model table: #{table_name} => class #{model_class_name}"
|
71
|
+
|
72
|
+
@@models[model_class_name] = table_name
|
73
|
+
@@tables[table_name] = model_class_name
|
74
|
+
|
75
|
+
# Process FKs?
|
76
|
+
if @conn.supports_fetch_foreign_keys?
|
77
|
+
table_names.each do |table_name|
|
78
|
+
logger.debug "Getting FKs for #{table_name}"
|
79
|
+
@@fks_by_table[table_name] = Array.new
|
80
|
+
@conn.foreign_key_constraints(table_name).each do |fk|
|
81
|
+
logger.debug "Got one: #{fk}"
|
82
|
+
@@fks_by_table[table_name].push(fk)
|
83
|
+
end # do each fk
|
84
|
+
end # each table
|
85
|
+
end
|
86
|
+
|
87
|
+
# Try to work out our link tables now...
|
88
|
+
#@@models.keys.sort.each{|klass| process_table(@@models[klass.to_s])}
|
89
|
+
#@@link_tables.keys.sort.each{|table_name| process_link_table(table_name) if @@link_tables[table_name]}
|
90
|
+
end
|
91
|
+
|
92
|
+
models.each do |model_name, table_name|
|
93
|
+
@@belongs_to_associations[model_name] = []
|
94
|
+
@@has_some_associations[model_name] = []
|
95
|
+
@@has_many_through_associations[model_name] = []
|
96
|
+
end
|
97
|
+
|
98
|
+
logger.debug "Loaded all models, now generating associations..."
|
99
|
+
|
100
|
+
models.keys.sort.each do |model_name|
|
101
|
+
puts "Generating for #{model_name}..."
|
102
|
+
table_name = models[model_name]
|
103
|
+
generate_associations(model_name, table_name)
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
# Used by the generator to access the association code lines for the generated class
|
109
|
+
def associations(klass)
|
110
|
+
@@belongs_to_associations[klass.to_s] +
|
111
|
+
@@has_some_associations[klass.to_s] +
|
112
|
+
@@has_many_through_associations[klass.to_s]
|
113
|
+
end
|
114
|
+
|
115
|
+
protected
|
116
|
+
def generate_associations(model_name, table_name)
|
117
|
+
belongs_to_klass = model_name.constantize rescue return
|
118
|
+
logger.debug "Processing model table #{table_name}"
|
119
|
+
|
120
|
+
processed_columns = Hash.new
|
121
|
+
|
122
|
+
# ok, so let's look at the foreign keys on the table...
|
123
|
+
|
124
|
+
fks_on_table(table_name).each do |fk|
|
125
|
+
logger.debug "Found FK column by suffix _id [#{fk.foreign_key}]"
|
126
|
+
has_some_klass = Inflector.classify(fk.reference_table).constantize rescue next
|
127
|
+
processed_columns[fk.foreign_key] = { :has_some_klass => has_some_klass }
|
128
|
+
processed_columns[fk.foreign_key].merge! add_has_some_belongs_to(belongs_to_klass, fk.foreign_key, has_some_klass) rescue next
|
129
|
+
end
|
130
|
+
|
131
|
+
column_names = @conn.columns(table_name).map{ |x| x.name}
|
132
|
+
column_names.each do |column_name|
|
133
|
+
next if not column_name =~ /_id$/
|
134
|
+
logger.debug "Found FK column by suffix _id [#{column_name}]"
|
135
|
+
if processed_columns.key?(column_name)
|
136
|
+
logger.debug "Skipping, already processed"
|
137
|
+
next
|
138
|
+
end
|
139
|
+
has_some_klass = Inflector.classify(column_name.sub(/_id$/,"")).constantize rescue next
|
140
|
+
processed_columns[column_name] = { :has_some_klass => has_some_klass }
|
141
|
+
begin
|
142
|
+
processed_columns[column_name].merge! add_has_some_belongs_to(belongs_to_klass, column_name, has_some_klass)
|
143
|
+
rescue
|
144
|
+
puts $!
|
145
|
+
next
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
# is this a link table with attributes? (has_many through?)
|
150
|
+
return if processed_columns.keys.length < 2
|
151
|
+
|
152
|
+
processed_columns.keys.each do |key1|
|
153
|
+
processed_columns.keys.each do |key2|
|
154
|
+
next if key1 == key2
|
155
|
+
has_some_class = processed_columns[key1][:has_some_class].to_s
|
156
|
+
@@has_many_through_associations[has_some_class] <<
|
157
|
+
"has_many :#{processed_columns[key2][:belongs_to_name].to_s.pluralize.to_sym}, :through => :#{processed_columns[key2][:has_some_name]}"
|
158
|
+
logger.debug @@has_many_through_associations[has_some_class].last
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def add_has_some_belongs_to(belongs_to_klass, belongs_to_fk, has_some_klass)
|
164
|
+
logger.debug "Trying to add a #{belongs_to_klass} belongs_to #{has_some_klass}..."
|
165
|
+
|
166
|
+
# so this is a belongs_to & has_some style relationship...
|
167
|
+
# is it a has_many, or a has_one? Well, let's assume a has_one has a unique index on the column please... good db design, haha!
|
168
|
+
unique = belongs_to_klass.get_unique_index_columns.include?(belongs_to_fk)
|
169
|
+
belongs_to_name = belongs_to_fk.sub(/_id$/, '').to_sym
|
170
|
+
@@belongs_to_associations[belongs_to_klass.to_s] << "belongs_to :#{belongs_to_name}, :class_name => '#{has_some_klass}', :foreign_key => :#{belongs_to_fk.to_sym}"
|
171
|
+
logger.debug @@belongs_to_associations[belongs_to_klass.to_s].last
|
172
|
+
|
173
|
+
# work out if we need a prefix
|
174
|
+
has_some_name = ((unique ? belongs_to_klass.table_name.singularize : belongs_to_klass.table_name.pluralize) + (belongs_to_name.to_s == has_some_klass.table_name.singularize ? "" : "_as_"+belongs_to_name.to_s)).downcase.to_sym
|
175
|
+
method = unique ? :has_one : :has_many
|
176
|
+
@@has_some_associations[has_some_klass.to_s] << "#{method} :#{has_some_name}, :class_name => '#{belongs_to_klass.to_s}', :foreign_key => :#{belongs_to_fk.to_sym}"
|
177
|
+
logger.debug @@has_some_associations[has_some_klass.to_s].last
|
178
|
+
|
179
|
+
return { :method => method,
|
180
|
+
:belongs_to_name => belongs_to_name,
|
181
|
+
:has_some_name => has_some_name,
|
182
|
+
:has_some_class => has_some_klass }
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
class ModelHash < Hash
|
189
|
+
def unenquire(class_id)
|
190
|
+
@enquired ||= {}
|
191
|
+
@enquired[class_id = class_id.to_s] = false
|
192
|
+
end
|
193
|
+
|
194
|
+
def enquired?(class_id)
|
195
|
+
@enquired ||= {}
|
196
|
+
@enquired[class_id.to_s]
|
197
|
+
end
|
198
|
+
|
199
|
+
def [](class_id)
|
200
|
+
enquired?(class_id = class_id.to_s)
|
201
|
+
@enquired[class_id] = true
|
202
|
+
super(class_id)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|