fix dependency import
This commit is contained in:
parent
bf1d745cef
commit
23dd29644c
@ -6,7 +6,8 @@ ChangeLog
|
|||||||
===
|
===
|
||||||
0.1.5
|
0.1.5
|
||||||
-----
|
-----
|
||||||
- Add sqlite and postgres support
|
- Add sqlite and postgres support.
|
||||||
|
- Fix dependency import.
|
||||||
|
|
||||||
0.1.4
|
0.1.4
|
||||||
-----
|
-----
|
||||||
|
@ -13,15 +13,9 @@ from tortoise import (
|
|||||||
Model,
|
Model,
|
||||||
Tortoise,
|
Tortoise,
|
||||||
)
|
)
|
||||||
from tortoise.backends.asyncpg.schema_generator import AsyncpgSchemaGenerator
|
|
||||||
from tortoise.backends.mysql.schema_generator import MySQLSchemaGenerator
|
|
||||||
from tortoise.backends.sqlite.schema_generator import SqliteSchemaGenerator
|
|
||||||
from tortoise.fields import Field
|
from tortoise.fields import Field
|
||||||
|
|
||||||
from aerich.ddl import BaseDDL
|
from aerich.ddl import BaseDDL
|
||||||
from aerich.ddl.mysql import MysqlDDL
|
|
||||||
from aerich.ddl.postgres import PostgresDDL
|
|
||||||
from aerich.ddl.sqlite import SqliteDDL
|
|
||||||
from aerich.exceptions import ConfigurationError
|
from aerich.exceptions import ConfigurationError
|
||||||
from aerich.utils import get_app_connection
|
from aerich.utils import get_app_connection
|
||||||
|
|
||||||
@ -78,11 +72,17 @@ class Migrate:
|
|||||||
await Tortoise.init(config=migrate_config)
|
await Tortoise.init(config=migrate_config)
|
||||||
|
|
||||||
connection = get_app_connection(config, app)
|
connection = get_app_connection(config, app)
|
||||||
if connection.schema_generator is MySQLSchemaGenerator:
|
if connection.schema_generator.DIALECT == "mysql":
|
||||||
|
from aerich.ddl.mysql import MysqlDDL
|
||||||
|
|
||||||
cls.ddl = MysqlDDL(connection)
|
cls.ddl = MysqlDDL(connection)
|
||||||
elif connection.schema_generator is SqliteSchemaGenerator:
|
elif connection.schema_generator.DIALECT == "sqlite":
|
||||||
|
from aerich.ddl.sqlite import SqliteDDL
|
||||||
|
|
||||||
cls.ddl = SqliteDDL(connection)
|
cls.ddl = SqliteDDL(connection)
|
||||||
elif connection.schema_generator is AsyncpgSchemaGenerator:
|
elif connection.schema_generator.DIALECT == "postgres":
|
||||||
|
from aerich.ddl.postgres import PostgresDDL
|
||||||
|
|
||||||
cls.ddl = PostgresDDL(connection)
|
cls.ddl = PostgresDDL(connection)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("Current only support MySQL")
|
raise NotImplementedError("Current only support MySQL")
|
||||||
|
@ -30,9 +30,6 @@ class User(Model):
|
|||||||
avatar = fields.CharField(max_length=200, default="")
|
avatar = fields.CharField(max_length=200, default="")
|
||||||
intro = fields.TextField(default="")
|
intro = fields.TextField(default="")
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"{self.pk}#{self.username}"
|
|
||||||
|
|
||||||
|
|
||||||
class Category(Model):
|
class Category(Model):
|
||||||
slug = fields.CharField(max_length=200)
|
slug = fields.CharField(max_length=200)
|
||||||
@ -40,9 +37,6 @@ class Category(Model):
|
|||||||
user = fields.ForeignKeyField("models.User", description="User")
|
user = fields.ForeignKeyField("models.User", description="User")
|
||||||
created_at = fields.DatetimeField(auto_now_add=True)
|
created_at = fields.DatetimeField(auto_now_add=True)
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"{self.pk}#{self.name}"
|
|
||||||
|
|
||||||
|
|
||||||
class Product(Model):
|
class Product(Model):
|
||||||
categories = fields.ManyToManyField("models.Category")
|
categories = fields.ManyToManyField("models.Category")
|
||||||
@ -55,15 +49,9 @@ class Product(Model):
|
|||||||
body = fields.TextField()
|
body = fields.TextField()
|
||||||
created_at = fields.DatetimeField(auto_now_add=True)
|
created_at = fields.DatetimeField(auto_now_add=True)
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"{self.pk}#{self.name}"
|
|
||||||
|
|
||||||
|
|
||||||
class Config(Model):
|
class Config(Model):
|
||||||
label = fields.CharField(max_length=200)
|
label = fields.CharField(max_length=200)
|
||||||
key = fields.CharField(max_length=20)
|
key = fields.CharField(max_length=20)
|
||||||
value = fields.JSONField()
|
value = fields.JSONField()
|
||||||
status: Status = fields.IntEnumField(Status, default=Status.on)
|
status: Status = fields.IntEnumField(Status, default=Status.on)
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"{self.pk}#{self.label}"
|
|
||||||
|
@ -48,7 +48,6 @@ class TestDDL(test.TruncationTestCase):
|
|||||||
);""",
|
);""",
|
||||||
)
|
)
|
||||||
elif isinstance(self.ddl, PostgresDDL):
|
elif isinstance(self.ddl, PostgresDDL):
|
||||||
print(ret)
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
ret,
|
ret,
|
||||||
"""CREATE TABLE IF NOT EXISTS "category" (
|
"""CREATE TABLE IF NOT EXISTS "category" (
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
from tortoise.contrib import test
|
|
||||||
|
|
||||||
|
|
||||||
class TestMigrate(test.TruncationTestCase):
|
|
||||||
pass
|
|
Loading…
x
Reference in New Issue
Block a user