Skip to content

Commit e1e106b

Browse files
authored
feat: don't add to existing DBs by default. (#2)
This tool is presently built around the idea that it translates one OBJ_DUMP file into one DB. It gets confusing if you were to run the tool twice with the same arguments. Prior to this commit it would in fact add the same contents twice and 2x the data without any clear indication that it was two separate imports. In this commit we add a `-force` flag that defaults to false. If given a `-db` path that already exists, but `-force` is not true, then an error is printed about the existing db and we abort. If `-force` is true, then we assume the user knows what they are doing and we add the file's rows to the existing DB.
1 parent a41c903 commit e1e106b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

main.go

+7
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ func infoPrint(msg string, args ...interface{}) {
1919

2020
func main() {
2121
dbFile := flag.String("db", "OBJ_DUMP.sqlite", "SQLite Database file path to populate")
22+
forceFlag := flag.Bool("force", false, "Add OBJ_DUMP data to an existing database")
2223
flag.Parse()
2324

25+
if _, err := os.Stat(*dbFile); err == nil && !(*forceFlag) {
26+
errPrint(
27+
"db %q exists and -force was not specified. Remove the database or add -force\n",
28+
*dbFile)
29+
}
30+
2431
// Open the database.
2532
db, err := openDB(*dbFile)
2633
if err != nil {

0 commit comments

Comments
 (0)