Skip to content

Commit

Permalink
refactor: store migrator
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Aug 16, 2024
1 parent 1ae3afc commit 6e901fc
Show file tree
Hide file tree
Showing 82 changed files with 1,494 additions and 402 deletions.
9 changes: 2 additions & 7 deletions bin/memos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,11 @@ var (
slog.Error("failed to create db driver", "error", err)
return
}
if err := dbDriver.Migrate(ctx); err != nil {
cancel()
slog.Error("failed to migrate database", "error", err)
return
}

storeInstance := store.New(dbDriver, instanceProfile)
if err := storeInstance.MigrateManually(ctx); err != nil {
if err := storeInstance.Migrate(ctx); err != nil {
cancel()
slog.Error("failed to migrate manually", "error", err)
slog.Error("failed to migrate", "error", err)
return
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/.air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ root = "."
tmp_dir = ".air"

[build]
bin = "./.air/memos --mode dev --public true"
bin = "./.air/memos --mode demo --public true"
cmd = "go build -o ./.air/memos ./bin/memos/main.go"
delay = 1000
exclude_dir = [".air", "web", "build"]
Expand Down
167 changes: 0 additions & 167 deletions store/db/mysql/migrator.go

This file was deleted.

28 changes: 2 additions & 26 deletions store/db/mysql/mysql.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package mysql

import (
"context"
"database/sql"
"log/slog"

"github.com/go-sql-driver/mysql"
"github.com/pkg/errors"
Expand Down Expand Up @@ -45,30 +43,8 @@ func (d *DB) GetDB() *sql.DB {
return d.db
}

func (d *DB) GetCurrentDBSize(ctx context.Context) (int64, error) {
query := "SELECT SUM(`data_length` + `index_length`) AS `size` " +
" FROM information_schema.TABLES" +
" WHERE `table_schema` = ?" +
" GROUP BY `table_schema`"
rows, err := d.db.QueryContext(ctx, query, d.config.DBName)
if err != nil {
slog.Error("Query db size error, make sure you have enough privilege", "error", err)
return 0, err
}
defer rows.Close()

var size int64
for rows.Next() {
if err := rows.Scan(&size); err != nil {
return 0, err
}
}

if rows.Err() != nil {
return 0, rows.Err()
}

return size, nil
func (d *DB) Type() string {

Check failure on line 46 in store/db/mysql/mysql.go

View workflow job for this annotation

GitHub Actions / go-static-checks

unused-receiver: method receiver 'd' is not referenced in method's body, consider removing or renaming it as _ (revive)
return "mysql"
}

func (d *DB) Close() error {
Expand Down
Loading

0 comments on commit 6e901fc

Please sign in to comment.