From 0d94b22b3f318cf9e58afd6db4aa1d40caab9dba Mon Sep 17 00:00:00 2001 From: long2ice Date: Wed, 3 Feb 2021 18:06:43 +0800 Subject: [PATCH] Remove unused functions --- README.md | 6 +++++- aerich/migrate.py | 38 +------------------------------------- 2 files changed, 6 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index ac38dff..3ad00cb 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ migrations solution. ~~**Important: You can only use absolutely import in your `models.py` to make `aerich` work.**~~ From version `v0.5.0`, there is no such limitation now. + ## Install Just install from pypi: @@ -111,7 +112,8 @@ Format of migrate filename is `{version_num}_{datetime}_{name|update}.sql`. And if `aerich` guess you are renaming a column, it will ask `Rename {old_column} to {new_column} [True]`, you can -choice `True` to rename column without column drop, or choice `False` to drop column then create, note that the after maybe lose data. +choice `True` to rename column without column drop, or choice `False` to drop column then create, note that the after +maybe lose data. ### Upgrade to latest version @@ -167,6 +169,8 @@ Now your db rollback to specified version. ### Inspect db tables to TortoiseORM model +Currently, only support MySQL. + ```shell Usage: aerich inspectdb [OPTIONS] diff --git a/aerich/migrate.py b/aerich/migrate.py index f4ed30c..b0c8eeb 100644 --- a/aerich/migrate.py +++ b/aerich/migrate.py @@ -5,17 +5,8 @@ from typing import Dict, List, Optional, Tuple, Type import click from dictdiffer import diff -from tortoise import ( - BackwardFKRelation, - BackwardOneToOneRelation, - BaseDBAsyncClient, - ForeignKeyFieldInstance, - ManyToManyFieldInstance, - Model, - Tortoise, -) +from tortoise import BaseDBAsyncClient, Model, Tortoise from tortoise.exceptions import OperationalError -from tortoise.fields import Field from aerich.ddl import BaseDDL from aerich.models import MAX_VERSION_LENGTH, Aerich @@ -358,10 +349,6 @@ class Migrate: if old_model not in new_models.keys(): cls._add_operator(cls.remove_model(cls._get_model(old_model)), upgrade) - @classmethod - def _is_fk_m2m(cls, field: Field): - return isinstance(field, (ForeignKeyFieldInstance, ManyToManyFieldInstance)) - @classmethod def add_model(cls, model: Type[Model]): return cls.ddl.create_table(model) @@ -390,29 +377,6 @@ class Migrate: fields_name = cls._resolve_fk_fields_name(model, fields_name) return cls.ddl.add_index(model, fields_name, unique) - @classmethod - def _exclude_field(cls, field: Field, upgrade=False): - """ - exclude BackwardFKRelation and repeat m2m field - :param field: - :return: - """ - if isinstance(field, ManyToManyFieldInstance): - through = field.through - if upgrade: - if through in cls._upgrade_m2m: - return True - else: - cls._upgrade_m2m.append(through) - return False - else: - if through in cls._downgrade_m2m: - return True - else: - cls._downgrade_m2m.append(through) - return False - return isinstance(field, (BackwardFKRelation, BackwardOneToOneRelation)) - @classmethod def _add_field(cls, model: Type[Model], field_describe: dict, is_pk: bool = False): return cls.ddl.add_column(model, field_describe, is_pk)