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:
Athurg Gooth
2023-09-28 22:09:52 +08:00
committed by GitHub
parent 4ca2b551f5
commit c72f221fc0
26 changed files with 2311 additions and 6 deletions

View File

@@ -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