feat: add captain usage table

This commit is contained in:
Shivam Mishra
2026-06-30 16:14:50 +05:30
parent 926a9d8a69
commit 1b8a4a8594
2 changed files with 34 additions and 1 deletions
@@ -0,0 +1,20 @@
class CreateCaptainUsages < ActiveRecord::Migration[7.1]
def change
create_table :captain_usages do |t|
t.references :account, null: false
t.references :assistant, null: false
t.integer :usage_type, null: false
# Usage is binned into 15-minute UTC buckets so it can be re-sliced into
# any caller timezone (including :45 offset zones). Do not widen to hourly.
t.datetime :bucket_started_at, null: false
t.integer :credits_used, null: false, default: 0
t.timestamps
end
add_index :captain_usages,
[:account_id, :assistant_id, :usage_type, :bucket_started_at],
unique: true,
name: 'index_captain_usages_unique_bucket'
end
end
+14 -1
View File
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2026_06_20_000000) do
ActiveRecord::Schema[7.1].define(version: 2026_06_30_102817) do
# These extensions should be enabled to support this database
enable_extension "pg_stat_statements"
enable_extension "pg_trgm"
@@ -431,6 +431,19 @@ ActiveRecord::Schema[7.1].define(version: 2026_06_20_000000) do
t.index ["enabled"], name: "index_captain_scenarios_on_enabled"
end
create_table "captain_usages", force: :cascade do |t|
t.bigint "account_id", null: false
t.bigint "assistant_id", null: false
t.integer "usage_type", null: false
t.datetime "bucket_started_at", null: false
t.integer "credits_used", default: 0, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["account_id", "assistant_id", "usage_type", "bucket_started_at"], name: "index_captain_usages_unique_bucket", unique: true
t.index ["account_id"], name: "index_captain_usages_on_account_id"
t.index ["assistant_id"], name: "index_captain_usages_on_assistant_id"
end
create_table "categories", force: :cascade do |t|
t.integer "account_id", null: false
t.integer "portal_id", null: false