Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion services/usage-stats/src/insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@

load_dotenv()

DATABASE_URL = os.getenv("DATABASE_URL")
raw_url = os.getenv("DATABASE_URL", "postgresql://user:pass@localhost:5432/dbname")

# Ensure it uses asyncpg
if raw_url.startswith("postgresql://"):
raw_url = raw_url.replace("postgresql://", "postgresql+asyncpg://", 1)
elif not raw_url.startswith("postgresql+asyncpg://"):
raise ValueError(
"Invalid DATABASE_URL: must start with postgresql:// or postgresql+asyncpg://"
)

DATABASE_URL = raw_url

engine = create_async_engine(DATABASE_URL, echo=True)

Expand Down
12 changes: 11 additions & 1 deletion services/usage-stats/src/last_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@

load_dotenv()

DATABASE_URL = os.getenv("DATABASE_URL")
raw_url = os.getenv("DATABASE_URL", "postgresql://user:pass@localhost:5432/dbname")

# Ensure it uses asyncpg
if raw_url.startswith("postgresql://"):
raw_url = raw_url.replace("postgresql://", "postgresql+asyncpg://", 1)
elif not raw_url.startswith("postgresql+asyncpg://"):
raise ValueError(
"Invalid DATABASE_URL: must start with postgresql:// or postgresql+asyncpg://"
)

DATABASE_URL = raw_url

engine = create_async_engine(DATABASE_URL, echo=True)

Expand Down
15 changes: 11 additions & 4 deletions services/usage-stats/src/macrostrat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@

BATCH_SIZE = 1000 # Adjust as needed

# Database URL format: mysql+asyncmy://user:password@host:port/database
DATABASE_URL = os.getenv(
"MARIADB_URL", "mysql+asyncmy://user:password@localhost:3306/database"
)
raw_url = os.getenv("MARIADB_URL", "mysql://user:password@localhost:3306/database")

# Ensure the URL uses asyncmy driver
if raw_url.startswith("mysql://"):
raw_url = raw_url.replace("mysql://", "mysql+asyncmy://", 1)
elif not raw_url.startswith("mysql+asyncmy://"):
raise ValueError(
"Invalid DATABASE_URL: must start with mysql:// or mysql+asyncmy://"
)

DATABASE_URL = raw_url

# Create async engine
engine = create_async_engine(DATABASE_URL, echo=True)
Expand Down
15 changes: 11 additions & 4 deletions services/usage-stats/src/rockd.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@

BATCH_SIZE = 1000 # Adjust batch size as needed

# Database URL format: mysql+asyncmy://user:password@host:port/database
DATABASE_URL = os.getenv(
"MARIADB_URL", "mysql+asyncmy://user:password@localhost:3306/database"
)
raw_url = os.getenv("MARIADB_URL", "mysql://user:password@localhost:3306/database")

# Ensure the URL uses asyncmy driver
if raw_url.startswith("mysql://"):
raw_url = raw_url.replace("mysql://", "mysql+asyncmy://", 1)
elif not raw_url.startswith("mysql+asyncmy://"):
raise ValueError(
"Invalid DATABASE_URL: must start with mysql:// or mysql+asyncmy://"
)

DATABASE_URL = raw_url

# Create async SQLAlchemy engine
engine = create_async_engine(DATABASE_URL, echo=True)
Expand Down