fix(reinstall): use OSTemplate.vmid (not template_vmid) and convert memory bytes->MB

- AttributeError: OSTemplate has no 'template_vmid' field; the actual column is 'vmid'.
- Use OSTemplate.get_vmid_for_node() to support cross-node replicated templates,
  falling back to source_node/vmid otherwise.
- VMInstance.memory is stored in bytes, but Proxmox config expects MB.
This commit is contained in:
markmorado
2026-04-29 23:48:48 +02:00
parent 5169bf80a3
commit 89d70654fc
45 changed files with 2946 additions and 741 deletions

View File

@@ -1256,6 +1256,37 @@ def migrate_user_role_remove_dashboard(conn):
logger.info("✓ user role: dashboard:view already False, skipping")
def migrate_deploy_tasks(conn):
"""Migration 22: Create deploy_tasks table for async VM deployment tracking"""
conn.execute(text("""
CREATE TABLE IF NOT EXISTS deploy_tasks (
id SERIAL PRIMARY KEY,
status VARCHAR(20) NOT NULL DEFAULT 'pending',
step VARCHAR(200),
progress INTEGER NOT NULL DEFAULT 0,
name VARCHAR(100) NOT NULL,
template_id INTEGER NOT NULL,
server_id INTEGER,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
vmid INTEGER,
node VARCHAR(100),
error_message TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
started_at TIMESTAMPTZ,
completed_at TIMESTAMPTZ
)
"""))
conn.execute(text("""
CREATE INDEX IF NOT EXISTS idx_deploy_task_user_status
ON deploy_tasks (user_id, status)
"""))
conn.execute(text("""
CREATE INDEX IF NOT EXISTS idx_deploy_tasks_created
ON deploy_tasks (created_at)
"""))
logger.info("✓ deploy_tasks table created")
def run_all_migrations(engine, db_session=None):
"""
Run all migrations in order.
@@ -1438,6 +1469,14 @@ def run_all_migrations(engine, db_session=None):
logger.warning(f"User role dashboard migration: {e}")
conn.rollback()
# Migration 22: Deploy Tasks table
try:
migrate_deploy_tasks(conn)
conn.commit()
except Exception as e:
logger.warning(f"Deploy tasks migration: {e}")
conn.rollback()
logger.info("=" * 50)
logger.info("✓ All migrations completed successfully")
logger.info("=" * 50)