Skip to content

Commit

Permalink
Generate models from database
Browse files Browse the repository at this point in the history
  • Loading branch information
garryod committed Apr 12, 2024
1 parent 19a0fb5 commit 9dddb7b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
- ..:/workspace:cached,z
command: sleep infinity
environment:
DATABASE_URL: mysql://root:rootpassword@ispyb/ispyb_build
DATABASE_URL: mysql+pymysql://root:rootpassword@ispyb/ispyb_build

ispyb:
image: ghcr.io/diamondlightsource/ispyb-database:v3.0.0
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ lockfiles/

# ruff cache
.ruff_cache/

# Generated Database Models
src/graph_energy_scan/models.py
16 changes: 14 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
[build-system]
requires = ["setuptools>=64", "setuptools_scm[toml]>=6.2"]
requires = [
"setuptools>=64",
"setuptools_scm[toml]>=6.2",
"sqlacodegen-v2",
"sqlalchemy",
"pymysql",
]
build-backend = "setuptools.build_meta"

[project]
Expand All @@ -14,7 +20,12 @@ classifiers = [
"Programming Language :: Python :: 3.11",
]
description = "A service providing energy scan information as part of the Dimaond graph"
dependencies = ["uvicorn", "fastapi", "strawberry-graphql[fastapi]"]
dependencies = [
"uvicorn",
"fastapi",
"strawberry-graphql[fastapi]",
"sqlalchemy",
]
dynamic = ["version"]
license.file = "LICENSE"
readme = "README.md"
Expand All @@ -31,6 +42,7 @@ dev = [
"ruff",
"tox-direct",
"types-mock",
"sqlacodegen-v2",
]

[project.scripts]
Expand Down
14 changes: 14 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os

import setuptools
from sqlacodegen_v2.generators import DataclassGenerator
from sqlalchemy import MetaData, create_engine

if __name__ == "__main__":
engine = create_engine(os.environ["DATABASE_URL"])
metadata = MetaData()
metadata.reflect(engine)
generator = DataclassGenerator(metadata, engine, set())
with open("src/graph_energy_scan/models.py", "w") as models_file:
models_file.write(generator.generate())
setuptools.setup()

0 comments on commit 9dddb7b

Please sign in to comment.