-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean_db_to_build.py
65 lines (53 loc) · 1.64 KB
/
clean_db_to_build.py
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
62
63
64
65
# import os
# import sys
# from pathlib import Path
# import django
# v_root = Path(__file__).parent
# sys.path.append(os.path.abspath(v_root))
# try:
# from django.conf import settings
# from django.db import connection
# os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'src.settings')
# os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
# django.setup()
# # from ge.models import (
# # Connector,
# # Datasource,
# # DSTColumn,
# # Logs,
# # PrefixOpc,
# # Term,
# # TermCategory,
# # TermGroup,
# # TermMap,
# # WFControl,
# # WordMap,
# # WordTerm,
# # )
# except Exception as e:
# print(e)
# raise
# # # Truncate Function
# # def truncate_table(table_name):
# table_name = 'termmap'
# try:
# with connection.cursor() as cursor:
# # Disable foreign key checks temporarily
# cursor.execute('PRAGMA foreign_keys = OFF;')
# # Truncate the table by deleting all records
# cursor.execute(f"DELETE FROM {table_name};")
# # Reset the primary key sequence for the table
# cursor.execute(
# f"DELETE FROM sqlite_sequence WHERE name='{table_name}';"
# )
# # Enable foreign key checks
# cursor.execute('PRAGMA foreign_keys = ON;')
# # Vacuum the database to reclaim unused space
# cursor.execute("VACUUM;")
# except Exception as e:
# print("ERROR:", e)
# def truncate_ge(table_name):
# with connection.cursor() as cursor:
# cursor.execute(f"DELETE FROM {table_name};")
# cursor.execute("VACUUM;")
# return True