Merge pull request #248 from isaquealves/feature/load_ddl_class_per_dialect
feat: Add support for dynamically load DDL classes
This commit is contained in:
commit
8f68f08eba
@ -5,6 +5,8 @@
|
||||
### 0.6.4
|
||||
|
||||
- Improve `inspectdb` adding support to `postgresql::numeric` data type
|
||||
- Add support for dynamically load DDL classes easing to add support to
|
||||
new databases without changing `Migrate` class logic
|
||||
|
||||
### 0.6.3
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import importlib
|
||||
import os
|
||||
from datetime import datetime
|
||||
from hashlib import md5
|
||||
@ -63,6 +64,11 @@ class Migrate:
|
||||
ret = await connection.execute_query(sql)
|
||||
cls._db_version = ret[1][0].get("version")
|
||||
|
||||
@classmethod
|
||||
async def load_ddl_class(cls):
|
||||
ddl_dialect_module = importlib.import_module(f"aerich.ddl.{cls.dialect}")
|
||||
return getattr(ddl_dialect_module, f"{cls.dialect.capitalize()}DDL")
|
||||
|
||||
@classmethod
|
||||
async def init(cls, config: dict, app: str, location: str):
|
||||
await Tortoise.init(config=config)
|
||||
@ -74,18 +80,8 @@ class Migrate:
|
||||
|
||||
connection = get_app_connection(config, app)
|
||||
cls.dialect = connection.schema_generator.DIALECT
|
||||
if cls.dialect == "mysql":
|
||||
from aerich.ddl.mysql import MysqlDDL
|
||||
|
||||
cls.ddl = MysqlDDL(connection)
|
||||
elif cls.dialect == "sqlite":
|
||||
from aerich.ddl.sqlite import SqliteDDL
|
||||
|
||||
cls.ddl = SqliteDDL(connection)
|
||||
elif cls.dialect == "postgres":
|
||||
from aerich.ddl.postgres import PostgresDDL
|
||||
|
||||
cls.ddl = PostgresDDL(connection)
|
||||
cls.ddl_class = await cls.load_ddl_class()
|
||||
cls.ddl = cls.ddl_class(connection)
|
||||
await cls._get_db_version(connection)
|
||||
|
||||
@classmethod
|
||||
|
Loading…
x
Reference in New Issue
Block a user