mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-18 11:46:23 -07:00
Add stubs for pre-2021 staff migration
This commit is contained in:
parent
b0635b15f6
commit
1dc22b6571
7 changed files with 80 additions and 23 deletions
|
@ -69,28 +69,26 @@ type DBMigrator interface {
|
|||
// logging any errors that occur during the migration
|
||||
MigrateDB() (bool, error)
|
||||
|
||||
// MigrateBoards gets info about the old boards in the board table and inserts each one
|
||||
// into the new database if they don't already exist
|
||||
// MigrateBoards migrates the board sections (if they exist) and boards if each one
|
||||
// doesn't already exists
|
||||
MigrateBoards() error
|
||||
|
||||
// MigratePosts gets the threads and replies in the old database, and inserts them into
|
||||
// the new database, creating new threads to avoid putting replies in threads that already
|
||||
// exist
|
||||
// MigratePosts gets the threads and replies (excluding deleted ones) in the old database, and inserts them into
|
||||
// the new database, creating new threads to avoid putting replies in threads that already exist
|
||||
MigratePosts() error
|
||||
|
||||
// MigrateStaff gets the staff list in the old board and inserts them into the new board if
|
||||
// the username doesn't already exist. It sets the starting password to the given password
|
||||
MigrateStaff(password string) error
|
||||
// the username doesn't already exist. Migrated staff accounts will need to have their password reset
|
||||
// in order to be logged into
|
||||
MigrateStaff() error
|
||||
|
||||
// MigrateBans gets the list of bans and appeals in the old database and inserts them into the
|
||||
// new one if, for each entry, the IP/name/etc isn't already banned for the same length
|
||||
// e.g. 1.1.1.1 is permabanned on both, 1.1.2.2 is banned for 5 days on both, etc
|
||||
// MigrateBans migrates IP bans, appeals, and filters
|
||||
MigrateBans() error
|
||||
|
||||
// MigrateAnnouncements gets the list of public and staff announcements in the old database
|
||||
// and inserts them into the new database,
|
||||
// and inserts them into the new database
|
||||
MigrateAnnouncements() error
|
||||
|
||||
// Close closes the database if initialized and deltes the temporary columns created
|
||||
// Close closes the database if initialized and deletes any temporary columns created
|
||||
Close() error
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ type filenameOrUsernameBanBase struct {
|
|||
StaffID int // sql: staff_id
|
||||
StaffNote string // sql: staff_note
|
||||
IssuedAt time.Time // sql: issued_at
|
||||
check string // replaced with username or filename
|
||||
IsRegex bool // sql: is_regex
|
||||
}
|
||||
|
||||
|
|
|
@ -475,7 +475,7 @@ func (*GCDatabaseUpdater) MigratePosts() error {
|
|||
return gcutil.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (*GCDatabaseUpdater) MigrateStaff(_ string) error {
|
||||
func (*GCDatabaseUpdater) MigrateStaff() error {
|
||||
return gcutil.ErrNotImplemented
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,9 @@ type migrationSection struct {
|
|||
}
|
||||
|
||||
func (m *Pre2021Migrator) migrateSectionsInPlace() error {
|
||||
return common.NewMigrationError("pre2021", "migrateSectionsInPlace not implemented")
|
||||
err := common.NewMigrationError("pre2021", "migrateSectionsInPlace not implemented")
|
||||
common.LogError().Err(err).Caller().Msg("Failed to migrate sections")
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *Pre2021Migrator) migrateBoardsInPlace() error {
|
||||
|
|
|
@ -83,12 +83,15 @@ func (m *Pre2021Migrator) MigrateDB() (bool, error) {
|
|||
return false, err
|
||||
}
|
||||
common.LogInfo().Msg("Migrated boards successfully")
|
||||
|
||||
if err = m.MigratePosts(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
// if err = m.MigrateStaff("password"); err != nil {
|
||||
// return false, err
|
||||
// }
|
||||
common.LogInfo().Msg("Migrated threads, posts, and uploads successfully")
|
||||
|
||||
if err = m.MigrateStaff(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if err = m.MigrateBans(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -99,12 +102,8 @@ func (m *Pre2021Migrator) MigrateDB() (bool, error) {
|
|||
return true, nil
|
||||
}
|
||||
|
||||
func (*Pre2021Migrator) MigrateStaff(_ string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (*Pre2021Migrator) MigrateAnnouncements() error {
|
||||
return nil
|
||||
return common.NewMigrationError("pre2021", "MigrateAnnouncements not yet implemented")
|
||||
}
|
||||
|
||||
func (m *Pre2021Migrator) Close() error {
|
||||
|
|
36
cmd/gochan-migration/internal/pre2021/staff.go
Normal file
36
cmd/gochan-migration/internal/pre2021/staff.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package pre2021
|
||||
|
||||
import (
|
||||
"github.com/gochan-org/gochan/cmd/gochan-migration/internal/common"
|
||||
"github.com/gochan-org/gochan/pkg/gcsql"
|
||||
)
|
||||
|
||||
type migrationStaff struct {
|
||||
gcsql.Staff
|
||||
|
||||
oldID int
|
||||
boardIDs []int
|
||||
}
|
||||
|
||||
func (*Pre2021Migrator) migrateStaffInPlace() error {
|
||||
err := common.NewMigrationError("pre2021", "migrateSectionsInPlace not yet implemented")
|
||||
common.LogError().Err(err).Caller().Msg("Failed to migrate sections")
|
||||
return err
|
||||
}
|
||||
|
||||
func (*Pre2021Migrator) migrateStaffToNewDB() error {
|
||||
errEv := common.LogError()
|
||||
defer errEv.Discard()
|
||||
|
||||
err := common.NewMigrationError("pre2021", "migrateStaffToNewDB not yet implemented")
|
||||
errEv.Err(err).Caller().Msg("Failed to migrate sections")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *Pre2021Migrator) MigrateStaff() error {
|
||||
if m.IsMigratingInPlace() {
|
||||
return m.migrateStaffInPlace()
|
||||
}
|
||||
return m.migrateStaffToNewDB()
|
||||
}
|
23
cmd/gochan-migration/internal/pre2021/staff_test.go
Normal file
23
cmd/gochan-migration/internal/pre2021/staff_test.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package pre2021
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMigrateStaffToNewDB(t *testing.T) {
|
||||
outDir := t.TempDir()
|
||||
migrator := setupMigrationTest(t, outDir, false)
|
||||
if !assert.False(t, migrator.IsMigratingInPlace(), "This test should not be migrating in place") {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
if !assert.NoError(t, migrator.MigrateBoards()) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
if !assert.NoError(t, migrator.MigrateStaff()) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue