cryogenic22 commited on
Commit
30d93de
·
verified ·
1 Parent(s): 78f8d8a

Update src/core/services/database_service.py

Browse files
src/core/services/database_service.py CHANGED
@@ -78,6 +78,39 @@ class DatabaseService:
78
  FOREIGN KEY (parent_account_id) REFERENCES accounts (id),
79
  FOREIGN KEY (account_owner_id) REFERENCES users (id)
80
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  ''')
82
 
83
  def generate_synthetic_data(self):
@@ -185,6 +218,62 @@ class DatabaseService:
185
  )
186
  ''', accounts)
187
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  conn.commit()
189
 
190
  def add_account(self, account_data: Dict[str, Any]) -> str:
 
78
  FOREIGN KEY (parent_account_id) REFERENCES accounts (id),
79
  FOREIGN KEY (account_owner_id) REFERENCES users (id)
80
  );
81
+
82
+ CREATE TABLE IF NOT EXISTS contacts (
83
+ id TEXT PRIMARY KEY,
84
+ account_id TEXT,
85
+ first_name TEXT,
86
+ last_name TEXT,
87
+ email TEXT,
88
+ phone TEXT,
89
+ title TEXT,
90
+ department TEXT,
91
+ reports_to_id TEXT,
92
+ influence_level TEXT,
93
+ engagement_score REAL,
94
+ preferences TEXT,
95
+ created_at TEXT,
96
+ last_contacted TEXT,
97
+ FOREIGN KEY (account_id) REFERENCES accounts (id),
98
+ FOREIGN KEY (reports_to_id) REFERENCES contacts (id)
99
+ );
100
+
101
+ CREATE TABLE IF NOT EXISTS interactions (
102
+ id TEXT PRIMARY KEY,
103
+ type TEXT,
104
+ account_id TEXT,
105
+ owner_id TEXT,
106
+ transcript TEXT,
107
+ summary TEXT,
108
+ sentiment_score REAL,
109
+ metadata TEXT,
110
+ created_at TEXT,
111
+ FOREIGN KEY (account_id) REFERENCES accounts (id),
112
+ FOREIGN KEY (owner_id) REFERENCES users (id)
113
+ );
114
  ''')
115
 
116
  def generate_synthetic_data(self):
 
218
  )
219
  ''', accounts)
220
 
221
+ # Generate contacts for each account
222
+ contacts = []
223
+ for account in accounts:
224
+ for _ in range(random.randint(3, 8)): # 3-8 contacts per account
225
+ contacts.append({
226
+ 'id': str(uuid.uuid4()),
227
+ 'account_id': account['id'],
228
+ 'first_name': self.fake.first_name(),
229
+ 'last_name': self.fake.last_name(),
230
+ 'email': self.fake.email(),
231
+ 'phone': self.fake.phone_number(),
232
+ 'title': random.choice(['CEO', 'CTO', 'CFO', 'VP Sales', 'Director']),
233
+ 'department': random.choice(['Executive', 'Sales', 'IT', 'Finance']),
234
+ 'reports_to_id': None,
235
+ 'influence_level': random.choice(['High', 'Medium', 'Low']),
236
+ 'engagement_score': random.uniform(0, 100),
237
+ 'preferences': json.dumps({}),
238
+ 'created_at': datetime.now().isoformat(),
239
+ 'last_contacted': datetime.now().isoformat()
240
+ })
241
+
242
+ c.executemany('''
243
+ INSERT OR REPLACE INTO contacts VALUES (
244
+ :id, :account_id, :first_name, :last_name, :email, :phone,
245
+ :title, :department, :reports_to_id, :influence_level,
246
+ :engagement_score, :preferences, :created_at, :last_contacted
247
+ )
248
+ ''', contacts)
249
+
250
+ # Generate interactions for each account
251
+ interactions = []
252
+ for account in accounts:
253
+ for _ in range(random.randint(5, 12)): # 5-12 interactions per account
254
+ interactions.append({
255
+ 'id': str(uuid.uuid4()),
256
+ 'type': random.choice(['call', 'meeting', 'email', 'presentation']),
257
+ 'account_id': account['id'],
258
+ 'owner_id': account['account_owner_id'],
259
+ 'transcript': self.fake.paragraph(),
260
+ 'summary': self.fake.sentence(),
261
+ 'sentiment_score': random.uniform(0, 1),
262
+ 'metadata': json.dumps({
263
+ 'duration': random.randint(15, 120),
264
+ 'location': random.choice(['virtual', 'in-person']),
265
+ 'attendees': random.randint(1, 5)
266
+ }),
267
+ 'created_at': datetime.now().isoformat()
268
+ })
269
+
270
+ c.executemany('''
271
+ INSERT OR REPLACE INTO interactions VALUES (
272
+ :id, :type, :account_id, :owner_id, :transcript, :summary,
273
+ :sentiment_score, :metadata, :created_at
274
+ )
275
+ ''', interactions)
276
+
277
  conn.commit()
278
 
279
  def add_account(self, account_data: Dict[str, Any]) -> str: