Skip to content

Commit

Permalink
Use aiomyql driver to generate models
Browse files Browse the repository at this point in the history
  • Loading branch information
garryod committed Apr 18, 2024
1 parent 2da5347 commit 57f3634
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/_container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Build and export to Docker local cache
uses: docker/build-push-action@v5
with:
build-args: DATABASE_URL=mysql+pymysql://root:rootpassword@localhost/ispyb_build
build-args: DATABASE_URL=mysql+aiomysql://root:rootpassword@localhost/ispyb_build
context: .
# Need load and tags so we can test it below
load: true
Expand All @@ -61,7 +61,7 @@ jobs:
# This does not build the image again, it will find the image in the
# Docker cache and publish it
with:
build-args: DATABASE_URL=mysql+pymysql://root:rootpassword@localhost/ispyb_build
build-args: DATABASE_URL=mysql+aiomysql://root:rootpassword@localhost/ispyb_build
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/_dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
options: >
--health-cmd "/usr/local/bin/healthcheck.sh --defaults-file=/ispyb/.my.cnf --connect"
env:
DATABASE_URL: mysql+pymysql://root:rootpassword@localhost/ispyb_build
DATABASE_URL: mysql+aiomysql://root:rootpassword@localhost/ispyb_build
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
options: >
--health-cmd "/usr/local/bin/healthcheck.sh --defaults-file=/ispyb/.my.cnf --connect"
env:
DATABASE_URL: mysql+pymysql://root:rootpassword@localhost/ispyb_build
DATABASE_URL: mysql+aiomysql://root:rootpassword@localhost/ispyb_build
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
options: >
--health-cmd "/usr/local/bin/healthcheck.sh --defaults-file=/ispyb/.my.cnf --connect"
env:
DATABASE_URL: mysql+pymysql://root:rootpassword@localhost/ispyb_build
DATABASE_URL: mysql+aiomysql://root:rootpassword@localhost/ispyb_build
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/_tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
options: >
--health-cmd "/usr/local/bin/healthcheck.sh --defaults-file=/ispyb/.my.cnf --connect"
env:
DATABASE_URL: mysql+pymysql://root:rootpassword@localhost/ispyb_build
DATABASE_URL: mysql+aiomysql://root:rootpassword@localhost/ispyb_build
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ requires = [
"setuptools_scm[toml]>=6.2",
"sqlacodegen-v2",
"sqlalchemy",
"pymysql",
"aiomysql",
]
build-backend = "setuptools.build_meta"

Expand All @@ -25,7 +25,7 @@ dependencies = [
"uvicorn",
"starlette",
"strawberry-graphql[asgi]",
"sqlalchemy",
"sqlalchemy[asyncio]",
"aiomysql",
"opentelemetry-api",
"opentelemetry-sdk",
Expand Down
22 changes: 17 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import asyncio
import os

import setuptools
from sqlacodegen_v2.generators import DeclarativeGenerator
from sqlalchemy import MetaData, create_engine
from sqlalchemy import MetaData
from sqlalchemy.ext.asyncio import create_async_engine

if __name__ == "__main__":
engine = create_engine(os.environ["DATABASE_URL"])

async def generate_models():
engine = create_async_engine(os.environ["DATABASE_URL"])
metadata = MetaData()
metadata.reflect(engine, only=["EnergyScan"])
generator = DeclarativeGenerator(metadata, engine, set())
async with engine.begin() as connection:
await connection.run_sync(
lambda connection: metadata.reflect(connection, only=["EnergyScan"])
)
generator = await connection.run_sync(
lambda connection: DeclarativeGenerator(metadata, connection, set())
)
with open("src/graph_energy_scan/models.py", "w") as models_file:
models_file.write(generator.generate())


if __name__ == "__main__":
asyncio.run(generate_models())
setuptools.setup()

0 comments on commit 57f3634

Please sign in to comment.