mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: support mysql as backend storage driver (#2300)
* Rename checkDSN to checkDataDir * Add option to set DSN and db driver * Add mysql driver skeleton * Add mysql container in compose for debug * Add basic function for mysql driver * Cleanup go mod with tidy * Cleanup go.sum with tidy * Add DeleteUser support for mysql driver * Fix UpdateUser of mysql driver * Add DeleteTag support for mysql driver * Add DeleteResource support for mysql driver * Add UpdateMemo and DeleteMemo support for mysql driver * Add MemoRelation support for mysql driver * Add MemoOrganizer support for mysql driver * Add Idp support for mysql driver * Add Storage support for mysql driver * Add FindMemosVisibilityList support for mysql driver * Add Vacuum support for mysql driver * Add Migration support for mysql driver * Add Migration support for mysql driver * Fix ListMemo failed with referece * Change Activity.CreateTs type in MySQL * Change User.CreateTs type in MySQL * Fix by golangci-lint * Change Resource.CreateTs type in MySQL * Change MigrationHistory.CreateTs type in MySQL * Change Memo.CreateTs type in MySQL
This commit is contained in:
@@ -24,7 +24,9 @@ type Profile struct {
|
||||
// Data is the data directory
|
||||
Data string `json:"-"`
|
||||
// DSN points to where Memos stores its own data
|
||||
DSN string `json:"-"`
|
||||
DSN string `json:"dsn"`
|
||||
// Driver is the database driver
|
||||
Driver string `json:"driver"`
|
||||
// Version is the current version of server
|
||||
Version string `json:"version"`
|
||||
}
|
||||
@@ -33,7 +35,7 @@ func (p *Profile) IsDev() bool {
|
||||
return p.Mode != "prod"
|
||||
}
|
||||
|
||||
func checkDSN(dataDir string) (string, error) {
|
||||
func checkDataDir(dataDir string) (string, error) {
|
||||
// Convert to absolute path if relative path is supplied.
|
||||
if !filepath.IsAbs(dataDir) {
|
||||
relativeDir := filepath.Join(filepath.Dir(os.Args[0]), dataDir)
|
||||
@@ -81,15 +83,17 @@ func GetProfile() (*Profile, error) {
|
||||
}
|
||||
}
|
||||
|
||||
dataDir, err := checkDSN(profile.Data)
|
||||
dataDir, err := checkDataDir(profile.Data)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to check dsn: %s, err: %+v\n", dataDir, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
profile.Data = dataDir
|
||||
dbFile := fmt.Sprintf("memos_%s.db", profile.Mode)
|
||||
profile.DSN = filepath.Join(dataDir, dbFile)
|
||||
if profile.Driver == "sqlite" && profile.DSN == "" {
|
||||
dbFile := fmt.Sprintf("memos_%s.db", profile.Mode)
|
||||
profile.DSN = filepath.Join(dataDir, dbFile)
|
||||
}
|
||||
profile.Version = version.GetCurrentVersion(profile.Mode)
|
||||
|
||||
return &profile, nil
|
||||
|
Reference in New Issue
Block a user