|
|
@@ -32,7 +32,55 @@ def cleanup_extra_columns(apps, schema_editor):
|
|
|
from archivebox.uuid_compat import uuid7
|
|
|
from archivebox.base_models.models import get_or_create_system_user_pk
|
|
|
|
|
|
- machine_id = cursor.execute("SELECT id FROM machine_machine LIMIT 1").fetchone()[0]
|
|
|
+ # Get or create a Machine record
|
|
|
+ result = cursor.execute("SELECT id FROM machine_machine LIMIT 1").fetchone()
|
|
|
+ if result:
|
|
|
+ machine_id = result[0]
|
|
|
+ print(f" Using existing Machine: {machine_id}")
|
|
|
+ else:
|
|
|
+ # Create a minimal Machine record with raw SQL (can't use model during migration)
|
|
|
+ print(" Creating Machine record for Process migration...")
|
|
|
+ import platform
|
|
|
+ import socket
|
|
|
+
|
|
|
+ # Generate minimal machine data without using the model
|
|
|
+ machine_id = str(uuid7())
|
|
|
+ guid = f"{socket.gethostname()}-{platform.machine()}"
|
|
|
+ hostname = socket.gethostname()
|
|
|
+
|
|
|
+ # Check if config column exists (v0.9.0+ only)
|
|
|
+ cursor.execute("SELECT COUNT(*) FROM pragma_table_info('machine_machine') WHERE name='config'")
|
|
|
+ has_config = cursor.fetchone()[0] > 0
|
|
|
+
|
|
|
+ # Insert directly with SQL (use INSERT OR IGNORE in case it already exists)
|
|
|
+ if has_config:
|
|
|
+ cursor.execute("""
|
|
|
+ INSERT OR IGNORE INTO machine_machine (
|
|
|
+ id, created_at, modified_at,
|
|
|
+ guid, hostname, hw_in_docker, hw_in_vm, hw_manufacturer, hw_product, hw_uuid,
|
|
|
+ os_arch, os_family, os_platform, os_release, os_kernel,
|
|
|
+ stats, config
|
|
|
+ ) VALUES (?, datetime('now'), datetime('now'), ?, ?, 0, 0, '', '', '', ?, ?, ?, ?, '', '{}', '{}')
|
|
|
+ """, (
|
|
|
+ machine_id, guid, hostname,
|
|
|
+ platform.machine(), platform.system(), platform.platform(), platform.release()
|
|
|
+ ))
|
|
|
+ else:
|
|
|
+ # v0.8.6rc0 schema (no config column)
|
|
|
+ cursor.execute("""
|
|
|
+ INSERT OR IGNORE INTO machine_machine (
|
|
|
+ id, created_at, modified_at,
|
|
|
+ guid, hostname, hw_in_docker, hw_in_vm, hw_manufacturer, hw_product, hw_uuid,
|
|
|
+ os_arch, os_family, os_platform, os_release, os_kernel,
|
|
|
+ stats
|
|
|
+ ) VALUES (?, datetime('now'), datetime('now'), ?, ?, 0, 0, '', '', '', ?, ?, ?, ?, '', '{}')
|
|
|
+ """, (
|
|
|
+ machine_id, guid, hostname,
|
|
|
+ platform.machine(), platform.system(), platform.platform(), platform.release()
|
|
|
+ ))
|
|
|
+ # Re-query to get the actual id (in case INSERT OR IGNORE skipped it)
|
|
|
+ machine_id = cursor.execute("SELECT id FROM machine_machine LIMIT 1").fetchone()[0]
|
|
|
+ print(f" ✓ Using/Created Machine: {machine_id}")
|
|
|
|
|
|
for ar_id, cmd, pwd, binary_id, iface_id, start_ts, end_ts, status in archive_results:
|
|
|
# Create Process record
|