class CreateWikiRevisions < ActiveRecord::Migration[7.0]
  def change
    create_table :wiki_revisions do |t|
      t.references :wiki_page, null: false, foreign_key: true
      t.references :base_revision, foreign_key: { to_table: :wiki_revisions }
      t.references :created_user, null: false, foreign_key: { to_table: :users }
      t.integer :kind, null: false, default: 0  # 0: content, 1: redirect
      t.references :redirect_page, foreign_key: { to_table: :wiki_pages }
      t.string :message
      t.integer :lines_count, null: false, default: 0
      t.string :tree_sha256, limit: 64
      t.timestamps
    end

    add_index :wiki_revisions, :tree_sha256
    add_index :wiki_revisions, [:wiki_page_id, :id]
    add_index :wiki_revisions, :kind
  end
end
