mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-09-04 10:06:24 -07:00
Don't automatically move the files
This may eventually change so files can be moved or copied in the future
This commit is contained in:
parent
64123e8e6b
commit
74b5c38fe6
4 changed files with 52 additions and 26 deletions
|
@ -7,6 +7,12 @@ import (
|
|||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
const (
|
||||
DirNoAction = iota
|
||||
DirCopy
|
||||
DirMove
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvalidSchema = errors.New("invalid database schema for old database")
|
||||
ErrUnsupportedDBType = errors.New("unsupported SQL driver, currently only MySQL and Postgres are supported")
|
||||
|
@ -39,6 +45,7 @@ type MigrationOptions struct {
|
|||
OldChanConfig string
|
||||
OldDBName string
|
||||
NewDBName string
|
||||
DirAction int
|
||||
}
|
||||
|
||||
// DBMigrator is used for handling the migration from one database type to a
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package pre2021
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/gochan-org/gochan/pkg/config"
|
||||
"github.com/gochan-org/gochan/pkg/gclog"
|
||||
"github.com/gochan-org/gochan/pkg/gcsql"
|
||||
)
|
||||
|
@ -127,19 +123,22 @@ func (m *Pre2021Migrator) MigrateBoards() error {
|
|||
return err
|
||||
}
|
||||
gclog.Printf(gclog.LStdLog, "/%s/ successfully migrated in the database")
|
||||
// switch m.options.DirAction {
|
||||
// case common.DirCopy:
|
||||
|
||||
// move the old directory (probably should copy instead) to the new one
|
||||
newDocumentRoot := config.GetSystemCriticalConfig().DocumentRoot
|
||||
gclog.Println(gclog.LStdLog, "Old board path:", path.Join(m.config.DocumentRoot, dir))
|
||||
gclog.Println(gclog.LStdLog, "Old board path:", path.Join(newDocumentRoot, dir))
|
||||
if err = os.Rename(
|
||||
path.Join(m.config.DocumentRoot, dir),
|
||||
path.Join(newDocumentRoot, dir),
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
gclog.Printf(gclog.LStdLog, "/%s/ directory/files successfully moved")
|
||||
// case common.DirMove:
|
||||
// // move the old directory (probably should copy instead) to the new one
|
||||
// newDocumentRoot := config.GetSystemCriticalConfig().DocumentRoot
|
||||
// gclog.Println(gclog.LStdLog, "Old board path:", path.Join(m.config.DocumentRoot, dir))
|
||||
// gclog.Println(gclog.LStdLog, "Old board path:", path.Join(newDocumentRoot, dir))
|
||||
// if err = os.Rename(
|
||||
// path.Join(m.config.DocumentRoot, dir),
|
||||
// path.Join(newDocumentRoot, dir),
|
||||
// ); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// gclog.Printf(gclog.LStdLog, "/%s/ directory/files successfully moved")
|
||||
// }
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -95,5 +95,5 @@ func (m *Pre2021Migrator) Close() error {
|
|||
if m.db != nil {
|
||||
return m.db.Close()
|
||||
}
|
||||
return gcsql.Close()
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
|
||||
"github.com/gochan-org/gochan/cmd/gochan-migration/internal/common"
|
||||
"github.com/gochan-org/gochan/cmd/gochan-migration/internal/pre2021"
|
||||
|
@ -18,7 +17,14 @@ several changes before it can be considered "stable", so make sure you check
|
|||
the README and/or the -h command line flag before you use it.
|
||||
|
||||
`
|
||||
fatalLogFlags = gclog.LFatal | gclog.LErrorLog | gclog.LStdLog
|
||||
migrateCompleteTxt = `Database migration successful!
|
||||
To migrate the uploads for each board, move or copy the uploads to /path/to/gochan/document/root/<boardname>/src/
|
||||
Then copy the thumbnails to /path/to/gochan/documentroot/<boardname>/thumb/
|
||||
Then start the gochan server and go to http://yoursite/manage?action=rebuildall to generate the html files
|
||||
for the threads and board pages`
|
||||
|
||||
fatalLogFlags = gclog.LFatal | gclog.LErrorLog | gclog.LStdLog
|
||||
allowedDirActions = "Valid values are noaction, copy, and move (defaults to noaction if unset)"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -29,17 +35,31 @@ func main() {
|
|||
var options common.MigrationOptions
|
||||
|
||||
config.InitConfig(versionStr)
|
||||
|
||||
var dirAction string
|
||||
flag.StringVar(&options.ChanType, "oldchan", "", "The imageboard we are migrating from (currently only pre2021 is supported, but more are coming")
|
||||
flag.StringVar(&options.OldChanConfig, "oldconfig", "", "The path to the old chan's configuration file")
|
||||
/* flag.StringVar(&dirAction, "diraction", "",
|
||||
"Action taken on each board directory after it has been migrated. "+allowedDirActions) */
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if options.ChanType == "" || options.OldChanConfig == "" {
|
||||
flag.PrintDefaults()
|
||||
gclog.Println(fatalLogFlags, "Missing required database connection info")
|
||||
os.Exit(1)
|
||||
gclog.Println(fatalLogFlags, "Missing required oldchan value")
|
||||
return
|
||||
}
|
||||
switch dirAction {
|
||||
case "":
|
||||
fallthrough
|
||||
case "noaction":
|
||||
options.DirAction = common.DirNoAction
|
||||
case "copy":
|
||||
options.DirAction = common.DirCopy
|
||||
case "move":
|
||||
options.DirAction = common.DirMove
|
||||
default:
|
||||
gclog.Println(fatalLogFlags, "Invalid diraction value. "+allowedDirActions)
|
||||
}
|
||||
|
||||
gclog.Printf(gclog.LAccessLog, banner, versionStr)
|
||||
var migrator common.DBMigrator
|
||||
|
@ -54,7 +74,7 @@ func main() {
|
|||
gclog.Printf(fatalLogFlags,
|
||||
"Unsupported chan type %q, Currently only pre2021 database migration is supported\n",
|
||||
options.ChanType)
|
||||
os.Exit(1)
|
||||
return
|
||||
}
|
||||
config.InitConfig(versionStr)
|
||||
systemCritical := config.GetSystemCriticalConfig()
|
||||
|
@ -69,12 +89,12 @@ func main() {
|
|||
if err != nil {
|
||||
gclog.Printf(fatalLogFlags,
|
||||
"Unable to initialize %s migrator: %s\n", options.ChanType, err.Error())
|
||||
os.Exit(1)
|
||||
return
|
||||
}
|
||||
defer migrator.Close()
|
||||
if err = migrator.MigrateDB(); err != nil {
|
||||
gclog.Printf(fatalLogFlags, "Error migrating database: ", err.Error())
|
||||
os.Exit(1)
|
||||
return
|
||||
}
|
||||
gclog.Println(gclog.LStdLog, "Database migration successful!")
|
||||
gclog.Println(gclog.LStdLog, migrateCompleteTxt)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue