|
1 | 1 | # Database_Difference_Checker-Python_SQLite |
2 | | -Python script to read SQLite files and check the differences between them |
| 2 | +Python script to read SQLite files and check the differences between them. |
| 3 | + |
| 4 | +## Before you start! |
| 5 | +This document provides a step-by-step guide to performing comparison between SQLite databases using the `Database_Difference_Checker-Python_SQLite` script. |
| 6 | + |
| 7 | +## Instructions for Use |
| 8 | +### 1. Using filters for tables and/or columns _(Optional Step)_ |
| 9 | +- **Table Filters**: Edit the `constants/general.py` file and add the names of the tables you want to exclude from the comparison within the `EXCLUDED_TABLES` constant. |
| 10 | + #### Example: |
| 11 | + ``` |
| 12 | + EXCLUDED_TABLES = {"table1", "table2", "table3"} |
| 13 | + ``` |
| 14 | +- **Column Filters**: Edit the same file and add the names of the columns to be excluded from the comparison within the `EXCLUDED_COLUMNS` constant. |
| 15 | + #### Example: |
| 16 | + ``` |
| 17 | + EXCLUDED_COLUMNS = {"column1", "column2", "column3"} |
| 18 | + ``` |
| 19 | + |
| 20 | +### 2. Adding SQLite databases for comparison |
| 21 | +Place the SQLite `(.db)` files you want to compare inside the `MOCK/DATA` folder. |
| 22 | + |
| 23 | +- For contexts of different databases _(for example, databases from different companies)_, it is ideal, but not mandatory, to organize the databases in different folders within `MOCK/DATA`. |
| 24 | + #### Example: |
| 25 | +  |
| 26 | + |
| 27 | +### 3. Adding the reference file |
| 28 | +Add the file with the reference data to the `MOCK/PATTERN` folder. **The reference file can be in `.txt`, `.json`, `.sqlite` or `.db` format**. |
| 29 | + |
| 30 | +### **Important** |
| 31 | +- **The `.sqlite` and `.db` files take precedence over the others** |
| 32 | +- The file must follow the pattern **_key-value_** _(key: value)_, with the **VALUE ALWAYS WRAPPED IN BRACKETS**. |
| 33 | + #### Examples for text file `(.txt)`: |
| 34 | + - **Example 1 (without line break):** |
| 35 | + ``` |
| 36 | + TABLE_1:[{...}]TABLE_2:[...]TABLE_3:[...] |
| 37 | + ``` |
| 38 | + - **Example 2 (with line break):** |
| 39 | + ``` |
| 40 | + TABLE_1:[{...}, {...}] |
| 41 | + TABLE_2:[{...}] |
| 42 | + TABLE_3:[...] |
| 43 | + ``` |
| 44 | + #### Example for JSON file `(.json)`: |
| 45 | + ``` |
| 46 | + { |
| 47 | + "TABLE_1": [ |
| 48 | + { |
| 49 | + "name": "XXXX", |
| 50 | + "type": "XXXX" |
| 51 | + }, |
| 52 | + { |
| 53 | + "name": "XXXX", |
| 54 | + "type": "XXXX" |
| 55 | + } |
| 56 | + ], |
| 57 | + "TABLE_2": [ |
| 58 | + { |
| 59 | + "name": "XXXX", |
| 60 | + "type": "XXXX" |
| 61 | + } |
| 62 | + ], |
| 63 | + ... |
| 64 | + } |
| 65 | + ``` |
| 66 | +
|
| 67 | +### 4. Analysis of Results |
| 68 | +After executing the script, check the `trackingCode`. The code `00` indicates that the process completed without errors (other tracking codes in the section below). |
| 69 | +
|
| 70 | +**The comparison results will be saved in a JSON file in the project root folder, called `Output.json` .** |
| 71 | +
|
| 72 | +#### Example of `Output.json` file: |
| 73 | +``` |
| 74 | +{ |
| 75 | + "MAIN_DATABASE_1": { |
| 76 | + "DATABASE_SQLite_1": { |
| 77 | + "Missing_Tables": [...], |
| 78 | + "Missing_Data": { |
| 79 | + "TABLE_1": [ |
| 80 | + { |
| 81 | + "name": "XXXX", |
| 82 | + "type": "XXXX" |
| 83 | + } |
| 84 | + ], |
| 85 | + "TABLE_2": [...] |
| 86 | + } |
| 87 | + }, |
| 88 | + "DATABASE_SQLite_2": {...} |
| 89 | + }, |
| 90 | + "MAIN_DATABASE_2": {...} |
| 91 | +} |
| 92 | +``` |
| 93 | +
|
| 94 | +## Tracking Codes |
| 95 | +
|
| 96 | +Tracking codes indicate the status of the process: |
| 97 | +
|
| 98 | +- `00`: **Finished without errors** |
| 99 | +- `01`: **An unexpected error occurred** |
| 100 | +- `02`: **Error reading file(s)** |
| 101 | +- `03`: **Error reading file(s) from directory** |
| 102 | +- `04`: **Error in the comparison process** |
| 103 | +- `05`: **Error generating `Output.json` file** |
| 104 | +- `06`: **Error reading data from databases** |
| 105 | +- `07`: **Error generating JSON from databases** |
| 106 | +- `08`: **Error when fetching JSON files from databases** |
| 107 | +- `09`: **Error creating reference JSON** |
| 108 | +- `10`: **Invalid file extension** |
| 109 | +
|
| 110 | +## 🛠 Used Packages |
| 111 | +
|
| 112 | +| Name | Version | |
| 113 | +| :-------- | :------ | |
| 114 | +| 🐍 Python | `3.8.0` | |
| 115 | +
|
| 116 | +## 🔗 Links |
| 117 | +
|
| 118 | +[](https://github.com/GabrielTorelo/Database_Difference_Checker-Python_SQLite) |
0 commit comments