Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

Update migrations.go

louloudev59cfb7dc022056
diff --git a/backend/app/migrations.go b/backend/app/migrations.go
index 12b7a25e..659aaf90 100644
--- a/backend/app/migrations.go
+++ b/backend/app/migrations.go
@@ -4,6 +4,8 @@ import (
"fmt"
"os"
"path/filepath"
+ "runtime"
+ "strings"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/mysql"
@@ -13,23 +15,30 @@ import (
func Migrate(config *Config) {
workingDir, _ := os.Getwd()
- absPath := filepath.Join(workingDir, os.Getenv("CONFIG_CPWD"), "migrations")
+ configCpwd := os.Getenv("CONFIG_CPWD")
+ if configCpwd == "" {
+ configCpwd = ""
+ }
+ absPath := filepath.Join(workingDir, configCpwd, "migrations")
+
+ if runtime.GOOS == "windows" {
+ absPath = strings.ReplaceAll(absPath, "\\", "/")
+ }
- db := DBConection(*config, true) // Use multiStatements for migration
+ db := DBConection(*config, true)
defer db.Close()
-
- // Test the database connection
+
if err := db.Ping(); err != nil {
panic(fmt.Sprintf("failed to ping database: %v", err))
}
-
+
driver, err := mysql.WithInstance(db, &mysql.Config{
MigrationsTable: "schema_migrations",
})
if err != nil {
panic(fmt.Sprintf("failed to create mysql driver: %v", err))
}
-
+
m, err := migrate.NewWithDatabaseInstance(
fmt.Sprintf("file://%s", absPath),
"mysql",