Skip to content

Commit 5814ba1

Browse files
committed
fix: balance snapshot indexes
This should help with the usage snapshot queries.
1 parent 55556d1 commit 5814ba1

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

openmeter/ent/db/migrate/schema.go

Lines changed: 5 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openmeter/ent/schema/balance_snapshot.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package schema
33
import (
44
"entgo.io/ent"
55
"entgo.io/ent/dialect"
6+
"entgo.io/ent/dialect/entsql"
67
"entgo.io/ent/schema/edge"
78
"entgo.io/ent/schema/field"
89
"entgo.io/ent/schema/index"
@@ -45,9 +46,9 @@ func (BalanceSnapshot) Fields() []ent.Field {
4546

4647
func (BalanceSnapshot) Indexes() []ent.Index {
4748
return []ent.Index{
48-
index.Fields("namespace", "at"),
49-
index.Fields("namespace", "balance"),
50-
index.Fields("namespace", "balance", "at"),
49+
index.Fields("namespace", "owner_id", "at").Annotations(
50+
entsql.IndexWhere("deleted_at IS NULL"),
51+
),
5152
}
5253
}
5354

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- reverse: create index "balancesnapshot_namespace_owner_id_at" to table: "balance_snapshots"
2+
DROP INDEX "balancesnapshot_namespace_owner_id_at";
3+
-- reverse: drop index "balancesnapshot_namespace_balance_at" from table: "balance_snapshots"
4+
CREATE INDEX "balancesnapshot_namespace_balance_at" ON "balance_snapshots" ("namespace", "balance", "at");
5+
-- reverse: drop index "balancesnapshot_namespace_balance" from table: "balance_snapshots"
6+
CREATE INDEX "balancesnapshot_namespace_balance" ON "balance_snapshots" ("namespace", "balance");
7+
-- reverse: drop index "balancesnapshot_namespace_at" from table: "balance_snapshots"
8+
CREATE INDEX "balancesnapshot_namespace_at" ON "balance_snapshots" ("namespace", "at");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- drop index "balancesnapshot_namespace_at" from table: "balance_snapshots"
2+
DROP INDEX "balancesnapshot_namespace_at";
3+
-- drop index "balancesnapshot_namespace_balance" from table: "balance_snapshots"
4+
DROP INDEX "balancesnapshot_namespace_balance";
5+
-- drop index "balancesnapshot_namespace_balance_at" from table: "balance_snapshots"
6+
DROP INDEX "balancesnapshot_namespace_balance_at";
7+
-- create index "balancesnapshot_namespace_owner_id_at" to table: "balance_snapshots"
8+
CREATE INDEX "balancesnapshot_namespace_owner_id_at" ON "balance_snapshots" ("namespace", "owner_id", "at") WHERE (deleted_at IS NULL);

tools/migrate/migrations/atlas.sum

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
h1:GBSDL939Zna5rKl2wFhpUqGQJUHddDKFReBELgNGbV0=
1+
h1:fDFD8PZ8j8vPRxmMYjAeFv9ai8AXG8pP7VA0oDQL2Hg=
22
20240826120919_init.down.sql h1:AIbgwwngjkJEYa3yRZsIXQyBa2+qoZttwMXHxXEbHLI=
33
20240826120919_init.up.sql h1:/hYHWF3Z3dab8SMKnw99ixVktCuJe2bAw5wstCZIEN8=
44
20240903155435_entitlement-expired-index.down.sql h1:np2xgYs3KQ2z7qPBcobtGNhqWQ3V8NwEP9E5U3TmpSA=
@@ -129,3 +129,5 @@ h1:GBSDL939Zna5rKl2wFhpUqGQJUHddDKFReBELgNGbV0=
129129
20250306040407_resource_meter.up.sql h1:L0bhDCSzStPWsIvx6hULDKK7eurpBD3bIv9b18mSWqc=
130130
20250307151454_balance-snapshot-usage.down.sql h1:UprCI9cWSumzY1NXmlO055r65VEd2M8+vvMzkJc6Q3g=
131131
20250307151454_balance-snapshot-usage.up.sql h1:j2x/+rYBLsHNpUCmeKwvyXe1TwXTSDMlddESgUFUqMM=
132+
20250311193204_balance-snapshot-indexes.down.sql h1:8EImnDEROfVw7dS2S6iIsbKH7L2VKBPdjKmfXV4bv4c=
133+
20250311193204_balance-snapshot-indexes.up.sql h1:pOm1/hjT5JNIKY6HGoE9cKdm7sEktvGoe70aXIXdtas=

0 commit comments

Comments
 (0)