add migrate and cli

This commit is contained in:
long2ice
2020-05-13 18:59:24 +08:00
parent 4e7e1626aa
commit a5a5de529b
16 changed files with 338 additions and 43 deletions

View File

@@ -2,17 +2,17 @@ from asynctest import TestCase
from tortoise import Tortoise
from alice.backends.mysql import MysqlDDL
from tests.models import Category
from alice.migrate import Migrate
TORTOISE_ORM = {
'connections': {
'default': 'mysql://root:123456@127.0.0.1:3306/test'
'default': 'mysql://root:123456@127.0.0.1:3306/test',
},
'apps': {
'models': {
'models': ['tests.models'],
'default_connection': 'default',
}
},
}
}
@@ -22,6 +22,7 @@ class DBTestCase(TestCase):
await Tortoise.init(config=TORTOISE_ORM)
self.client = Tortoise.get_connection('default')
self.ddl = MysqlDDL(self.client)
self.migrate = Migrate(ddl=self.ddl)
async def tearDown(self) -> None:
await Tortoise.close_connections()

View File

@@ -1,5 +1,5 @@
from tests.backends.mysql import DBTestCase
from tests.models import Category, User
from tests.models import Category
class TestDDL(DBTestCase):
@@ -47,7 +47,3 @@ class TestDDL(DBTestCase):
def test_drop_fk(self):
ret = self.ddl.drop_fk(Category, Category._meta.fields_map.get('user'))
self.assertEqual(ret, "ALTER TABLE category DROP FOREIGN KEY fk_category_user_366ffa6f")
async def test_aa(self):
user = await User.get(username='test')
await user.save()

View File

@@ -0,0 +1,7 @@
from tests.backends.mysql import DBTestCase
class TestMigrate(DBTestCase):
async def test_migrate(self):
self.migrate.diff_models_module('tests.models', 'tests.new_models')
print(self.migrate.operators)