Skip to content

Commit 58801ac

Browse files
authored
Add Index for Workflow Rate-Limiter (#499)
Porting dbos-inc/dbos-transact-ts#1106 to Python
1 parent b329d55 commit 58801ac

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

dbos/_migration.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,18 @@ def get_dbos_migration_two(schema: str) -> str:
209209
"""
210210

211211

212+
def get_dbos_migration_three(schema: str) -> str:
213+
return f"""
214+
create index "idx_workflow_status_queue_status_started" on \"{schema}\"."workflow_status" ("queue_name", "status", "started_at_epoch_ms")
215+
"""
216+
217+
212218
def get_dbos_migrations(schema: str) -> list[str]:
213-
return [get_dbos_migration_one(schema), get_dbos_migration_two(schema)]
219+
return [
220+
get_dbos_migration_one(schema),
221+
get_dbos_migration_two(schema),
222+
get_dbos_migration_three(schema),
223+
]
214224

215225

216226
def get_sqlite_timestamp_expr() -> str:
@@ -303,4 +313,9 @@ def get_sqlite_timestamp_expr() -> str:
303313
ALTER TABLE workflow_status ADD COLUMN queue_partition_key TEXT;
304314
"""
305315

306-
sqlite_migrations = [sqlite_migration_one, sqlite_migration_two]
316+
sqlite_migration_three = """
317+
CREATE INDEX "idx_workflow_status_queue_status_started"
318+
ON "workflow_status" ("queue_name", "status", "started_at_epoch_ms")
319+
"""
320+
321+
sqlite_migrations = [sqlite_migration_one, sqlite_migration_two, sqlite_migration_three]

0 commit comments

Comments
 (0)