scinote-web/db/migrate/20150924115001_create_report_elements.rb

45 lines
1.4 KiB
Ruby
Raw Normal View History

2017-06-30 16:23:28 +08:00
class CreateReportElements < ActiveRecord::Migration[4.2]
2016-02-12 23:52:43 +08:00
def change
create_table :report_elements do |t|
t.integer :position, null: false
t.integer :type_of, null: false
t.integer :sort_order, default: 0 # Can be null
2016-02-12 23:52:43 +08:00
# Each element belongs to report
t.integer :report_id
# Each element can have parent element
t.references :parent, index: true
# References to various report entities
t.integer :project_id
t.integer :my_module_id
t.integer :step_id
t.integer :result_id
t.integer :checklist_id
t.integer :asset_id
t.integer :table_id
t.timestamps null: false
end
add_foreign_key :report_elements, :reports
add_index :report_elements, :report_id
add_foreign_key :report_elements, :projects
add_index :report_elements, :project_id
add_foreign_key :report_elements, :my_modules
add_index :report_elements, :my_module_id
add_foreign_key :report_elements, :steps
add_index :report_elements, :step_id
add_foreign_key :report_elements, :results
add_index :report_elements, :result_id
add_foreign_key :report_elements, :checklists
add_index :report_elements, :checklist_id
add_foreign_key :report_elements, :assets
add_index :report_elements, :asset_id
add_foreign_key :report_elements, :tables
add_index :report_elements, :table_id
end
end