1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-09-04 10:06:24 -07:00

Move post migration methods a separate file

This commit is contained in:
Eggbertx 2022-02-17 22:45:47 -08:00
parent 4379886647
commit 69fb7c9d31
4 changed files with 145 additions and 149 deletions

View file

@ -14,6 +14,7 @@ func (m *Pre2021Migrator) MigrateBoards() error {
// get boards from old db
rows, err := m.db.QuerySQL(`SELECT
id,
dir,
type,
upload_type,
@ -40,6 +41,7 @@ func (m *Pre2021Migrator) MigrateBoards() error {
return err
}
for rows.Next() {
var id int
var dir string
var board_type int
var upload_type int
@ -86,6 +88,9 @@ func (m *Pre2021Migrator) MigrateBoards() error {
}
found := false
for _, board := range boards {
if _, ok := m.oldBoards[id]; !ok {
m.oldBoards[id] = dir
}
if board.Dir == dir {
gclog.Printf(gclog.LStdLog, "Board /%s/ already exists in new db, moving on\n", dir)
found = true
@ -122,6 +127,7 @@ func (m *Pre2021Migrator) MigrateBoards() error {
}); err != nil {
return err
}
m.newBoards[id] = dir
gclog.Printf(gclog.LStdLog, "/%s/ successfully migrated in the database")
// switch m.options.DirAction {
// case common.DirCopy:

View file

@ -0,0 +1,135 @@
package pre2021
import (
"time"
"github.com/gochan-org/gochan/pkg/gclog"
)
type postTable struct {
id int
boardid int
parentid int
name string
tripcode string
email string
subject string
message string
message_raw string
password string
filename string
filename_original string
file_checksum string
filesize int
image_w int
image_h int
thumb_w int
thumb_h int
ip string
tag string
timestamp time.Time
autosage bool
deleted_timestamp time.Time
bumped time.Time
stickied bool
locked bool
reviewed bool
newBoardID int
newParentID int
}
func (m *Pre2021Migrator) MigratePosts() error {
var err error
if err = m.migrateThreads(); err != nil {
return err
}
return m.migratePostsUtil()
}
func (m *Pre2021Migrator) migrateThreads() error {
rows, err := m.db.QuerySQL(`SELECT
id,
boardid,
parentid,
name,
tripcode,
email,
subject,
message,
message_raw,
password,
filename,
filename_original,
file_checksum,
filesize,
image_w,
image_h,
thumb_w,
thumb_h,
ip,
tag,
timestamp,
autosage,
deleted_timestamp,
bumped,
stickied,
locked,
reviewed from DBPREFIXposts WHERE is_deleted = 0`)
if err != nil {
return err
}
for rows.Next() {
var post postTable
if err = rows.Scan(
&post.id,
&post.boardid,
&post.parentid,
&post.name,
&post.tripcode,
&post.email,
&post.subject,
&post.message,
&post.message_raw,
&post.password,
&post.filename,
&post.filename_original,
&post.file_checksum,
&post.filesize,
&post.image_w,
&post.image_h,
&post.thumb_w,
&post.thumb_h,
&post.ip,
&post.tag,
&post.timestamp,
&post.autosage,
&post.deleted_timestamp,
&post.bumped,
&post.stickied,
&post.locked,
&post.reviewed,
); err != nil {
return err
}
_, ok := m.oldBoards[post.boardid]
if !ok {
// board doesn't exist
gclog.Printf(gclog.LStdLog|gclog.LErrorLog, "Pre-migrated post #%d has an invalid boardid %d (board doesn't exist), skipping", post.id, post.boardid)
continue
}
// gcsql.QueryRowSQL(`SELECT id FROM DBPREFIXboards WHERE uri = ?`, []interface{}{})
m.posts = append(m.posts, post)
if post.parentid == 0 {
// post is a thread, save it to the DBPREFIXthreads table
}
}
return nil
}
func (m *Pre2021Migrator) migratePostsUtil() error {
return nil
}

View file

@ -32,6 +32,10 @@ type Pre2021Migrator struct {
db *gcsql.GCDB
options common.MigrationOptions
config Pre2021Config
posts []postTable
oldBoards map[int]string // map[boardid]dir
newBoards map[int]string // map[board]dir
}
func (m *Pre2021Migrator) readConfig() error {
@ -75,10 +79,6 @@ func (m *Pre2021Migrator) MigrateDB() error {
return nil
}
func (m *Pre2021Migrator) MigratePosts() error {
return nil
}
func (m *Pre2021Migrator) MigrateStaff(password string) error {
return nil
}

View file

@ -1,145 +0,0 @@
package pre2021
import (
"time"
"github.com/gochan-org/gochan/pkg/gcsql"
)
func GetPosts(db *gcsql.GCDB) ([]Post, error) {
rows, err := db.QuerySQL("SELECT id,boardid,parentid,name,tripcode,email,subject,message,message_raw,password,filename,filename_original,file_checksum,filesize,image_w,image_h,thumb_w,thumb_h,ip,tag,timestamp,autosage,deleted_timestamp,bumped,stickied,locked,reviewed FROM `gc_posts`")
if err != nil {
return nil, err
}
var posts []Post
for rows.Next() {
var post Post
err = rows.Scan(&post.ID, &post.BoardID, &post.ParentID, &post.Name, &post.Tripcode, &post.Email, &post.Subject, &post.MessageHTML, &post.MessageText, &post.Password, &post.Filename, &post.FilenameOriginal, &post.FileChecksum, &post.Filesize, &post.ImageW, &post.ImageH, &post.ThumbW, &post.ThumbH, &post.IP, &post.Capcode, &post.Timestamp, &post.Autosage, &post.DeletedTimestamp, &post.Bumped, &post.Stickied, &post.Locked, &post.Reviewed)
if err != nil {
return posts, err
}
posts = append(posts, post)
}
return posts, nil
}
// DBPREFIXannouncements
type Announcement struct {
ID uint // id: bigint
Subject string // subject: varchar
Message string // message: text
Poster string // poster: varchar
Timestamp time.Time // timestamp: timestamp
}
// DBPREFIXappeals
type BanAppeal struct {
ID int // id: bigint
Ban int // ban: int
Message string // message: text
Denied bool // denied: tinyint
Timestamp *time.Time // timestamp: timestamp
StaffResponse string // staff_response: text
}
// DBPREFIXbanlist
type BanInfo struct {
ID uint // id: bigint
AllowRead bool // allow_read: tinyint
IP string // ip: varchar
Name string // name: varchar
NameIsRegex bool // name_is_regex: tinyint
Filename string // filename: varchar
Checksum string // file_checksum: varchar
Boards string // boards: varchar
Staff string // staff: varchar
Timestamp time.Time // timestamp: timestamp
Expires time.Time // expires: timestamp
Permaban bool // permaban: tinyint
Reason string // reason: varchar
Type int // type: smallint
StaffNote string // staff_note: varchar
AppealAt time.Time // appeal_at: timestamp
CanAppeal bool // can_appeal: tinyint
}
// DBPREFIXboards
type Board struct {
ID int // id: bigint
ListOrder int // list_order: tinyint
Dir string // dir: varchar
Type int // type: tinyint
UploadType int // upload_type: tinyint
Title string // title: varchar
Subtitle string // subtitle: varchar
Description string // description: varchar
Section int // section: int
MaxFilesize int // max_file_size: int
MaxPages int // max_pages: tinyint
DefaultStyle string // default_style: varchar
Locked bool // locked: tinyint
CreatedOn time.Time // created_on: timestamp
Anonymous string // anonymous: varchar
ForcedAnon bool // forced_anon: tinyint
MaxAge int // max_age: int
AutosageAfter int // autosage_after: int
NoImagesAfter int // no_images_after: int
MaxMessageLength int // max_message_length: int
EmbedsAllowed bool // embeds_allowed: tinyint
RedirectToThread bool // redirect_to_thread: tinyint
RequireFile bool // require_file: tinyint
EnableCatalog bool // enable_catalog: tinyint
}
// DBPREFIXposts
type Post struct {
ID int // id: bigint
BoardID int // boardid: int
ParentID int // parentid: int
Name string // name: varchar
Tripcode string // tripcode: varchar
Email string // email: varchar
Subject string // subject: varchar
MessageHTML string // message: text
MessageText string // message_raw: text
Password string // password: varchar
Filename string // filename: varchar
FilenameOriginal string // filename_original: varchar
FileChecksum string // file_checksum: varchar
Filesize int // filesize: int
ImageW int // image_w: smallint
ImageH int // image_h: smallint
ThumbW int // thumb_w: smallint
ThumbH int // thumb_h: smallint
IP string // ip: varchar
Capcode string // tag: varchar
Timestamp time.Time // timestamp: timestamp
Autosage bool // autosage: tinyint
DeletedTimestamp time.Time // deleted_timestamp: timestamp
Bumped time.Time // bumped: timestamp
Stickied bool // stickied: tinyint
Locked bool // locked: tinyint
Reviewed bool // reviewed: tinyint
}
// DBPREFIXreports
type Report struct {
ID int // id: bigint
Board string // board: varchar
PostID int // postid: int
Timestamp time.Time // timestamp: timestamp
IP string // ip: varchar
Reason string // reason: varchar
Cleared bool // cleared: tinyint
IsTemp bool // istemp: tinyint
}
// DBPREFIXsections
type BoardSection struct {
ID int // id: bigint
ListOrder int // list_order: int
Hidden bool // hidden: tinyint
Name string // name: varchar
Abbreviation string // abbreviation: varchar
}