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

Method database_forward

tortoise/migrations/operations.py:579–604  ·  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

577 state.reload_models(models_to_reload)
578
579 async def database_forward(
580 self,
581 app_label: str,
582 old_state: State,
583 new_state: State,
584 state_editor: BaseSchemaEditor | None = None,
585 ) -> None:
586 if not state_editor:
587 return
588 old_model = old_state.apps.get_model(f"{app_label}.{self.model_name}")
589 new_model = new_state.apps.get_model(f"{app_label}.{self.model_name}")
590 old_field = old_model._meta.fields_map[self.old_name]
591 new_field = new_model._meta.fields_map[self.new_name]
592 old_db_field = old_field.source_field or old_field.model_field_name
593 new_db_field = new_field.source_field or new_field.model_field_name
594 if old_db_field == new_db_field:
595 return
596 await state_editor._run_sql(
597 state_editor.RENAME_FIELD_TEMPLATE.format(
598 table=state_editor._qualify_table_name(
599 new_model._meta.db_table, new_model._meta.schema
600 ),
601 old_column=old_db_field,
602 new_column=new_db_field,
603 )
604 )
605
606 async def database_backward(
607 self,

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