python-glowplug 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
glowplug/base.py CHANGED
@@ -1,6 +1,8 @@
1
1
  from abc import ABC, abstractmethod
2
2
  from functools import cached_property
3
+ from typing import Any
3
4
 
5
+ import alembic
4
6
  from sqlalchemy import Engine, create_engine
5
7
  from sqlalchemy.ext.asyncio import (
6
8
  AsyncEngine,
@@ -11,9 +13,25 @@ from sqlalchemy.ext.asyncio import (
11
13
  from sqlalchemy.orm import DeclarativeBase, Session, sessionmaker
12
14
 
13
15
 
16
+ class AlembicCommandProxy:
17
+ """Proxy for running alembic commands with a given config."""
18
+
19
+ def __init__(self, config: alembic.config.Config) -> None:
20
+ self.config = config
21
+
22
+ def __getattribute__(self, name: str) -> Any:
23
+ cmd = getattr(alembic.command, name)
24
+ if callable(cmd):
25
+ return lambda *args, **kwargs: cmd(self.config, *args, **kwargs)
26
+ return super().__getattribute__(name)
27
+
28
+
14
29
  class DbDriver(ABC):
15
- def __init__(self, debug: bool = False) -> None:
30
+ def __init__(
31
+ self, debug: bool = False, alembic_config: str = "alembic.ini"
32
+ ) -> None:
16
33
  self.debug = debug
34
+ self.alembic_config = alembic_config
17
35
 
18
36
  @abstractmethod
19
37
  async def exists(self) -> bool:
@@ -63,3 +81,11 @@ class DbDriver(ABC):
63
81
  def sync_session(self) -> Session:
64
82
  """Get a sync session."""
65
83
  return sessionmaker(self.get_sync_engine(), expire_on_commit=False)
84
+
85
+ @cached_property
86
+ def alembic(self) -> AlembicCommandProxy:
87
+ """Get an alembic command proxy."""
88
+ # Use the Alembic config from `alembic.ini` but override the URL for the db
89
+ al_cfg = alembic.config.Config(self.alembic_config)
90
+ al_cfg.set_main_option("sqlalchemy.url", self.sync_uri)
91
+ return AlembicCommandProxy(al_cfg)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-glowplug
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary:
5
5
  Home-page: https://github.com/jnu/python-glowplug
6
6
  License: MIT
@@ -13,6 +13,7 @@ Classifier: Programming Language :: Python :: 3.9
13
13
  Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
15
  Classifier: Programming Language :: Python :: 3.12
16
+ Requires-Dist: alembic (>=1.5,<2.0)
16
17
  Requires-Dist: sqlalchemy (>=2,<3)
17
18
  Project-URL: Repository, https://github.com/jnu/python-glowplug
18
19
  Description-Content-Type: text/markdown
@@ -22,13 +23,14 @@ Glowplug
22
23
 
23
24
  A consistent interface for maintenance operations on database engines not covered by SQLAlchemy.
24
25
 
25
- Chooses opinionated drivers with both async + sync support.
26
+ Chooses opinionated drivers with both async + sync support, as well as support for Alembic.
26
27
 
27
28
  ## Supported operations
28
29
 
29
30
  - `exists` - Check if database exists
30
31
  - `create` - Create a new database
31
32
  - `init` - Create all tables in the given database, optionally dropping first
33
+ - `alembic` - Run any of the alembic commands on the given database
32
34
 
33
35
  ## Supported databases
34
36
 
@@ -1,9 +1,9 @@
1
1
  glowplug/__init__.py,sha256=vOFfxzKjr7djsdQcWi3x4IKMgcNHYSZgwyld5Xzezws,195
2
- glowplug/base.py,sha256=fuj9PlOZEV6Cb6pgbtffQGR2Tm3mrMCVjvOldn6XDcA,1870
2
+ glowplug/base.py,sha256=5NtigIoCKxwgb7LSvrvLi0BiUjAeeKTu_2__GbkQOts,2800
3
3
  glowplug/mssql.py,sha256=XTNqeekpi6nyZ4J007F3k4ejPfXJhgXemCQdoUSqVH8,2094
4
4
  glowplug/pg.py,sha256=4Hw2WG33UzgYyJtWLv8QWZzHhzzsM34TyDuObtxvNmI,2600
5
5
  glowplug/sqlite.py,sha256=DEJ8lYP8ZPemeGezTovs8WISGaVyUfwTIqiwMz3FPdU,1020
6
- python_glowplug-0.1.0.dist-info/LICENSE,sha256=HvAzro26TfbigQ3ppmyagEGHIr_UtyQDfU8muTAqWFU,1060
7
- python_glowplug-0.1.0.dist-info/METADATA,sha256=Yeec4d9MRiXHyG9Bp6zroy8usK8w0pNBTSMj685jPUc,1120
8
- python_glowplug-0.1.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
9
- python_glowplug-0.1.0.dist-info/RECORD,,
6
+ python_glowplug-0.2.0.dist-info/LICENSE,sha256=HvAzro26TfbigQ3ppmyagEGHIr_UtyQDfU8muTAqWFU,1060
7
+ python_glowplug-0.2.0.dist-info/METADATA,sha256=U_smRn-daLjtyA0XMFQOBrY1sydrA0v7-DFK-EIptBg,1257
8
+ python_glowplug-0.2.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
9
+ python_glowplug-0.2.0.dist-info/RECORD,,