Skip to content

Commit

Permalink
Add "UNATTENDED_MIGRATION" environment variable for automatic migrati…
Browse files Browse the repository at this point in the history
…on of blocklists

If this environment variable is present and set to true, the bot will automatically run the blocklist migration upon connection and config load, skipping the requirement to run the migration command. This only checks environment variables, it is not a traditional config option.
  • Loading branch information
khakers committed Aug 3, 2023
1 parent 56604aa commit 985478e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
except ImportError:
pass

from core import checks
from core import checks, migrations
from core.changelog import Changelog
from core.clients import ApiClient, MongoDBClient, PluginDatabaseClient
from core.config import ConfigManager
Expand Down Expand Up @@ -576,12 +576,18 @@ async def on_ready(self):
)
logger.line()

# Check if the legacy blocklist is being used
if len(self.config["blocked"]) > 0 or len(self.config["blocked_roles"]) > 0:
logger.warning(
"Un-migrated blocklists found. Please run the '[p]migrate blocklist' command after backing "
"up your config/database. Blocklist functionality will be disabled until this is done."
)
logger.line()
# This should only run in the host has decided on it, which is why it's environment variable based
if "UNATTENDED_MIGRATION" in os.environ.items() and os.environ["UNATTENDED_MIGRATION"].lower() == "true":
logger.info("running unattended blocklist migration")
await migrations.migrate_blocklist(self)
else:
logger.warning(
"Un-migrated blocklists found. Please run the '[p]migrate blocklist' command after backing "
"up your config/database. Blocklist functionality will be disabled until this is done."
)
logger.line()

await self.threads.populate_cache()

Expand Down

0 comments on commit 985478e

Please sign in to comment.