feat: support skip table migration by set managed=False (#397)
This commit is contained in:
@@ -102,6 +102,7 @@ class Product(Model):
|
||||
class Meta:
|
||||
unique_together = (("name", "type"),)
|
||||
indexes = (("name", "type"),)
|
||||
managed = True
|
||||
|
||||
|
||||
class Config(Model):
|
||||
@@ -118,6 +119,21 @@ class Config(Model):
|
||||
|
||||
email: fields.OneToOneRelation[Email]
|
||||
|
||||
class Meta:
|
||||
managed = True
|
||||
|
||||
|
||||
class DontManageMe(Model):
|
||||
name = fields.CharField(max_length=50)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
|
||||
|
||||
class Ignore(Model):
|
||||
class Meta:
|
||||
managed = False
|
||||
|
||||
|
||||
class NewModel(Model):
|
||||
name = fields.CharField(max_length=50)
|
||||
|
||||
@@ -89,3 +89,40 @@ class Config(Model):
|
||||
|
||||
class Meta:
|
||||
table = "configs"
|
||||
|
||||
|
||||
class DontManageMe(Model):
|
||||
name = fields.CharField(max_length=50)
|
||||
|
||||
class Meta:
|
||||
table = "dont_manage"
|
||||
|
||||
|
||||
class Ignore(Model):
|
||||
name = fields.CharField(max_length=50)
|
||||
|
||||
class Meta:
|
||||
managed = True
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Generate a python file for the old_models_describe"""
|
||||
from pathlib import Path
|
||||
|
||||
from tortoise import run_async
|
||||
from tortoise.contrib.test import init_memory_sqlite
|
||||
|
||||
from aerich.utils import get_models_describe
|
||||
|
||||
@init_memory_sqlite
|
||||
async def run() -> None:
|
||||
old_models_describe = get_models_describe("models")
|
||||
p = Path("old_models_describe.py")
|
||||
p.write_text(f"{old_models_describe = }", encoding="utf-8")
|
||||
print(f"Write value to {p}\nYou can reformat it by `ruff format {p}`")
|
||||
|
||||
run_async(run())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user