MCPcopy
hub / github.com/tortoise/tortoise-orm / database_backward

Method database_backward

tortoise/migrations/operations.py:606–631  ·  view source on GitHub ↗
(
        self,
        app_label: str,
        old_state: State,
        new_state: State,
        state_editor: BaseSchemaEditor | None = None,
    )

Source from the content-addressed store, hash-verified

604 )
605
606 async def database_backward(
607 self,
608 app_label: str,
609 old_state: State,
610 new_state: State,
611 state_editor: BaseSchemaEditor | None = None,
612 ) -> None:
613 if not state_editor:
614 return
615 old_model = old_state.apps.get_model(f"{app_label}.{self.model_name}")
616 new_model = new_state.apps.get_model(f"{app_label}.{self.model_name}")
617 old_field = old_model._meta.fields_map[self.new_name]
618 new_field = new_model._meta.fields_map[self.old_name]
619 old_db_field = old_field.source_field or old_field.model_field_name
620 new_db_field = new_field.source_field or new_field.model_field_name
621 if old_db_field == new_db_field:
622 return
623 await state_editor._run_sql(
624 state_editor.RENAME_FIELD_TEMPLATE.format(
625 table=state_editor._qualify_table_name(
626 new_model._meta.db_table, new_model._meta.schema
627 ),
628 old_column=old_db_field,
629 new_column=new_db_field,
630 )
631 )
632
633
634def _get_option_list(model_state: ModelState, key: str) -> list:

Callers

nothing calls this directly

Calls 3

get_modelMethod · 0.45
_run_sqlMethod · 0.45
_qualify_table_nameMethod · 0.45

Tested by

no test coverage detected