pihole-cloudsync icon indicating copy to clipboard operation
pihole-cloudsync copied to clipboard

Fix bugs when importing from git repo

Open mgamlem3 opened this issue 2 years ago • 3 comments

TL;DR:

  • Only modify domainlist table if there is content in domainlist.csv
  • Switch DROP TABLE to DELETE FROM
  • Skip first row when importing from csv
  • Add some semicolons

DROP vs DELETE

This addresses issue #40. An explanation can be seen in this comment on the issue. Essentially, dropping the table is more destructive than what is needed when replacing the entries with the data from the csv files saved in git. Using the DELETE command preserves references, triggers, and other important information on the table.

Only modify if there is csv content

I was running into issues where the script would crash if there was no content in domainlist.csv and the script tried to import from it. Obviously, if there is no content in the file it doesn't need to be imported so I just added a check to see if there is anything in the file before attempting an import and modifying the table.

Ignore first line of csv when importing

The first line of the csv file should contain the column names from the SQL table. Skipping this line prevents errors and warnings when importing.

Add some semicolons

I was running into some strange issues with the if statements while making changes and adding these semicolons seemed to solve them.

mgamlem3 avatar Jul 25 '22 23:07 mgamlem3

@mgamlem3 Can you take a peek and see what's conflicting with your merge request? I'm reactivating this project after a long pause. Thanks for your great help!

stevejenkins avatar Nov 21 '23 16:11 stevejenkins

@stevejenkins it looked like some of the other changes you merged modified the same lines I did. I went ahead and resolved the conflicts while preserving my changes.

mgamlem3 avatar Nov 22 '23 01:11 mgamlem3

Also, this should close issue #40.

mgamlem3 avatar Nov 22 '23 01:11 mgamlem3