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: SmarterCommand

Django manage.py rename_plugin_app_label command.

Moves a database created before smarter.apps.plugin became smarter.apps.llmtool to the new app label: tables, migration history and content types. Run it before makemigrations and migrate.

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.llmtool before 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.

Return type:

list[tuple[str, str]]

Returns:

one ("plugin_<model>", "llmtool_<model>") pair per table.

smarter.apps.llmtool.management.commands.rename_plugin_app_label.relabel_content_types()[source]

Move the app’s content types from plugin to llmtool.

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 llmtool content type is left alone and logged, because deleting it would also delete the rows that reference it.

Return type:

int

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_migrations rows from plugin to llmtool.

A legacy row whose migration is already recorded under llmtool is deleted.

Return type:

int

Returns:

the number of rows moved.

smarter.apps.llmtool.management.commands.rename_plugin_app_label.rename_tables()[source]

Rename the legacy plugin_<model> tables to llmtool_<model>.

All tables are renamed by one RENAME TABLE statement, which MariaDB runs atomically: either every table is renamed, or none is. Foreign keys that reference a renamed table follow it.

Return type:

list[str]

Returns:

the new names of the tables that were renamed.

Raises:

CommandError – if a table exists under both its legacy and its new name.