mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
FQDN, Dig refactor, docs #1065
This commit is contained in:
19
scripts/db_empty/README.md
Executable file
19
scripts/db_empty/README.md
Executable file
@@ -0,0 +1,19 @@
|
||||
# Overview
|
||||
|
||||
A script for deleting all data from the database.
|
||||
|
||||
# Usage
|
||||
|
||||
1. **Run the Script**
|
||||
|
||||
`python ./db_empty.py`
|
||||
|
||||
### Other info
|
||||
|
||||
- Version: 1.0
|
||||
- Release Date: 01-Jun-2025
|
||||
- Author: [jokob-sk](https://github.com/jokob-sk)
|
||||
|
||||
|
||||
> [!NOTE]
|
||||
> This is a community supplied script and not maintained.
|
||||
26
scripts/db_empty/db_empty.py
Executable file
26
scripts/db_empty/db_empty.py
Executable file
@@ -0,0 +1,26 @@
|
||||
import sqlite3
|
||||
|
||||
# Connect to the database
|
||||
conn = sqlite3.connect("/app/db/app.db")
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Get the names of all tables (excluding SQLite internal tables)
|
||||
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%';")
|
||||
tables = cursor.fetchall()
|
||||
|
||||
# Disable foreign key constraints temporarily
|
||||
cursor.execute("PRAGMA foreign_keys = OFF;")
|
||||
|
||||
# Delete all rows from each table
|
||||
for (table_name,) in tables:
|
||||
cursor.execute(f"DELETE FROM {table_name};")
|
||||
|
||||
# Commit changes and re-enable foreign keys
|
||||
conn.commit()
|
||||
cursor.execute("PRAGMA foreign_keys = ON;")
|
||||
|
||||
# Vacuum to shrink database file
|
||||
cursor.execute("VACUUM;")
|
||||
|
||||
# Close connection
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user