【发布时间】:2023-03-19 23:06:02
【问题描述】:
我设计了以下迁移,并想与社区确认是否符合 Rails 迁移的最佳实践。我正在运行一个 postgres 数据库。
我正在尝试实现一个数据库结构,其中附加到用户的各种状态存储在一个单独的表中。比如婚姻状况。
如果这听起来像是一个相当有效的桌子设计,请告诉我。以及我可以改进的地方。
class CreatePrequalifications < ActiveRecord::Migration[5.2]
def change
create_table :prequalifications do |t|
t.string :attachment
t.text :description
t.integer :marital_status
t.integer :professional_status
t.integer :collateral_status
t.integer :income_direct
t.integer :income_support
t.integer :income_scolarship
t.integer :income_other
t.boolean :blacklist
t.references :user, foreign_key: true
t.timestamps
end
end
create_table :marital_status do |t|
t.string :single
t.string :married
t.string :other
t.string :divorced
t.string :with_dependants
t.references :user, foreign_key: true
t.references :prequalifications, foreign_key: true
end
create_table :professional_status do |t|
t.string :self_employed
t.string :employed
t.string :student
t.string :other
t.text :description
t.datetime :contract_created_at
t.datetime :contract_terminated_at
t.references :user, foreign_key: true
t.references :prequalifications, foreign_key: true
end
create_table :collateral_status do |t|
t.string :collateral_name
t.string :collateral_income
t.boolean :visale_collateral
t.boolean :student_collateral
t.boolean :bank_collateral
t.references :user, foreign_key: true
t.references :prequalifications, foreign_key: true
end
结束
【问题讨论】:
标签: ruby-on-rails postgresql ruby-on-rails-5 database-migration rails-migrations