Fix data directory not creating on first run

This commit is contained in:
Marco Realacci 2022-12-22 16:40:57 +01:00
parent ec0b06affc
commit 7543fd36e0
3 changed files with 16 additions and 7 deletions

View file

@ -120,6 +120,14 @@ func run() error {
logger.WithError(err).Error("error creating the API server instance") logger.WithError(err).Error("error creating the API server instance")
return fmt.Errorf("creating the API server instance: %w", err) return fmt.Errorf("creating the API server instance: %w", err)
} }
// Create the directories if they don't exist
if err := os.MkdirAll(cfg.Data.Path, 0755); err != nil {
logger.WithError(err).Error("error creating data directory")
return fmt.Errorf("creating data directory: %w", err)
}
router := apirouter.Handler() router := apirouter.Handler()
router, err = registerWebUI(router) router, err = registerWebUI(router)

View file

@ -98,8 +98,9 @@ func New(db *sql.DB) (AppDatabase, error) {
// Check if tables exist. If not, the database is empty, and we need to create the structure // Check if tables exist. If not, the database is empty, and we need to create the structure
var tableName string var tableName string
//todo: check for all the tables, not just users //todo: check for all the tables, not just users
err := db.QueryRow(`SELECT name FROM sqlite_master WHERE type='table' AND name='users';`).Scan(&tableName) err := db.QueryRow(`SELECT uid from users LIMIT 1;`).Scan(&tableName)
if errors.Is(err, sql.ErrNoRows) { if err != nil {
//fmt.Println("database is empty, creating structure")
sqlStmt := `CREATE TABLE "users" ( sqlStmt := `CREATE TABLE "users" (
"uid" TEXT NOT NULL, "uid" TEXT NOT NULL,
"name" TEXT NOT NULL UNIQUE, "name" TEXT NOT NULL UNIQUE,

View file

@ -1,23 +1,23 @@
{ {
"hash": "0c3e4771", "hash": "80447977",
"browserHash": "01248067", "browserHash": "b98131b5",
"optimized": { "optimized": {
"axios": { "axios": {
"src": "../../axios/index.js", "src": "../../axios/index.js",
"file": "axios.js", "file": "axios.js",
"fileHash": "d8d02cf0", "fileHash": "6b5eae63",
"needsInterop": true "needsInterop": true
}, },
"vue": { "vue": {
"src": "../../vue/dist/vue.runtime.esm-bundler.js", "src": "../../vue/dist/vue.runtime.esm-bundler.js",
"file": "vue.js", "file": "vue.js",
"fileHash": "f8034b26", "fileHash": "de50261f",
"needsInterop": false "needsInterop": false
}, },
"vue-router": { "vue-router": {
"src": "../../vue-router/dist/vue-router.mjs", "src": "../../vue-router/dist/vue-router.mjs",
"file": "vue-router.js", "file": "vue-router.js",
"fileHash": "b4ca170f", "fileHash": "4cad12d6",
"needsInterop": false "needsInterop": false
} }
}, },