Merge pull request #1101 from useautumn/fix/inconsistent-count-numbers
feat: sync up db indices and structure for getPaginatedFullCusQuery
This commit is contained in:
@@ -64,10 +64,18 @@ export const customers = pgTable(
|
||||
.on(table.org_id, table.env, table.fingerprint)
|
||||
.where(sql`${table.fingerprint} IS NOT NULL`),
|
||||
index("idx_customers_processor_id").on(sql`(${table.processor} ->> 'id')`),
|
||||
index("idx_customers_composite").on(table.org_id, table.env, table.id),
|
||||
index("idx_customers_org_env_internal_id").on(
|
||||
table.org_id,
|
||||
table.env,
|
||||
sql`${table.internal_id} DESC`,
|
||||
),
|
||||
index("idx_customers_org_id_env_created_at").on(
|
||||
table.org_id,
|
||||
table.env,
|
||||
sql`${table.created_at} DESC`,
|
||||
),
|
||||
],
|
||||
).enableRLS();
|
||||
|
||||
collatePgColumn(customers.internal_id, "C");
|
||||
|
||||
// CREATE INDEX idx_customers_org_env_internal_id
|
||||
// ON customers (org_id, env, internal_id DESC);
|
||||
|
||||
@@ -60,10 +60,7 @@ export const entities = pgTable(
|
||||
table.internal_customer_id,
|
||||
table.id,
|
||||
),
|
||||
index("idx_entities_internal_customer_id").using(
|
||||
"hash",
|
||||
table.internal_customer_id,
|
||||
),
|
||||
index("idx_entities_internal_customer_id").on(table.internal_customer_id),
|
||||
index("idx_entities_customer_internal_desc").on(
|
||||
table.internal_customer_id,
|
||||
sql`${table.internal_id} DESC`,
|
||||
|
||||
@@ -77,10 +77,19 @@ export const customerEntitlements = pgTable(
|
||||
.onUpdate("cascade")
|
||||
.onDelete("cascade"),
|
||||
index("idx_customer_entitlements_product_id").on(table.customer_product_id),
|
||||
index("idx_customer_entitlements_internal_customer_id").on(
|
||||
index("idx_customer_entitlements_internal_customer_id").using(
|
||||
"hash",
|
||||
table.internal_customer_id,
|
||||
),
|
||||
index("idx_customer_entitlements_internal_customer_id_btree").on(
|
||||
table.internal_customer_id,
|
||||
),
|
||||
index("idx_customer_entitlements_entitlement_id").on(table.entitlement_id),
|
||||
index("idx_customer_entitlements_internal_entity_id").using(
|
||||
"hash",
|
||||
table.internal_entity_id,
|
||||
),
|
||||
index("idx_customer_entitlements_on_next_reset_at").on(table.next_reset_at),
|
||||
index("idx_customer_entitlements_loose_customer_expires")
|
||||
.on(table.internal_customer_id, table.expires_at)
|
||||
.where(sql`${table.customer_product_id} IS NULL`),
|
||||
|
||||
@@ -89,6 +89,13 @@ export const customerProducts = pgTable(
|
||||
index("idx_customer_products_on_internal_entity_id").on(
|
||||
table.internal_entity_id,
|
||||
),
|
||||
index("idx_customer_products_on_internal_product_id").on(
|
||||
table.internal_product_id,
|
||||
),
|
||||
index("idx_customer_products_subscription_ids").using(
|
||||
"gin",
|
||||
table.subscription_ids,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user