rename_plugin_app_label
This module moves a database from the llmtool app’s legacy app label, plugin, to llmtool.
The app was smarter.apps.plugin, with the app label plugin, until it
was renamed smarter.apps.llmtool. A database created before the rename
holds its tables as plugin_<model>, its migration history as
django_migrations rows with app = "plugin", and its content types with
app_label = "plugin". Django can’t migrate such a database: migrate
and makemigrations both stop with InconsistentMigrationHistory,
because the prompt and llmclient migrations are recorded as applied while
their dependency, llmtool.0001_initial, is not. Run this command once,
before makemigrations and migrate. It is idempotent: on a new database,
or one that it already moved, it changes nothing.
- class smarter.apps.llmtool.management.commands.rename_plugin_app_label.Command(*args, **kwargs)[source]
Bases:
SmarterCommandDjango manage.py rename_plugin_app_label command.
Moves a database created before
smarter.apps.pluginbecamesmarter.apps.llmtoolto the new app label: tables, migration history and content types. Run it beforemakemigrationsandmigrate.- handle(*args, **options)[source]
Rename the tables, then relabel the migration history and content types.
- help = "Move the llmtool app's tables, migration history and content types from the legacy app label 'plugin'."
- smarter.apps.llmtool.management.commands.rename_plugin_app_label.LEGACY_APP_LABEL = 'plugin'
The app label of
smarter.apps.llmtoolbefore it was renamed.
- smarter.apps.llmtool.management.commands.rename_plugin_app_label.legacy_table_names()[source]
The llmtool app’s tables, as (legacy name, current name) pairs.
Proxy and unmanaged models have no table of their own, so they are left out. Many-to-many tables that Django creates are included.
- smarter.apps.llmtool.management.commands.rename_plugin_app_label.relabel_content_types()[source]
Move the app’s content types from
plugintollmtool.The content type ids don’t change, so permissions, tags and admin log entries that reference them stay attached. A legacy content type whose model already has an
llmtoolcontent type is left alone and logged, because deleting it would also delete the rows that reference it.- Return type:
- Returns:
the number of content types moved.
- smarter.apps.llmtool.management.commands.rename_plugin_app_label.relabel_migration_history()[source]
Move the app’s
django_migrationsrows fromplugintollmtool.A legacy row whose migration is already recorded under
llmtoolis deleted.- Return type:
- Returns:
the number of rows moved.
- smarter.apps.llmtool.management.commands.rename_plugin_app_label.rename_tables()[source]
Rename the legacy
plugin_<model>tables tollmtool_<model>.All tables are renamed by one
RENAME TABLEstatement, which MariaDB runs atomically: either every table is renamed, or none is. Foreign keys that reference a renamed table follow it.