fix(database): move database file to storage dir
This commit is contained in:
@@ -1,10 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
|
|
||||||
"tomatentum.net/svg-templater/internal/command"
|
"tomatentum.net/svg-templater/internal/command"
|
||||||
"tomatentum.net/svg-templater/internal/database"
|
|
||||||
"tomatentum.net/svg-templater/pkg/format"
|
"tomatentum.net/svg-templater/pkg/format"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,12 +9,6 @@ func main() {
|
|||||||
if !format.CheckInkscape() {
|
if !format.CheckInkscape() {
|
||||||
panic("Inkscape not found")
|
panic("Inkscape not found")
|
||||||
}
|
}
|
||||||
if err := database.OpenSQLite(); err != nil {
|
|
||||||
log.Fatal("Failed opening DB:\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer database.Close()
|
|
||||||
database.InitDB()
|
|
||||||
command.PrepareCommandLine()
|
command.PrepareCommandLine()
|
||||||
command.HandleCommandline()
|
command.HandleCommandline()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"tomatentum.net/svg-templater/internal/database"
|
||||||
"tomatentum.net/svg-templater/internal/server"
|
"tomatentum.net/svg-templater/internal/server"
|
||||||
"tomatentum.net/svg-templater/pkg/svg"
|
"tomatentum.net/svg-templater/pkg/svg"
|
||||||
)
|
)
|
||||||
@@ -23,6 +25,17 @@ func PrepareCommandLine() {
|
|||||||
|
|
||||||
func HandleCommandline() {
|
func HandleCommandline() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if !help {
|
||||||
|
svg.Storage = svg.NewFileStorage(datapath, "public")
|
||||||
|
if err := database.OpenSQLite(datapath); err != nil {
|
||||||
|
log.Fatal("Failed opening DB:\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
database.InitDB()
|
||||||
|
}
|
||||||
|
defer database.Close()
|
||||||
|
|
||||||
if generateTokenFlag {
|
if generateTokenFlag {
|
||||||
GenerateTokenCommand()
|
GenerateTokenCommand()
|
||||||
} else if deleteTokenFlag {
|
} else if deleteTokenFlag {
|
||||||
@@ -30,7 +43,6 @@ func HandleCommandline() {
|
|||||||
} else if help {
|
} else if help {
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
} else {
|
} else {
|
||||||
svg.Storage = svg.NewFileStorage(datapath, "public")
|
|
||||||
server.PrepareHTTP()
|
server.PrepareHTTP()
|
||||||
server.Start()
|
server.Start()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package database
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"log"
|
"log"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
_ "github.com/glebarez/go-sqlite"
|
_ "github.com/glebarez/go-sqlite"
|
||||||
)
|
)
|
||||||
@@ -11,8 +12,8 @@ const FILENAME string = "storage.db"
|
|||||||
|
|
||||||
var database *sql.DB
|
var database *sql.DB
|
||||||
|
|
||||||
func OpenSQLite() error {
|
func OpenSQLite(basepath string) error {
|
||||||
db, err := sql.Open("sqlite", FILENAME)
|
db, err := sql.Open("sqlite", filepath.Join(basepath, FILENAME))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user