π The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
Implement data migration
Smaug6739f9d34e11d434
diff --git a/backend/app/app.go b/backend/app/app.goindex 2283a11d..0ec5a8eb 100644--- a/backend/app/app.go+++ b/backend/app/app.go@@ -4,6 +4,7 @@ import ("alexandrie/services""alexandrie/utils""database/sql"+ "fmt"_ "github.com/go-sql-driver/mysql""github.com/minio/minio-go/v7"@@ -62,5 +63,31 @@ func InitApp(config Config) *App {}Migrate(&config)+ DB_DATA_MIGRATION(app.DB)return &app}++// This function is used to migrate the database+// It will be called when the application is started+func DB_DATA_MIGRATION(db *sql.DB) {+ // Select all categories with "workspace_id" not empty+ rows, err := db.Query("SELECT id, workspace_id FROM categories WHERE workspace_id IS NOT NULL")+ if err != nil {+ panic(err.Error())+ }+ defer rows.Close()+ // Iterate over the rows+ for rows.Next() {+ var id int+ var workspace_id string+ if err := rows.Scan(&id, &workspace_id); err != nil {+ panic(err.Error())+ }+ // Update the category with the new workspace_id+ _, err = db.Exec("UPDATE categories SET parent_id = ? WHERE id = ?", workspace_id, id)+ if err != nil {+ panic(err.Error())+ }+ }+ fmt.Println("β Database migration completed successfully")+}