Introduction
Welcome to this in-depth guide on the trim-database
feature in Empress, a crucial functionality that allows developers to maintain optimal database performance by removing unnecessary tables. This guide is tailored to provide a comprehensive understanding of the trim-database
feature, its technical functionalities, and its integration within your Empress projects.
Feature Overview
In the course of software development, especially during migrations, your Site Database may accumulate ‘ghost tables’—tables that remain in the database even after their corresponding DocTypes have been deleted from the list view. While these do provide a layer of redundancy and recovery, they can also lead to clutter and inefficiency.
The trim-database
feature is a command that addresses this issue. It drops any tables that seem to be remnants like ghost tables. A partial backup of the tables is attempted before dropping them, allowing for recovery in case the tables were required and were dropped erroneously.
Implementation and Usage
The command syntax for the trim-database
feature is as follows:
bench trim-database [OPTIONS]
Options and Flags
This feature comes with several options and flags that allow for customization:
--format
,-f
: Set output format. Available options are JSON and Table. Defaults to Table.--dry-run
: Show what would be deleted.--no-backup
: Do not backup the site prior to the trimming.
Examples
To understand the usage of these options and flags, consider the following examples:
Example 1: If you want to assess what data will be deleted when you run the command, you can run it with the --dry-run
flag:
bench --site {site} trim-database --dry-run
Example 2: To make the output data machine-parsable, set the output --format
to json
:
bench --site {site} trim-database --format json
Debugging and Security
The trim-database
command attempts a partial backup before dropping any tables, which is a security measure to prevent accidental loss of important data. However, in case you want to bypass this backup, you can use the --no-backup
flag.
If you find that tables were dropped erroneously, you can restore them in your site’s database using a separate command, partial-restore
.
Conclusion
The trim-database
feature is a powerful tool in the Empress suite that enables developers to maintain clean and efficient database structures by removing redundant tables. With the detailed explanation provided in this guide, developers should be able to effectively integrate this feature into their workflow and use it to optimize their software development and customization process.