From 8429faf0a804dd9f462638d3181712d17cb1e089 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 19 Dec 2024 18:03:52 +0300 Subject: [PATCH] fix seed data --- server/db/seed.go | 7 ++++-- server/db/seed_data/jobs.json | 12 +++++----- server/db/seed_data/servers.json | 16 ++++++------- server/db/seed_data/users.json | 40 +++++++------------------------- 4 files changed, 28 insertions(+), 47 deletions(-) diff --git a/server/db/seed.go b/server/db/seed.go index feb804d..00dec5a 100644 --- a/server/db/seed.go +++ b/server/db/seed.go @@ -2,7 +2,6 @@ package db import ( "context" - "encoding/json" "fmt" "github.com/moevm/nosql2h24-transcribtion/config" "github.com/moevm/nosql2h24-transcribtion/models" @@ -12,6 +11,10 @@ import ( "os" ) +import ( + "go.mongodb.org/mongo-driver/bson" +) + func loadDataFromFile(filePath string, result interface{}) error { file, err := os.Open(filePath) if err != nil { @@ -24,7 +27,7 @@ func loadDataFromFile(filePath string, result interface{}) error { return err } - err = json.Unmarshal(data, &result) + err = bson.UnmarshalExtJSON(data, true, result) if err != nil { return err } diff --git a/server/db/seed_data/jobs.json b/server/db/seed_data/jobs.json index b77da03..094412d 100644 --- a/server/db/seed_data/jobs.json +++ b/server/db/seed_data/jobs.json @@ -1,7 +1,7 @@ [ { "_id": { "$oid": "650e7c3f5f1e4e0001a0bdf3" }, - "user_id": { "$oid": "650e802f5f1e4e0001a0be00" }, + "user_id": { "$oid": "650e812f5f1e4e0001a0be01" }, "title": "Transcription Task 1", "status": "in_progress", "source_language": "English", @@ -11,12 +11,12 @@ "output_file": "transcription1.txt", "created_at": "2023-10-15T09:00:00Z", "updated_at": "2023-10-15T09:00:00Z", - "host_id": { "$oid": "650e822f5f1e4e0001a0be01" }, + "host_id": { "$oid": "650e822f5f1e4e0001a0be11" }, "estimated_finish_datetime": "2023-10-15T11:00:00Z" }, { "_id": { "$oid": "650e7c3f5f1e4e0001a0bdf4" }, - "user_id": { "$oid": "650e802f5f1e4e0001a0be01" }, + "user_id": { "$oid": "650e812f5f1e4e0001a0be02" }, "title": "Translation Task 1", "status": "completed", "source_language": "Spanish", @@ -26,12 +26,12 @@ "output_file": "translated1.pdf", "created_at": "2023-11-12T11:30:00Z", "updated_at": "2023-11-12T11:30:00Z", - "host_id": { "$oid": "650e832f5f1e4e0001a0be02" }, + "host_id": { "$oid": "650e832f5f1e4e0001a0be12" }, "estimated_finish_datetime": "2023-11-12T14:30:00Z" }, { "_id": { "$oid": "650e7c3f5f1e4e0001a0bdf5" }, - "user_id": { "$oid": "650e802f5f1e4e0001a0be02" }, + "user_id": { "$oid": "650e812f5f1e4e0001a0be03" }, "title": "Data Processing Task 1", "status": "pending", "source_language": "French", @@ -41,7 +41,7 @@ "output_file": "processed1.csv", "created_at": "2023-11-18T15:00:00Z", "updated_at": "2023-11-18T15:00:00Z", - "host_id": { "$oid": "650e842f5f1e4e0001a0be03" }, + "host_id": { "$oid": "650e842f5f1e4e0001a0be13" }, "estimated_finish_datetime": "2023-11-18T18:00:00Z" } ] diff --git a/server/db/seed_data/servers.json b/server/db/seed_data/servers.json index dc00022..abb6b26 100644 --- a/server/db/seed_data/servers.json +++ b/server/db/seed_data/servers.json @@ -1,6 +1,6 @@ [ { - "_id": { "$oid": "650e822f5f1e4e0001a0be01" }, + "_id": { "$oid": "650e822f5f1e4e0001a0be11" }, "hostname": "server_1", "address": "192.168.1.1", "description": "Main processing server for jobs.", @@ -10,15 +10,13 @@ "current_jobs": [ { "$oid": "650e7c3f5f1e4e0001a0bdf3" } ], - "completed_jobs": [ - { "$oid": "650e7c3f5f1e4e0001a0bdf7" } - ], + "completed_jobs": [], "cpu_info": "Intel Xeon E5-2680 v4", "gpu_info": "NVIDIA Tesla V100", "ram_size_gb": 256 }, { - "_id": { "$oid": "650e832f5f1e4e0001a0be02" }, + "_id": { "$oid": "650e832f5f1e4e0001a0be12" }, "hostname": "server_2", "address": "192.168.1.2", "description": "Backup server for job processing.", @@ -26,13 +24,15 @@ "created_at": "2023-11-05T14:30:00Z", "updated_at": "2023-11-05T14:30:00Z", "current_jobs": [], - "completed_jobs": [], + "completed_jobs": [ + { "$oid": "650e7c3f5f1e4e0001a0bdf4" } + ], "cpu_info": "AMD EPYC 7742", "gpu_info": "NVIDIA A100", "ram_size_gb": 512 }, { - "_id": { "$oid": "650e842f5f1e4e0001a0be03" }, + "_id": { "$oid": "650e842f5f1e4e0001a0be13" }, "hostname": "server_3", "address": "192.168.1.3", "description": "Test server for job simulation.", @@ -40,7 +40,7 @@ "created_at": "2023-11-20T09:00:00Z", "updated_at": "2023-11-20T09:00:00Z", "current_jobs": [ - { "$oid": "650e7c3f5f1e4e0001a0bdf4" } + { "$oid": "650e7c3f5f1e4e0001a0bdf5" } ], "completed_jobs": [], "cpu_info": "Intel Xeon Platinum 8280", diff --git a/server/db/seed_data/users.json b/server/db/seed_data/users.json index cff468c..a1871a3 100644 --- a/server/db/seed_data/users.json +++ b/server/db/seed_data/users.json @@ -12,7 +12,7 @@ "jobs": [] }, { - "_id": { "$oid": "650e7c2f5f1e4e0001a0bdf1" }, + "_id": { "$oid": "650e812f5f1e4e0001a0be01" }, "username": "john_doe", "email": "john.doe@example.com", "password_hash": "hashed_password_123", @@ -34,7 +34,7 @@ "jobs": [{ "$oid": "650e7c3f5f1e4e0001a0bdf3" }] }, { - "_id": { "$oid": "650e7d2f5f1e4e0001a0bdf5" }, + "_id": { "$oid": "650e812f5f1e4e0001a0be02" }, "username": "jane_smith", "email": "jane.smith@example.com", "password_hash": "hashed_password_456", @@ -50,13 +50,13 @@ "payment_status": "pending", "created_at": "2023-11-19T08:00:00Z", "updated_at": "2023-11-19T09:00:00Z", - "job_id": { "$oid": "650e7d4f5f1e4e0001a0bdf7" } + "job_id": { "$oid": "650e7c3f5f1e4e0001a0bdf4" } } ], - "jobs": [{ "$oid": "650e7d4f5f1e4e0001a0bdf7" }] + "jobs": [{ "$oid": "650e7c3f5f1e4e0001a0bdf4" }] }, { - "_id": { "$oid": "650e7e2f5f1e4e0001a0bdf8" }, + "_id": { "$oid": "650e812f5f1e4e0001a0be03" }, "username": "alice_wonder", "email": "alice.wonder@example.com", "password_hash": "hashed_password_789", @@ -72,13 +72,13 @@ "payment_status": "completed", "created_at": "2023-11-15T10:30:00Z", "updated_at": "2023-11-15T11:00:00Z", - "job_id": { "$oid": "650e7e4f5f1e4e0001a0bdfa" } + "job_id": { "$oid": "650e7c3f5f1e4e0001a0bdf5" } } ], - "jobs": [{ "$oid": "650e7e4f5f1e4e0001a0bdfa" }] + "jobs": [{ "$oid": "650e7c3f5f1e4e0001a0bdf5" }] }, { - "_id": { "$oid": "650e7f2f5f1e4e0001a0bdfb" }, + "_id": { "$oid": "650e812f5f1e4e0001a0be04" }, "username": "bob_builder", "email": "bob.builder@example.com", "password_hash": "hashed_password_987", @@ -87,28 +87,6 @@ "updated_at": "2023-09-20T08:00:00Z", "last_login_at": "2023-11-18T07:00:00Z", "payments": [], - "jobs": [{ "$oid": "650e7f4f5f1e4e0001a0bdfc" }] - }, - { - "_id": { "$oid": "650e802f5f1e4e0001a0bdfd" }, - "username": "charlie_chaplin", - "email": "charlie.chaplin@example.com", - "password_hash": "hashed_password_654", - "permissions": "moderator", - "created_at": "2023-10-01T15:00:00Z", - "updated_at": "2023-10-01T15:00:00Z", - "last_login_at": "2023-11-22T18:00:00Z", - "payments": [ - { - "_id": { "$oid": "650e803e5f1e4e0001a0bdfe" }, - "price": "120.00", - "payment_method": "credit_card", - "payment_status": "completed", - "created_at": "2023-10-15T12:00:00Z", - "updated_at": "2023-10-15T12:30:00Z", - "job_id": { "$oid": "650e804f5f1e4e0001a0bdff" } - } - ], - "jobs": [{ "$oid": "650e804f5f1e4e0001a0bdff" }] + "jobs": [] } ]