Skip to content

Commit

Permalink
Moved the code from _create_schema() to start()
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Sep 22, 2024
1 parent 2469de7 commit c44876e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/apscheduler/datastores/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,6 @@ async def _begin_transaction(

yield conn

async def _create_schema(self, conn: Connection | AsyncConnection) -> None:
if not self.schema:
return
t = CreateSchema(name=self.schema, if_not_exists=True)
await self._execute(conn, t)

async def _create_metadata(self, conn: Connection | AsyncConnection) -> None:
if isinstance(conn, AsyncConnection):
await conn.run_sync(self._metadata.create_all)
Expand Down Expand Up @@ -396,7 +390,12 @@ async def start(
async for attempt in self._retry():
with attempt:
async with self._begin_transaction() as conn:
await self._create_schema(conn)
# Create the schema first if it doesn't exist yet
if self.schema:
await self._execute(
conn, CreateSchema(name=self.schema, if_not_exists=True)
)

if self.start_from_scratch:
for table in self._metadata.sorted_tables:
await self._execute(conn, DropTable(table, if_exists=True))
Expand Down

0 comments on commit c44876e

Please sign in to comment.