major V2 update
This commit is contained in:
parent
f9a664b2ee
commit
2bd6456f45
9 changed files with 24 additions and 16 deletions
|
|
@ -15,9 +15,17 @@ class MigrationContext:
|
|||
def __init__(self, config: AppConfig, target_platform: str = "fluxer"):
|
||||
self.config = config
|
||||
self.target_platform = target_platform
|
||||
|
||||
# Use the target server/community ID for state file naming so each
|
||||
# target server gets its own independent migration history.
|
||||
if target_platform == "stoat":
|
||||
server_id = config.stoat_server_id
|
||||
else:
|
||||
server_id = config.fluxer_community_id
|
||||
|
||||
self.state = MigrationState(
|
||||
state_file=f"{target_platform}.state.json",
|
||||
messages_file=f"{target_platform}.messages.json"
|
||||
state_file=f"{server_id}.state.json",
|
||||
messages_file=f"{server_id}.messages.json"
|
||||
)
|
||||
|
||||
self.discord_reader = DiscordReader(
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from typing import Dict, Any
|
|||
class MigrationState:
|
||||
"""Manages persistence of the migration state to allow resumability."""
|
||||
|
||||
def __init__(self, state_file: str | Path = "fluxer.state.json", messages_file: str | Path = "fluxer.messages.json"):
|
||||
def __init__(self, state_file: str | Path = "default.state.json", messages_file: str | Path = "default.messages.json"):
|
||||
self.state_file = Path(state_file)
|
||||
self.messages_file = Path(messages_file)
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ class MigrationState:
|
|||
migrated_state = False
|
||||
migrated_messages = False
|
||||
|
||||
# 1. Load primary fluxer.state.json
|
||||
# 1. Load primary state file
|
||||
if self.state_file.exists():
|
||||
with open(self.state_file, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
|
@ -41,12 +41,12 @@ class MigrationState:
|
|||
self.sticker_map = data.get("stickers", {})
|
||||
self.audit_log_channel = data.get("audit_log_channel")
|
||||
|
||||
# Check for legacy messages in fluxer.state.json
|
||||
# Check for legacy messages in state file
|
||||
if "messages" in data or "last_message_timestamps" in data:
|
||||
self.message_map = data.get("messages", {})
|
||||
self.last_message_ids = data.get("last_message_ids", {})
|
||||
self.last_message_timestamps = data.get("last_message_timestamps", {})
|
||||
migrated_messages = True # We found legacy data, we should write it out to fluxer.messages.json later
|
||||
migrated_messages = True # We found legacy data, we should write it out to messages file later
|
||||
|
||||
# Legacy Migration: Move role_, emoji_, sticker_ from channel_map to dedicated maps
|
||||
legacy_keys = list(self.channel_map.keys())
|
||||
|
|
@ -64,7 +64,7 @@ class MigrationState:
|
|||
self.sticker_map[discord_id] = self.channel_map.pop(k)
|
||||
migrated_state = True
|
||||
|
||||
# 2. Load separate fluxer.messages.json (overrides legacy fluxer.state.json)
|
||||
# 2. Load separate messages file (overrides legacy state file messages)
|
||||
if self.messages_file.exists():
|
||||
with open(self.messages_file, "r", encoding="utf-8") as f:
|
||||
msg_data = json.load(f)
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
async def sync_channel_state(context: MigrationContext):
|
||||
"""
|
||||
Scans Fluxer for channels matching Discord names and updates fluxer.state.json mappings.
|
||||
This prevents duplicate creation when the fluxer.state.json is empty but channels exist in Fluxer.
|
||||
Scans Fluxer for channels matching Discord names and updates state file mappings.
|
||||
This prevents duplicate creation when the state file is empty but channels exist in Fluxer.
|
||||
"""
|
||||
categories = await context.discord_reader.get_categories()
|
||||
channels = await context.discord_reader.get_channels()
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
async def sync_assets_state(context: MigrationContext):
|
||||
"""
|
||||
Scans Fluxer for emojis and stickers matching Discord names and updates fluxer.state.json mappings.
|
||||
Scans Fluxer for emojis and stickers matching Discord names and updates state file mappings.
|
||||
"""
|
||||
discord_emojis = await context.discord_reader.get_emojis()
|
||||
discord_stickers = await context.discord_reader.get_stickers()
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
async def sync_roles_state(context: MigrationContext):
|
||||
"""
|
||||
Scans Fluxer for roles matching Discord names and updates fluxer.state.json mappings.
|
||||
Scans Fluxer for roles matching Discord names and updates state file mappings.
|
||||
"""
|
||||
discord_roles = await context.discord_reader.get_roles()
|
||||
fluxer_roles = await context.fluxer_writer.client.get_guild_roles(context.config.fluxer_community_id)
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
async def sync_channel_state(context: MigrationContext):
|
||||
"""
|
||||
Scans Stoat for channels matching Discord names and updates stoat.state.json mappings.
|
||||
This prevents duplicate creation when the stoat.state.json is empty but channels exist in Stoat.
|
||||
Scans Stoat for channels matching Discord names and updates state file mappings.
|
||||
This prevents duplicate creation when the state file is empty but channels exist in Stoat.
|
||||
"""
|
||||
categories = await context.discord_reader.get_categories()
|
||||
channels = await context.discord_reader.get_channels()
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
async def sync_assets_state(context: MigrationContext):
|
||||
"""
|
||||
Scans Stoat for emojis matching Discord names and updates stoat.state.json mappings.
|
||||
Scans Stoat for emojis matching Discord names and updates state file mappings.
|
||||
"""
|
||||
discord_emojis = await context.discord_reader.get_emojis()
|
||||
# Stickers not supported on Stoat based on current library investigation
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
async def sync_roles_state(context: MigrationContext):
|
||||
"""
|
||||
Scans Stoat for roles matching Discord names and updates stoat.state.json mappings.
|
||||
Scans Stoat for roles matching Discord names and updates state file mappings.
|
||||
"""
|
||||
discord_roles = await context.discord_reader.get_roles()
|
||||
server = await context.stoat_writer._get_server()
|
||||
|
|
|
|||
|
|
@ -514,7 +514,7 @@ class MigrationCLI:
|
|||
|
||||
force = False
|
||||
if cached_count > 0:
|
||||
console.print(f"[yellow]\u26a0 {cached_count}/{all_ids_len} item(s) already in fluxer.state.json cache.[/yellow]")
|
||||
console.print(f"[yellow]\u26a0 {cached_count}/{all_ids_len} item(s) already in state cache.[/yellow]")
|
||||
# End of table consolidated section, back to standard flow logic.
|
||||
|
||||
console.print("[bold green](Y) Continue with only missing items[/bold green]")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue