ぼざクリタグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

35 lines
1.3 KiB

  1. class CreateMaterials < ActiveRecord::Migration[8.0]
  2. def change
  3. create_table :materials do |t|
  4. t.string :url
  5. t.references :parent, index: true, foreign_key: { to_table: :materials }
  6. t.references :tag, index: true, foreign_key: true
  7. t.references :created_by_user, foreign_key: { to_table: :users }
  8. t.references :updated_by_user, foreign_key: { to_table: :users }
  9. t.timestamps
  10. t.datetime :discarded_at, index: true
  11. t.virtual :active_url, type: :string,
  12. as: 'IF(discarded_at IS NULL, url, NULL)',
  13. stored: false
  14. t.index :active_url, unique: true
  15. end
  16. create_table :material_versions do |t|
  17. t.references :material, null: false, foreign_key: true
  18. t.integer :version_no, null: false
  19. t.string :url, index: true
  20. t.references :parent, index: true, foreign_key: { to_table: :materials }
  21. t.references :tag, index: true, foreign_key: true
  22. t.references :created_by_user, foreign_key: { to_table: :users }
  23. t.references :updated_by_user, foreign_key: { to_table: :users }
  24. t.timestamps
  25. t.datetime :discarded_at, index: true
  26. t.index [:material_id, :version_no],
  27. unique: true,
  28. name: 'index_material_versions_on_material_id_and_version_no'
  29. end
  30. end
  31. end