-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclear_db.py
More file actions
50 lines (40 loc) · 1.36 KB
/
clear_db.py
File metadata and controls
50 lines (40 loc) · 1.36 KB
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
import os
from dotenv import load_dotenv
from pocketbase import Client
from pocketbase.errors import ClientResponseError
PB_URL = 'http://192.168.8.68:8090' # Database Pi IP
client = Client(PB_URL, timeout=5)
token = None
# Load environment variables from .env file
load_dotenv()
# Get admin credentials from environment variables
admin_email = os.getenv("ADMIN_EMAIL")
admin_password = os.getenv("ADMIN_PASS")
if not admin_email or not admin_password:
print("DB - Admin credentials not found in environment variables.")
exit(1)
auth_data = client.collection("_superusers").auth_with_password(admin_email, admin_password)
token = auth_data.token
if token is None:
print("DB - Failed to authenticate as admin.")
exit(1)
print("Clearing <Plc> collection")
num_of_records = 0
while True:
try:
record = client.collection('Plc').get_first_list_item("")
client.collection('Plc').delete(record.id)
num_of_records += 1
except ClientResponseError:
print(f"Deleted {num_of_records} entries")
break
print("Clearing <LabJack> collection")
num_of_records = 0
while True:
try:
record = client.collection('LabJack').get_first_list_item("")
client.collection('LabJack').delete(record.id)
num_of_records += 1
except ClientResponseError:
print(f"Deleted {num_of_records} entries")
break