File size: 1,660 Bytes
2c29579
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import shutil
import sqlite3
import json

# Setup paths
BASE_DIR = "/home/aj/Downloads/CODIN"
BACKEND_DIR = os.path.join(BASE_DIR, "backend")
TMP_DIR = os.path.join(BACKEND_DIR, "tmp")
RUNS_DIR = os.path.join(BACKEND_DIR, "runs")
DB_PATH = os.path.join(BACKEND_DIR, "automl_studio.db")


def migrate_models():
    print(f"🚀 Starting model migration...")
    print(f"📁 TMP_DIR: {TMP_DIR}")
    print(f"📁 RUNS_DIR: {RUNS_DIR}")

    if not os.path.exists(TMP_DIR):
        print("❌ TMP_DIR not found. Nothing to migrate.")
        return

    os.makedirs(RUNS_DIR, exist_ok=True)

    moved_count = 0

    for filename in os.listdir(TMP_DIR):
        if not filename.endswith("_model.pkl"):
            continue

        job_id = filename.replace("_model.pkl", "")
        src_path = os.path.join(TMP_DIR, filename)

        if not os.path.isfile(src_path):
            continue

        dest_dir = os.path.join(RUNS_DIR, job_id, "artifacts")
        try:
            os.makedirs(dest_dir, exist_ok=True)
        except Exception as e:
            print(f"❌ Failed to create directory for {job_id}: {e}")
            continue

        dest_path = os.path.join(dest_dir, "model.pkl")

        print(f"📦 Moving {filename} -> runs/{job_id}/artifacts/model.pkl")

        try:
            shutil.copy2(src_path, dest_path)
            moved_count += 1
        except Exception as e:
            print(f"❌ Failed to move {filename}: {e}")

    print(f"✅ Migration complete. Moved {moved_count} models.")


if __name__ == "__main__":
    try:
        migrate_models()
    except Exception as e:
        print(f"❌ Migration failed: {e}")