fix make table order

This commit is contained in:
2025-01-23 06:41:40 -06:00
parent 3c0b3c04b7
commit 536894c7dd

View File

@@ -5,6 +5,7 @@ import (
"database/sql"
_ "embed"
"flag"
"fmt"
"git.infra.nkode.tech/dkelly/nkode-core/repository"
"git.infra.nkode.tech/dkelly/nkode-core/sqlite"
_ "github.com/mattn/go-sqlite3"
@@ -21,17 +22,23 @@ func main() {
commandLine := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
dbPath := commandLine.String("db-path", "", "Path to the database")
svgPath := commandLine.String("svg-path", "", "Path to the SVG directory")
ctx := context.Background()
sqliteRepo, err := repository.NewSqliteRepository(*dbPath, ctx)
err = commandLine.Parse(os.Args[1:])
if err != nil {
if err = commandLine.Parse(os.Args[1:]); err != nil {
log.Fatalf("Failed to parse flags: %v", err)
}
if err = MakeTables(*dbPath, string(sqliteSchema)); err != nil {
log.Fatal(err)
}
ctx := context.Background()
sqliteRepo, err := repository.NewSqliteRepository(*dbPath, ctx)
sqliteRepo.Start()
defer func(sqliteRepo *repository.SqliteRepository) {
if err := sqliteRepo.Stop(); err != nil {
log.Fatal(err)
}
}(sqliteRepo)
FlaticonToSqlite(sqliteRepo, *svgPath)
fmt.Sprintf("Successfully added all SVGs in %s to the database at %s", *svgPath, *dbPath)
}
func FlaticonToSqlite(repo *repository.SqliteRepository, svgDir string) {
@@ -60,7 +67,6 @@ func FlaticonToSqlite(repo *repository.SqliteRepository, svgDir string) {
}
func MakeTables(dbPath string, schema string) error {
// check if the database file and path exists. make them if they don't
if _, err := os.Stat(dbPath); os.IsNotExist(err) {
if err = os.MkdirAll(filepath.Dir(dbPath), 0755); err != nil {
return err
@@ -73,9 +79,8 @@ func MakeTables(dbPath string, schema string) error {
if err != nil {
return err
}
defer db.Close()
if _, err = db.Exec(schema); err != nil {
return err
}
return nil
return db.Close()
}