# frozen_string_literal: true

class CreateRequestOptimizationTables < ActiveRecord::Migration[8.1]
  def change
    # Path segments for compression and analytics
    create_table :path_segments, force: :cascade do |t|
      t.string :segment, null: false, index: { unique: true }
      t.integer :usage_count, default: 1, null: false
      t.datetime :first_seen_at, null: false

      t.timestamps
    end

    # Request hosts for compression and analytics
    create_table :request_hosts, force: :cascade do |t|
      t.string :hostname, null: false, index: { unique: true }
      t.integer :usage_count, default: 1, null: false
      t.datetime :first_seen_at, null: false

      t.timestamps
    end

    # Request methods for normalization
    create_table :request_methods, force: :cascade do |t|
      t.string :method, null: false, index: { unique: true }

      t.timestamps
    end

    # Request protocols for normalization
    create_table :request_protocols, force: :cascade do |t|
      t.string :protocol, null: false, index: { unique: true }

      t.timestamps
    end

    # Request actions for normalization
    create_table :request_actions, force: :cascade do |t|
      t.string :action, null: false, index: { unique: true }

      t.timestamps
    end
  end
end