Add aggregation in migration?

Is there any way to add aggregation in migration like we add type?

We do something like this in the migration file - we add the type of the field.

def change do
    create table("mall") do
      add :visitors, :integer
      add :total_time, :integer
    
      timestamps()
    end
  end

Is there any way we could add aggregation in migration file? Like for example I would like the field visitors to have aggregation sum and total_time to have aggregation sum /visitors. Or can this be only done through queries?

What’s stopping you execute-ing an SQL statement after the create table(...) statement? Or do you mean an automatic aggregation every time a record changes in the table?