2018-04-23 08:38:25 +00:00
package main
import (
"bufio"
2019-04-13 11:54:22 +00:00
"database/sql"
2018-04-23 08:38:25 +00:00
"strconv"
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
"strings"
"unicode"
2018-04-23 08:38:25 +00:00
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
meta "github.com/Azareal/Gosora/common/meta"
2019-10-18 00:35:13 +00:00
qgen "github.com/Azareal/Gosora/query_gen"
2018-04-23 08:38:25 +00:00
)
2018-12-27 05:42:41 +00:00
type tblColumn = qgen . DBTableColumn
2019-08-14 10:39:04 +00:00
type tC = tblColumn
2018-12-27 05:42:41 +00:00
type tblKey = qgen . DBTableKey
2019-11-10 02:37:53 +00:00
type tK = tblKey
2018-12-27 05:42:41 +00:00
2018-05-16 10:46:14 +00:00
func init ( ) {
addPatch ( 0 , patch0 )
addPatch ( 1 , patch1 )
addPatch ( 2 , patch2 )
addPatch ( 3 , patch3 )
2018-05-27 09:36:35 +00:00
addPatch ( 4 , patch4 )
2018-06-17 07:28:18 +00:00
addPatch ( 5 , patch5 )
2018-07-13 11:27:58 +00:00
addPatch ( 6 , patch6 )
2018-07-28 12:52:23 +00:00
addPatch ( 7 , patch7 )
2018-10-27 03:21:02 +00:00
addPatch ( 8 , patch8 )
2018-12-17 04:58:55 +00:00
addPatch ( 9 , patch9 )
2018-12-27 05:42:41 +00:00
addPatch ( 10 , patch10 )
2018-12-27 09:12:30 +00:00
addPatch ( 11 , patch11 )
2018-12-31 09:03:49 +00:00
addPatch ( 12 , patch12 )
2019-01-21 12:27:59 +00:00
addPatch ( 13 , patch13 )
2019-02-23 06:29:19 +00:00
addPatch ( 14 , patch14 )
2019-02-28 07:28:17 +00:00
addPatch ( 15 , patch15 )
2019-03-11 08:47:45 +00:00
addPatch ( 16 , patch16 )
2019-04-13 11:54:22 +00:00
addPatch ( 17 , patch17 )
2019-04-27 06:32:26 +00:00
addPatch ( 18 , patch18 )
2019-05-01 06:59:51 +00:00
addPatch ( 19 , patch19 )
2019-05-06 04:04:00 +00:00
addPatch ( 20 , patch20 )
2019-05-09 06:58:55 +00:00
addPatch ( 21 , patch21 )
2019-05-27 09:00:40 +00:00
addPatch ( 22 , patch22 )
2019-08-14 10:39:04 +00:00
addPatch ( 23 , patch23 )
2019-09-29 04:56:39 +00:00
addPatch ( 24 , patch24 )
2019-10-06 22:20:37 +00:00
addPatch ( 25 , patch25 )
2019-10-18 00:35:13 +00:00
addPatch ( 26 , patch26 )
2019-11-10 02:37:53 +00:00
addPatch ( 27 , patch27 )
2019-12-08 03:40:56 +00:00
addPatch ( 28 , patch28 )
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
addPatch ( 29 , patch29 )
2020-02-09 10:00:08 +00:00
addPatch ( 30 , patch30 )
2020-02-21 11:42:21 +00:00
addPatch ( 31 , patch31 )
2020-02-23 09:08:47 +00:00
addPatch ( 32 , patch32 )
2020-02-26 10:34:38 +00:00
addPatch ( 33 , patch33 )
2020-07-14 21:50:29 +00:00
addPatch ( 34 , patch34 )
2021-01-02 21:46:24 +00:00
addPatch ( 35 , patch35 )
2021-04-07 14:23:11 +00:00
addPatch ( 36 , patch36 )
2018-05-16 10:46:14 +00:00
}
2020-07-14 21:50:29 +00:00
func bcol ( col string , val bool ) qgen . DBTableColumn {
if val {
return tC { col , "boolean" , 0 , false , false , "1" }
2018-05-11 05:41:51 +00:00
}
2020-07-14 21:50:29 +00:00
return tC { col , "boolean" , 0 , false , false , "0" }
}
func ccol ( col string , size int , sdefault string ) qgen . DBTableColumn {
return tC { col , "varchar" , size , false , false , sdefault }
}
2018-05-11 05:41:51 +00:00
2020-07-14 21:50:29 +00:00
func patch0 ( scanner * bufio . Scanner ) ( err error ) {
2020-03-21 08:55:15 +00:00
err = createTable ( "menus" , "" , "" ,
2019-08-14 10:39:04 +00:00
[ ] tC {
2021-01-06 06:41:08 +00:00
{ "mid" , "int" , 0 , false , true , "" } ,
2018-04-23 08:38:25 +00:00
} ,
2019-11-10 02:37:53 +00:00
[ ] tK {
2021-01-06 06:41:08 +00:00
{ "mid" , "primary" , "" , false } ,
2018-04-23 08:38:25 +00:00
} ,
2020-03-21 08:55:15 +00:00
)
2018-04-23 08:38:25 +00:00
if err != nil {
return err
}
2020-03-21 08:55:15 +00:00
err = createTable ( "menu_items" , "" , "" ,
2019-08-14 10:39:04 +00:00
[ ] tC {
2021-01-06 06:41:08 +00:00
{ "miid" , "int" , 0 , false , true , "" } ,
{ "mid" , "int" , 0 , false , false , "" } ,
2020-07-14 21:50:29 +00:00
ccol ( "name" , 200 , "" ) ,
ccol ( "htmlID" , 200 , "''" ) ,
ccol ( "cssClass" , 200 , "''" ) ,
ccol ( "position" , 100 , "" ) ,
ccol ( "path" , 200 , "''" ) ,
ccol ( "aria" , 200 , "''" ) ,
ccol ( "tooltip" , 200 , "''" ) ,
ccol ( "tmplName" , 200 , "''" ) ,
2021-01-06 06:41:08 +00:00
{ "order" , "int" , 0 , false , false , "0" } ,
2019-08-14 10:39:04 +00:00
2020-07-14 21:50:29 +00:00
bcol ( "guestOnly" , false ) ,
bcol ( "memberOnly" , false ) ,
bcol ( "staffOnly" , false ) ,
bcol ( "adminOnly" , false ) ,
2018-04-23 08:38:25 +00:00
} ,
2019-11-10 02:37:53 +00:00
[ ] tK {
2021-01-06 06:41:08 +00:00
{ "miid" , "primary" , "" , false } ,
2018-05-11 05:41:51 +00:00
} ,
2020-03-21 08:55:15 +00:00
)
2018-04-23 08:38:25 +00:00
if err != nil {
return err
}
err = execStmt ( qgen . Builder . SimpleInsert ( "menus" , "" , "" ) )
if err != nil {
return err
}
2018-04-23 21:08:31 +00:00
var order int
2019-10-18 00:35:13 +00:00
mOrder := "mid, name, htmlID, cssClass, position, path, aria, tooltip, guestOnly, memberOnly, staffOnly, adminOnly"
addMenuItem := func ( data map [ string ] interface { } ) error {
2018-04-23 08:38:25 +00:00
cols , values := qgen . InterfaceMapToInsertStrings ( data , mOrder )
2018-04-23 21:08:31 +00:00
err := execStmt ( qgen . Builder . SimpleInsert ( "menu_items" , cols + ", order" , values + "," + strconv . Itoa ( order ) ) )
order ++
2018-04-23 08:38:25 +00:00
return err
}
2018-05-11 05:41:51 +00:00
err = addMenuItem ( map [ string ] interface { } { "mid" : 1 , "name" : "{lang.menu_forums}" , "htmlID" : "menu_forums" , "position" : "left" , "path" : "/forums/" , "aria" : "{lang.menu_forums_aria}" , "tooltip" : "{lang.menu_forums_tooltip}" } )
2018-04-23 08:38:25 +00:00
if err != nil {
return err
}
2018-05-11 05:41:51 +00:00
err = addMenuItem ( map [ string ] interface { } { "mid" : 1 , "name" : "{lang.menu_topics}" , "htmlID" : "menu_topics" , "cssClass" : "menu_topics" , "position" : "left" , "path" : "/topics/" , "aria" : "{lang.menu_topics_aria}" , "tooltip" : "{lang.menu_topics_tooltip}" } )
2018-04-23 08:38:25 +00:00
if err != nil {
return err
}
err = addMenuItem ( map [ string ] interface { } { "mid" : 1 , "htmlID" : "general_alerts" , "cssClass" : "menu_alerts" , "position" : "right" , "tmplName" : "menu_alerts" } )
if err != nil {
return err
}
2018-05-11 05:41:51 +00:00
err = addMenuItem ( map [ string ] interface { } { "mid" : 1 , "name" : "{lang.menu_account}" , "cssClass" : "menu_account" , "position" : "left" , "path" : "/user/edit/critical/" , "aria" : "{lang.menu_account_aria}" , "tooltip" : "{lang.menu_account_tooltip}" , "memberOnly" : true } )
2018-04-23 08:38:25 +00:00
if err != nil {
return err
}
2018-05-11 05:41:51 +00:00
err = addMenuItem ( map [ string ] interface { } { "mid" : 1 , "name" : "{lang.menu_profile}" , "cssClass" : "menu_profile" , "position" : "left" , "path" : "{me.Link}" , "aria" : "{lang.menu_profile_aria}" , "tooltip" : "{lang.menu_profile_tooltip}" , "memberOnly" : true } )
2018-04-23 08:38:25 +00:00
if err != nil {
return err
}
2018-05-11 05:41:51 +00:00
err = addMenuItem ( map [ string ] interface { } { "mid" : 1 , "name" : "{lang.menu_panel}" , "cssClass" : "menu_panel menu_account" , "position" : "left" , "path" : "/panel/" , "aria" : "{lang.menu_panel_aria}" , "tooltip" : "{lang.menu_panel_tooltip}" , "memberOnly" : true , "staffOnly" : true } )
2018-04-23 08:38:25 +00:00
if err != nil {
return err
}
2018-05-11 05:41:51 +00:00
err = addMenuItem ( map [ string ] interface { } { "mid" : 1 , "name" : "{lang.menu_logout}" , "cssClass" : "menu_logout" , "position" : "left" , "path" : "/accounts/logout/?session={me.Session}" , "aria" : "{lang.menu_logout_aria}" , "tooltip" : "{lang.menu_logout_tooltip}" , "memberOnly" : true } )
2018-04-23 08:38:25 +00:00
if err != nil {
return err
}
2018-05-11 05:41:51 +00:00
err = addMenuItem ( map [ string ] interface { } { "mid" : 1 , "name" : "{lang.menu_register}" , "cssClass" : "menu_register" , "position" : "left" , "path" : "/accounts/create/" , "aria" : "{lang.menu_register_aria}" , "tooltip" : "{lang.menu_register_tooltip}" , "guestOnly" : true } )
2018-04-23 08:38:25 +00:00
if err != nil {
return err
}
2018-05-11 05:41:51 +00:00
err = addMenuItem ( map [ string ] interface { } { "mid" : 1 , "name" : "{lang.menu_login}" , "cssClass" : "menu_login" , "position" : "left" , "path" : "/accounts/login/" , "aria" : "{lang.menu_login_aria}" , "tooltip" : "{lang.menu_login_tooltip}" , "guestOnly" : true } )
2018-04-23 08:38:25 +00:00
if err != nil {
return err
}
return nil
}
2018-05-11 05:41:51 +00:00
func patch1 ( scanner * bufio . Scanner ) error {
2021-04-07 14:23:11 +00:00
return renameRoutes ( map [ string ] string {
2018-10-27 03:21:02 +00:00
"routeAccountEditCriticalSubmit" : "routes.AccountEditCriticalSubmit" ,
2018-12-17 04:58:55 +00:00
"routeAccountEditAvatar" : "routes.AccountEditAvatar" ,
"routeAccountEditAvatarSubmit" : "routes.AccountEditAvatarSubmit" ,
"routeAccountEditUsername" : "routes.AccountEditUsername" ,
2018-10-27 03:21:02 +00:00
"routeAccountEditUsernameSubmit" : "routes.AccountEditUsernameSubmit" ,
2021-04-07 14:23:11 +00:00
} )
2018-05-11 05:41:51 +00:00
}
2018-05-15 05:59:52 +00:00
func patch2 ( scanner * bufio . Scanner ) error {
2021-04-07 14:23:11 +00:00
return renameRoutes ( map [ string ] string {
2018-12-17 04:58:55 +00:00
"routeLogout" : "routes.AccountLogout" ,
"routeShowAttachment" : "routes.ShowAttachment" ,
"routeChangeTheme" : "routes.ChangeTheme" ,
2018-10-27 03:21:02 +00:00
"routeProfileReplyCreateSubmit" : "routes.ProfileReplyCreateSubmit" ,
2018-12-17 04:58:55 +00:00
"routeLikeTopicSubmit" : "routes.LikeTopicSubmit" ,
"routeReplyLikeSubmit" : "routes.ReplyLikeSubmit" ,
"routeDynamic" : "routes.DynamicRoute" ,
"routeUploads" : "routes.UploadedFile" ,
"BadRoute" : "routes.BadRoute" ,
2021-04-07 14:23:11 +00:00
} )
2018-05-15 05:59:52 +00:00
}
2018-05-16 10:46:14 +00:00
func patch3 ( scanner * bufio . Scanner ) error {
2020-03-21 08:55:15 +00:00
return createTable ( "registration_logs" , "" , "" ,
2019-08-14 10:39:04 +00:00
[ ] tC {
2021-01-06 06:41:08 +00:00
{ "rlid" , "int" , 0 , false , true , "" } ,
2020-07-14 21:50:29 +00:00
ccol ( "username" , 100 , "" ) ,
ccol ( "email" , 100 , "" ) ,
ccol ( "failureReason" , 100 , "" ) ,
bcol ( "success" , false ) , // Did this attempt succeed?
ccol ( "ipaddress" , 200 , "" ) ,
2021-01-06 06:41:08 +00:00
{ "doneAt" , "createdAt" , 0 , false , false , "" } ,
2018-05-16 10:46:14 +00:00
} ,
2019-11-10 02:37:53 +00:00
[ ] tK {
2021-01-06 06:41:08 +00:00
{ "rlid" , "primary" , "" , false } ,
2018-05-16 10:46:14 +00:00
} ,
2020-03-21 08:55:15 +00:00
)
2018-05-16 10:46:14 +00:00
}
2018-05-27 09:36:35 +00:00
func patch4 ( scanner * bufio . Scanner ) error {
2019-10-18 00:35:13 +00:00
routes := map [ string ] string {
2018-12-17 04:58:55 +00:00
"routeReportSubmit" : "routes.ReportSubmit" ,
"routeAccountEditEmail" : "routes.AccountEditEmail" ,
"routeAccountEditEmailTokenSubmit" : "routes.AccountEditEmailTokenSubmit" ,
"routePanelLogsRegs" : "panel.LogsRegs" ,
"routePanelLogsMod" : "panel.LogsMod" ,
"routePanelLogsAdmin" : "panel.LogsAdmin" ,
"routePanelDebug" : "panel.Debug" ,
"routePanelAnalyticsViews" : "panel.AnalyticsViews" ,
"routePanelAnalyticsRouteViews" : "panel.AnalyticsRouteViews" ,
"routePanelAnalyticsAgentViews" : "panel.AnalyticsAgentViews" ,
"routePanelAnalyticsForumViews" : "panel.AnalyticsForumViews" ,
"routePanelAnalyticsSystemViews" : "panel.AnalyticsSystemViews" ,
"routePanelAnalyticsLanguageViews" : "panel.AnalyticsLanguageViews" ,
"routePanelAnalyticsReferrerViews" : "panel.AnalyticsReferrerViews" ,
"routePanelAnalyticsTopics" : "panel.AnalyticsTopics" ,
"routePanelAnalyticsPosts" : "panel.AnalyticsPosts" ,
"routePanelAnalyticsForums" : "panel.AnalyticsForums" ,
"routePanelAnalyticsRoutes" : "panel.AnalyticsRoutes" ,
"routePanelAnalyticsAgents" : "panel.AnalyticsAgents" ,
"routePanelAnalyticsSystems" : "panel.AnalyticsSystems" ,
"routePanelAnalyticsLanguages" : "panel.AnalyticsLanguages" ,
"routePanelAnalyticsReferrers" : "panel.AnalyticsReferrers" ,
"routePanelSettings" : "panel.Settings" ,
"routePanelSettingEdit" : "panel.SettingEdit" ,
"routePanelSettingEditSubmit" : "panel.SettingEditSubmit" ,
"routePanelForums" : "panel.Forums" ,
"routePanelForumsCreateSubmit" : "panel.ForumsCreateSubmit" ,
"routePanelForumsDelete" : "panel.ForumsDelete" ,
"routePanelForumsDeleteSubmit" : "panel.ForumsDeleteSubmit" ,
"routePanelForumsEdit" : "panel.ForumsEdit" ,
"routePanelForumsEditSubmit" : "panel.ForumsEditSubmit" ,
"routePanelForumsEditPermsSubmit" : "panel.ForumsEditPermsSubmit" ,
"routePanelForumsEditPermsAdvance" : "panel.ForumsEditPermsAdvance" ,
2018-10-27 03:21:02 +00:00
"routePanelForumsEditPermsAdvanceSubmit" : "panel.ForumsEditPermsAdvanceSubmit" ,
2018-12-17 04:58:55 +00:00
"routePanelBackups" : "panel.Backups" ,
2018-10-27 03:21:02 +00:00
}
2021-04-07 14:23:11 +00:00
e := renameRoutes ( routes )
if e != nil {
return e
2018-05-27 09:36:35 +00:00
}
2021-04-07 14:23:11 +00:00
e = execStmt ( qgen . Builder . SimpleDelete ( "settings" , "name='url_tags'" ) )
if e != nil {
return e
2018-05-27 09:36:35 +00:00
}
2021-01-06 06:41:08 +00:00
return createTable ( "pages" , "utf8mb4" , "utf8mb4_general_ci" ,
2019-08-14 10:39:04 +00:00
[ ] tC {
2021-01-06 06:41:08 +00:00
{ "pid" , "int" , 0 , false , true , "" } ,
2020-07-14 21:50:29 +00:00
ccol ( "name" , 200 , "" ) ,
ccol ( "title" , 200 , "" ) ,
2021-01-06 06:41:08 +00:00
{ "body" , "text" , 0 , false , false , "" } ,
{ "allowedGroups" , "text" , 0 , false , false , "" } ,
{ "menuID" , "int" , 0 , false , false , "-1" } ,
2018-05-27 09:36:35 +00:00
} ,
2019-11-10 02:37:53 +00:00
[ ] tK {
2021-01-06 06:41:08 +00:00
{ "pid" , "primary" , "" , false } ,
2018-05-27 09:36:35 +00:00
} ,
2020-03-21 08:55:15 +00:00
)
2018-05-27 09:36:35 +00:00
}
2018-06-17 07:28:18 +00:00
func patch5 ( scanner * bufio . Scanner ) error {
2019-10-18 00:35:13 +00:00
routes := map [ string ] string {
2018-12-17 04:58:55 +00:00
"routePanelUsers" : "panel.Users" ,
"routePanelUsersEdit" : "panel.UsersEdit" ,
"routePanelUsersEditSubmit" : "panel.UsersEditSubmit" ,
"routes.AccountEditCritical" : "routes.AccountEditPassword" ,
2018-10-27 03:21:02 +00:00
"routes.AccountEditCriticalSubmit" : "routes.AccountEditPasswordSubmit" ,
2018-06-17 07:28:18 +00:00
}
2021-04-07 14:23:11 +00:00
e := renameRoutes ( routes )
if e != nil {
return e
2018-06-17 07:28:18 +00:00
}
2021-04-07 14:23:11 +00:00
e = execStmt ( qgen . Builder . SimpleUpdate ( "menu_items" , "path='/user/edit/'" , "path='/user/edit/critical/'" ) )
if e != nil {
return e
2018-06-17 07:28:18 +00:00
}
2020-07-14 21:50:29 +00:00
return createTable ( "users_2fa_keys" , "utf8mb4" , "utf8mb4_general_ci" ,
2019-08-14 10:39:04 +00:00
[ ] tC {
2021-01-06 06:41:08 +00:00
{ "uid" , "int" , 0 , false , false , "" } ,
2020-07-14 21:50:29 +00:00
ccol ( "secret" , 100 , "" ) ,
ccol ( "scratch1" , 50 , "" ) ,
ccol ( "scratch2" , 50 , "" ) ,
ccol ( "scratch3" , 50 , "" ) ,
ccol ( "scratch4" , 50 , "" ) ,
ccol ( "scratch5" , 50 , "" ) ,
ccol ( "scratch6" , 50 , "" ) ,
ccol ( "scratch7" , 50 , "" ) ,
ccol ( "scratch8" , 50 , "" ) ,
2021-01-06 06:41:08 +00:00
{ "createdAt" , "createdAt" , 0 , false , false , "" } ,
2018-06-17 07:28:18 +00:00
} ,
2019-11-10 02:37:53 +00:00
[ ] tK {
2021-01-06 06:41:08 +00:00
{ "uid" , "primary" , "" , false } ,
2018-06-17 07:28:18 +00:00
} ,
2020-03-21 08:55:15 +00:00
)
2018-06-17 07:28:18 +00:00
}
2018-07-13 11:27:58 +00:00
func patch6 ( scanner * bufio . Scanner ) error {
2018-12-27 05:42:41 +00:00
return execStmt ( qgen . Builder . SimpleInsert ( "settings" , "name, content, type" , "'rapid_loading','1','bool'" ) )
2018-07-13 11:27:58 +00:00
}
2018-07-28 12:52:23 +00:00
func patch7 ( scanner * bufio . Scanner ) error {
2020-03-21 08:55:15 +00:00
return createTable ( "users_avatar_queue" , "" , "" ,
2019-08-14 10:39:04 +00:00
[ ] tC {
2021-01-06 06:41:08 +00:00
{ "uid" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
2018-07-28 12:52:23 +00:00
} ,
2019-11-10 02:37:53 +00:00
[ ] tK {
2021-01-06 06:41:08 +00:00
{ "uid" , "primary" , "" , false } ,
2018-07-28 12:52:23 +00:00
} ,
2020-03-21 08:55:15 +00:00
)
2018-07-28 12:52:23 +00:00
}
2018-10-27 03:21:02 +00:00
func renameRoutes ( routes map [ string ] string ) error {
// ! Don't reuse this function blindly, it doesn't escape apostrophes
2019-10-18 00:35:13 +00:00
replaceTextWhere := func ( replaceThis string , withThis string ) error {
2018-10-27 03:21:02 +00:00
return execStmt ( qgen . Builder . SimpleUpdate ( "viewchunks" , "route = '" + withThis + "'" , "route = '" + replaceThis + "'" ) )
}
for key , value := range routes {
2021-04-07 14:23:11 +00:00
e := replaceTextWhere ( key , value )
if e != nil {
return e
2018-10-27 03:21:02 +00:00
}
}
return nil
}
func patch8 ( scanner * bufio . Scanner ) error {
2019-10-18 00:35:13 +00:00
routes := map [ string ] string {
2018-12-17 04:58:55 +00:00
"routePanelWordFilter" : "panel.WordFilters" ,
"routePanelWordFiltersCreateSubmit" : "panel.WordFiltersCreateSubmit" ,
"routePanelWordFiltersEdit" : "panel.WordFiltersEdit" ,
"routePanelWordFiltersEditSubmit" : "panel.WordFiltersEditSubmit" ,
"routePanelWordFiltersDeleteSubmit" : "panel.WordFiltersDeleteSubmit" ,
"routePanelPlugins" : "panel.Plugins" ,
"routePanelPluginsActivate" : "panel.PluginsActivate" ,
"routePanelPluginsDeactivate" : "panel.PluginsDeactivate" ,
"routePanelPluginsInstall" : "panel.PluginsInstall" ,
"routePanelGroups" : "panel.Groups" ,
"routePanelGroupsEdit" : "panel.GroupsEdit" ,
"routePanelGroupsEditPerms" : "panel.GroupsEditPerms" ,
"routePanelGroupsEditSubmit" : "panel.GroupsEditSubmit" ,
"routePanelGroupsEditPermsSubmit" : "panel.GroupsEditPermsSubmit" ,
"routePanelGroupsCreateSubmit" : "panel.GroupsCreateSubmit" ,
"routePanelThemes" : "panel.Themes" ,
"routePanelThemesSetDefault" : "panel.ThemesSetDefault" ,
"routePanelThemesMenus" : "panel.ThemesMenus" ,
"routePanelThemesMenusEdit" : "panel.ThemesMenusEdit" ,
"routePanelThemesMenuItemEdit" : "panel.ThemesMenuItemEdit" ,
"routePanelThemesMenuItemEditSubmit" : "panel.ThemesMenuItemEditSubmit" ,
"routePanelThemesMenuItemCreateSubmit" : "panel.ThemesMenuItemCreateSubmit" ,
"routePanelThemesMenuItemDeleteSubmit" : "panel.ThemesMenuItemDeleteSubmit" ,
"routePanelThemesMenuItemOrderSubmit" : "panel.ThemesMenuItemOrderSubmit" ,
"routePanelDashboard" : "panel.Dashboard" ,
2018-10-27 03:21:02 +00:00
}
2021-04-07 14:23:11 +00:00
e := renameRoutes ( routes )
if e != nil {
return e
2018-10-27 03:21:02 +00:00
}
2020-03-21 08:55:15 +00:00
return createTable ( "updates" , "" , "" ,
2019-08-14 10:39:04 +00:00
[ ] tC {
2021-01-06 06:41:08 +00:00
{ "dbVersion" , "int" , 0 , false , false , "0" } ,
2019-11-10 02:37:53 +00:00
} , nil ,
2020-03-21 08:55:15 +00:00
)
2018-10-27 03:21:02 +00:00
}
2018-12-17 04:58:55 +00:00
func patch9 ( scanner * bufio . Scanner ) error {
// Table "updates" might not exist due to the installer, so drop it and remake it if so
err := patch8 ( scanner )
if err != nil {
return err
}
2020-03-21 08:55:15 +00:00
return createTable ( "login_logs" , "" , "" ,
2019-08-14 10:39:04 +00:00
[ ] tC {
2021-01-06 06:41:08 +00:00
{ "lid" , "int" , 0 , false , true , "" } ,
{ "uid" , "int" , 0 , false , false , "" } ,
2020-07-14 21:50:29 +00:00
bcol ( "success" , false ) , // Did this attempt succeed?
ccol ( "ipaddress" , 200 , "" ) ,
2021-01-06 06:41:08 +00:00
{ "doneAt" , "createdAt" , 0 , false , false , "" } ,
2018-12-17 04:58:55 +00:00
} ,
2019-11-10 02:37:53 +00:00
[ ] tK {
2021-01-06 06:41:08 +00:00
{ "lid" , "primary" , "" , false } ,
2018-12-17 04:58:55 +00:00
} ,
2020-03-21 08:55:15 +00:00
)
2018-12-27 05:42:41 +00:00
}
var acc = qgen . NewAcc
var itoa = strconv . Itoa
func patch10 ( scanner * bufio . Scanner ) error {
2019-08-14 10:39:04 +00:00
err := execStmt ( qgen . Builder . AddColumn ( "topics" , tC { "attachCount" , "int" , 0 , false , false , "0" } , nil ) )
2018-12-27 05:42:41 +00:00
if err != nil {
return err
}
2019-08-14 10:39:04 +00:00
err = execStmt ( qgen . Builder . AddColumn ( "topics" , tC { "lastReplyID" , "int" , 0 , false , false , "0" } , nil ) )
2018-12-17 04:58:55 +00:00
if err != nil {
return err
}
2018-12-27 05:42:41 +00:00
err = acc ( ) . Select ( "topics" ) . Cols ( "tid" ) . EachInt ( func ( tid int ) error {
stid := itoa ( tid )
2020-02-26 10:34:38 +00:00
count , err := acc ( ) . Count ( "attachments" ) . Where ( "originTable = 'topics' and originID=" + stid ) . Total ( )
2018-12-27 05:42:41 +00:00
if err != nil {
return err
}
2019-10-18 00:35:13 +00:00
hasReply := false
2020-02-26 10:34:38 +00:00
err = acc ( ) . Select ( "replies" ) . Cols ( "rid" ) . Where ( "tid=" + stid ) . Orderby ( "rid DESC" ) . Limit ( "1" ) . EachInt ( func ( rid int ) error {
2018-12-27 05:42:41 +00:00
hasReply = true
2020-02-26 10:34:38 +00:00
_ , err := acc ( ) . Update ( "topics" ) . Set ( "lastReplyID=?, attachCount=?" ) . Where ( "tid=" + stid ) . Exec ( rid , count )
2018-12-27 05:42:41 +00:00
return err
} )
if err != nil {
return err
}
if ! hasReply {
2020-02-26 10:34:38 +00:00
_ , err = acc ( ) . Update ( "topics" ) . Set ( "attachCount=?" ) . Where ( "tid=" + stid ) . Exec ( count )
2018-12-27 05:42:41 +00:00
}
return err
} )
if err != nil {
return err
}
_ , err = acc ( ) . Insert ( "updates" ) . Columns ( "dbVersion" ) . Fields ( "0" ) . Exec ( )
return err
2018-12-17 04:58:55 +00:00
}
2018-12-27 09:12:30 +00:00
func patch11 ( scanner * bufio . Scanner ) error {
2019-08-14 10:39:04 +00:00
err := execStmt ( qgen . Builder . AddColumn ( "replies" , tC { "attachCount" , "int" , 0 , false , false , "0" } , nil ) )
2018-12-27 09:12:30 +00:00
if err != nil {
return err
}
// Attachments for replies got the topicID rather than the replyID for a while in error, so we want to separate these out
2020-07-14 21:50:29 +00:00
_ , err = acc ( ) . Update ( "attachments" ) . Set ( "originTable='freplies'" ) . Where ( "originTable='replies'" ) . Exec ( )
2018-12-27 09:12:30 +00:00
if err != nil {
return err
}
// We could probably do something more efficient, but as there shouldn't be too many sites right now, we can probably cheat a little, otherwise it'll take forever to get things done
return acc ( ) . Select ( "topics" ) . Cols ( "tid" ) . EachInt ( func ( tid int ) error {
stid := itoa ( tid )
2019-11-10 02:37:53 +00:00
count , err := acc ( ) . Count ( "attachments" ) . Where ( "originTable='topics' and originID=" + stid ) . Total ( )
2018-12-27 09:12:30 +00:00
if err != nil {
return err
}
2020-03-21 08:55:15 +00:00
_ , err = acc ( ) . Update ( "topics" ) . Set ( "attachCount=?" ) . Where ( "tid=" + stid ) . Exec ( count )
2018-12-27 09:12:30 +00:00
return err
} )
/ * return acc ( ) . Select ( "replies" ) . Cols ( "rid" ) . EachInt ( func ( rid int ) error {
srid := itoa ( rid )
2019-11-10 02:37:53 +00:00
count , err := acc ( ) . Count ( "attachments" ) . Where ( "originTable='replies' and originID=" + srid ) . Total ( )
2018-12-27 09:12:30 +00:00
if err != nil {
return err
}
2019-11-10 02:37:53 +00:00
_ , err = acc ( ) . Update ( "replies" ) . Set ( "attachCount = ?" ) . Where ( "rid=" + srid ) . Exec ( count )
2018-12-27 09:12:30 +00:00
return err
} ) * /
}
2018-12-31 09:03:49 +00:00
func patch12 ( scanner * bufio . Scanner ) error {
2020-07-14 21:50:29 +00:00
var e error
addIndex := func ( tbl , iname , colname string ) {
if e != nil {
return
}
/ * e = execStmt ( qgen . Builder . RemoveIndex ( tbl , iname ) )
if e != nil {
return
} * /
e = execStmt ( qgen . Builder . AddIndex ( tbl , iname , colname ) )
}
addIndex ( "topics" , "parentID" , "parentID" )
addIndex ( "replies" , "tid" , "tid" )
addIndex ( "polls" , "parentID" , "parentID" )
addIndex ( "likes" , "targetItem" , "targetItem" )
addIndex ( "emails" , "uid" , "uid" )
addIndex ( "attachments" , "originID" , "originID" )
addIndex ( "attachments" , "path" , "path" )
addIndex ( "activity_stream_matches" , "watcher" , "watcher" )
return e
2018-12-31 09:03:49 +00:00
}
2019-01-21 12:27:59 +00:00
func patch13 ( scanner * bufio . Scanner ) error {
2019-11-10 02:37:53 +00:00
return execStmt ( qgen . Builder . AddColumn ( "widgets" , tC { "wid" , "int" , 0 , false , true , "" } , & tK { "wid" , "primary" , "" , false } ) )
2019-01-21 12:27:59 +00:00
}
2019-02-23 06:29:19 +00:00
func patch14 ( scanner * bufio . Scanner ) error {
2020-02-21 11:42:21 +00:00
/ * err := execStmt ( qgen . Builder . AddKey ( "topics" , "title" , tK { "title" , "fulltext" , "" , false } ) )
2019-02-23 06:29:19 +00:00
if err != nil {
return err
}
2019-11-10 02:37:53 +00:00
err = execStmt ( qgen . Builder . AddKey ( "topics" , "content" , tK { "content" , "fulltext" , "" , false } ) )
2019-02-23 06:29:19 +00:00
if err != nil {
return err
}
2019-11-10 02:37:53 +00:00
err = execStmt ( qgen . Builder . AddKey ( "replies" , "content" , tK { "content" , "fulltext" , "" , false } ) )
2019-02-23 06:29:19 +00:00
if err != nil {
return err
2020-02-21 11:42:21 +00:00
} * /
2019-02-23 06:29:19 +00:00
return nil
}
2019-02-28 07:28:17 +00:00
func patch15 ( scanner * bufio . Scanner ) error {
return execStmt ( qgen . Builder . SimpleInsert ( "settings" , "name, content, type" , "'google_site_verify','','html-attribute'" ) )
}
2019-03-11 08:47:45 +00:00
func patch16 ( scanner * bufio . Scanner ) error {
2020-03-21 08:55:15 +00:00
return createTable ( "password_resets" , "" , "" ,
2019-08-14 10:39:04 +00:00
[ ] tC {
2020-07-14 21:50:29 +00:00
ccol ( "email" , 200 , "" ) ,
2021-01-06 06:41:08 +00:00
{ "uid" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
ccol ( "validated" , 200 , "" ) , // Token given once the one-use token is consumed, used to prevent multiple people consuming the same one-use token
2020-07-14 21:50:29 +00:00
ccol ( "token" , 200 , "" ) ,
2021-01-06 06:41:08 +00:00
{ "createdAt" , "createdAt" , 0 , false , false , "" } ,
2019-03-11 08:47:45 +00:00
} , nil ,
2020-03-21 08:55:15 +00:00
)
2019-03-11 08:47:45 +00:00
}
2019-04-13 11:54:22 +00:00
func patch17 ( scanner * bufio . Scanner ) error {
2020-07-14 21:50:29 +00:00
err := execStmt ( qgen . Builder . AddColumn ( "attachments" , ccol ( "extra" , 200 , "" ) , nil ) )
2019-04-13 11:54:22 +00:00
if err != nil {
return err
}
2020-03-21 08:55:15 +00:00
err = acc ( ) . Select ( "topics" ) . Cols ( "tid,parentID" ) . Where ( "attachCount > 0" ) . Each ( func ( rows * sql . Rows ) error {
2019-04-13 11:54:22 +00:00
var tid , parentID int
err := rows . Scan ( & tid , & parentID )
if err != nil {
return err
}
2020-07-14 21:50:29 +00:00
_ , err = acc ( ) . Update ( "attachments" ) . Set ( "sectionID=?" ) . Where ( "originTable='topics' AND originID=?" ) . Exec ( parentID , tid )
2019-04-13 11:54:22 +00:00
return err
} )
if err != nil {
return err
}
2020-03-21 08:55:15 +00:00
return acc ( ) . Select ( "replies" ) . Cols ( "rid,tid" ) . Where ( "attachCount > 0" ) . Each ( func ( rows * sql . Rows ) error {
2019-04-13 11:54:22 +00:00
var rid , tid , sectionID int
err := rows . Scan ( & rid , & tid )
if err != nil {
return err
}
2020-03-21 08:55:15 +00:00
err = acc ( ) . Select ( "topics" ) . Cols ( "parentID" ) . Where ( "tid=?" ) . QueryRow ( tid ) . Scan ( & sectionID )
2019-04-13 11:54:22 +00:00
if err != nil {
return err
}
2020-07-14 21:50:29 +00:00
_ , err = acc ( ) . Update ( "attachments" ) . Set ( "sectionID=?, extra=?" ) . Where ( "originTable='replies' AND originID=?" ) . Exec ( sectionID , tid , rid )
2019-04-13 11:54:22 +00:00
return err
} )
}
2019-04-27 06:32:26 +00:00
func patch18 ( scanner * bufio . Scanner ) error {
2019-08-14 10:39:04 +00:00
return execStmt ( qgen . Builder . AddColumn ( "forums" , tC { "order" , "int" , 0 , false , false , "0" } , nil ) )
2019-05-01 06:59:51 +00:00
}
func patch19 ( scanner * bufio . Scanner ) error {
2020-03-21 08:55:15 +00:00
return createTable ( "memchunks" , "" , "" ,
2019-08-14 10:39:04 +00:00
[ ] tC {
2021-01-06 06:41:08 +00:00
{ "count" , "int" , 0 , false , false , "0" } ,
{ "createdAt" , "datetime" , 0 , false , false , "" } ,
2019-05-01 06:59:51 +00:00
} , nil ,
2020-03-21 08:55:15 +00:00
)
2019-05-06 04:04:00 +00:00
}
func patch20 ( scanner * bufio . Scanner ) error {
err := acc ( ) . Select ( "activity_stream_matches" ) . Cols ( "asid" ) . Each ( func ( rows * sql . Rows ) error {
var asid int
2020-07-14 21:50:29 +00:00
if e := rows . Scan ( & asid ) ; e != nil {
return e
2019-05-06 04:04:00 +00:00
}
2020-07-14 21:50:29 +00:00
e := acc ( ) . Select ( "activity_stream" ) . Cols ( "asid" ) . Where ( "asid=?" ) . QueryRow ( asid ) . Scan ( & asid )
if e != sql . ErrNoRows {
return e
2019-05-06 04:04:00 +00:00
}
2020-07-14 21:50:29 +00:00
_ , e = acc ( ) . Delete ( "activity_stream_matches" ) . Where ( "asid=?" ) . Run ( asid )
return e
2019-05-06 04:04:00 +00:00
} )
if err != nil {
return err
}
2019-10-18 00:35:13 +00:00
return execStmt ( qgen . Builder . AddForeignKey ( "activity_stream_matches" , "asid" , "activity_stream" , "asid" , true ) )
2019-05-06 04:04:00 +00:00
}
2019-05-09 06:58:55 +00:00
func patch21 ( scanner * bufio . Scanner ) error {
2019-08-14 10:39:04 +00:00
err := execStmt ( qgen . Builder . AddColumn ( "memchunks" , tC { "stack" , "int" , 0 , false , false , "0" } , nil ) )
2019-05-09 06:58:55 +00:00
if err != nil {
return err
}
2019-10-18 00:35:13 +00:00
2019-08-14 10:39:04 +00:00
err = execStmt ( qgen . Builder . AddColumn ( "memchunks" , tC { "heap" , "int" , 0 , false , false , "0" } , nil ) )
2019-05-09 06:58:55 +00:00
if err != nil {
return err
}
2019-10-18 00:35:13 +00:00
2020-03-21 08:55:15 +00:00
err = createTable ( "meta" , "" , "" ,
2019-08-14 10:39:04 +00:00
[ ] tC {
2020-07-14 21:50:29 +00:00
ccol ( "name" , 200 , "" ) ,
ccol ( "value" , 200 , "" ) ,
2019-05-09 06:58:55 +00:00
} , nil ,
2020-03-21 08:55:15 +00:00
)
2019-05-09 06:58:55 +00:00
if err != nil {
return err
}
2019-08-14 10:39:04 +00:00
return execStmt ( qgen . Builder . AddColumn ( "activity_stream" , tC { "createdAt" , "createdAt" , 0 , false , false , "" } , nil ) )
2019-05-27 09:00:40 +00:00
}
func patch22 ( scanner * bufio . Scanner ) error {
2020-07-14 21:50:29 +00:00
return execStmt ( qgen . Builder . AddColumn ( "forums" , ccol ( "tmpl" , 200 , "''" ) , nil ) )
2019-08-14 10:39:04 +00:00
}
func patch23 ( scanner * bufio . Scanner ) error {
2020-07-14 21:50:29 +00:00
err := createTable ( "conversations" , "" , "" ,
2019-08-14 10:39:04 +00:00
[ ] tC {
2021-01-06 06:41:08 +00:00
{ "cid" , "int" , 0 , false , true , "" } ,
{ "createdBy" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
{ "createdAt" , "createdAt" , 0 , false , false , "" } ,
{ "lastReplyAt" , "datetime" , 0 , false , false , "" } ,
{ "lastReplyBy" , "int" , 0 , false , false , "" } ,
2019-08-14 10:39:04 +00:00
} ,
2019-11-10 02:37:53 +00:00
[ ] tK {
2021-01-06 06:41:08 +00:00
{ "cid" , "primary" , "" , false } ,
2019-08-14 10:39:04 +00:00
} ,
2020-03-21 08:55:15 +00:00
)
2019-08-14 10:39:04 +00:00
if err != nil {
return err
}
2020-03-21 08:55:15 +00:00
err = createTable ( "conversations_posts" , "" , "" ,
2019-08-14 10:39:04 +00:00
[ ] tC {
2021-01-06 06:41:08 +00:00
{ "pid" , "int" , 0 , false , true , "" } ,
{ "cid" , "int" , 0 , false , false , "" } ,
{ "createdBy" , "int" , 0 , false , false , "" } ,
2020-07-14 21:50:29 +00:00
ccol ( "body" , 50 , "" ) ,
ccol ( "post" , 50 , "''" ) ,
2019-08-14 10:39:04 +00:00
} ,
2019-11-10 02:37:53 +00:00
[ ] tK {
2021-01-06 06:41:08 +00:00
{ "pid" , "primary" , "" , false } ,
2019-08-14 10:39:04 +00:00
} ,
2020-03-21 08:55:15 +00:00
)
2019-08-14 10:39:04 +00:00
if err != nil {
return err
}
2020-03-21 08:55:15 +00:00
return createTable ( "conversations_participants" , "" , "" ,
2019-08-14 10:39:04 +00:00
[ ] tC {
2021-01-06 06:41:08 +00:00
{ "uid" , "int" , 0 , false , false , "" } ,
{ "cid" , "int" , 0 , false , false , "" } ,
2019-08-14 10:39:04 +00:00
} , nil ,
2020-03-21 08:55:15 +00:00
)
2019-09-29 04:56:39 +00:00
}
func patch24 ( scanner * bufio . Scanner ) error {
2020-03-21 08:55:15 +00:00
return createTable ( "users_groups_promotions" , "" , "" ,
2019-09-29 04:56:39 +00:00
[ ] tC {
2021-01-06 06:41:08 +00:00
{ "pid" , "int" , 0 , false , true , "" } ,
{ "from_gid" , "int" , 0 , false , false , "" } ,
{ "to_gid" , "int" , 0 , false , false , "" } ,
2020-07-14 21:50:29 +00:00
bcol ( "two_way" , false ) , // If a user no longer meets the requirements for this promotion then they will be demoted if this flag is set
2019-09-29 04:56:39 +00:00
// Requirements
2021-01-06 06:41:08 +00:00
{ "level" , "int" , 0 , false , false , "" } ,
{ "minTime" , "int" , 0 , false , false , "" } , // How long someone needs to have been in their current group before being promoted
2019-09-29 04:56:39 +00:00
} ,
2019-11-10 02:37:53 +00:00
[ ] tK {
2021-01-06 06:41:08 +00:00
{ "pid" , "primary" , "" , false } ,
2019-09-29 04:56:39 +00:00
} ,
2020-03-21 08:55:15 +00:00
)
2019-10-06 22:20:37 +00:00
}
func patch25 ( scanner * bufio . Scanner ) error {
return execStmt ( qgen . Builder . AddColumn ( "users_groups_promotions" , tC { "posts" , "int" , 0 , false , false , "0" } , nil ) )
2019-10-18 00:35:13 +00:00
}
func patch26 ( scanner * bufio . Scanner ) error {
2020-03-21 08:55:15 +00:00
return createTable ( "users_blocks" , "" , "" ,
2019-10-18 00:35:13 +00:00
[ ] tC {
2021-01-06 06:41:08 +00:00
{ "blocker" , "int" , 0 , false , false , "" } ,
{ "blockedUser" , "int" , 0 , false , false , "" } ,
2019-10-18 00:35:13 +00:00
} , nil ,
2020-03-21 08:55:15 +00:00
)
2019-10-18 00:35:13 +00:00
}
2019-11-10 02:37:53 +00:00
func patch27 ( scanner * bufio . Scanner ) error {
err := execStmt ( qgen . Builder . AddColumn ( "moderation_logs" , tC { "extra" , "text" , 0 , false , false , "" } , nil ) )
if err != nil {
return err
}
return execStmt ( qgen . Builder . AddColumn ( "administration_logs" , tC { "extra" , "text" , 0 , false , false , "" } , nil ) )
}
2019-12-08 03:40:56 +00:00
func patch28 ( scanner * bufio . Scanner ) error {
return execStmt ( qgen . Builder . AddColumn ( "users" , tC { "enable_embeds" , "int" , 0 , false , false , "-1" } , nil ) )
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
}
// The word counter might run into problems with some languages where words aren't as obviously demarcated, I would advise turning it off in those cases, or if it becomes annoying in general, really.
func WordCount ( input string ) ( count int ) {
input = strings . TrimSpace ( input )
if input == "" {
return 0
}
var inSpace bool
for _ , value := range input {
if unicode . IsSpace ( value ) || unicode . IsPunct ( value ) {
if ! inSpace {
inSpace = true
}
} else if inSpace {
count ++
inSpace = false
}
}
return count + 1
}
func patch29 ( scanner * bufio . Scanner ) error {
f := func ( tbl , idCol string ) error {
return acc ( ) . Select ( tbl ) . Cols ( idCol + ",content" ) . Each ( func ( rows * sql . Rows ) error {
var id int
var content string
err := rows . Scan ( & id , & content )
if err != nil {
return err
}
_ , err = acc ( ) . Update ( tbl ) . Set ( "words=?" ) . Where ( idCol + "=?" ) . Exec ( WordCount ( content ) , id )
return err
} )
}
err := f ( "topics" , "tid" )
if err != nil {
return err
}
err = f ( "replies" , "rid" )
if err != nil {
return err
}
meta , err := meta . NewDefaultMetaStore ( acc ( ) )
if err != nil {
return err
}
err = meta . Set ( "sched" , "recalc" )
if err != nil {
return err
}
2020-07-14 21:50:29 +00:00
fixCols := func ( tbls ... string ) error {
for _ , tbl := range tbls {
//err := execStmt(qgen.Builder.RenameColumn(tbl, "ipaddress","ip"))
err := execStmt ( qgen . Builder . ChangeColumn ( tbl , "ipaddress" , ccol ( "ip" , 200 , "''" ) ) )
if err != nil {
return err
}
err = execStmt ( qgen . Builder . SetDefaultColumn ( tbl , "ip" , "varchar" , "" ) )
if err != nil {
return err
}
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
}
2020-07-14 21:50:29 +00:00
return nil
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
}
2020-07-14 21:50:29 +00:00
err = fixCols ( "topics" , "replies" , "polls_votes" , "users_replies" )
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
if err != nil {
return err
}
err = execStmt ( qgen . Builder . SetDefaultColumn ( "replies" , "lastEdit" , "int" , "0" ) )
if err != nil {
return err
}
err = execStmt ( qgen . Builder . SetDefaultColumn ( "replies" , "lastEditBy" , "int" , "0" ) )
if err != nil {
return err
}
err = execStmt ( qgen . Builder . SetDefaultColumn ( "users_replies" , "lastEdit" , "int" , "0" ) )
if err != nil {
return err
}
err = execStmt ( qgen . Builder . SetDefaultColumn ( "users_replies" , "lastEditBy" , "int" , "0" ) )
if err != nil {
return err
}
return execStmt ( qgen . Builder . AddColumn ( "activity_stream" , tC { "extra" , "varchar" , 200 , false , false , "''" } , nil ) )
}
2020-02-09 10:00:08 +00:00
func patch30 ( scanner * bufio . Scanner ) error {
2021-04-07 14:23:11 +00:00
e := execStmt ( qgen . Builder . AddColumn ( "users_groups_promotions" , tC { "registeredFor" , "int" , 0 , false , false , "0" } , nil ) )
if e != nil {
return e
2020-02-09 10:00:08 +00:00
}
return execStmt ( qgen . Builder . SetDefaultColumn ( "users" , "last_ip" , "varchar" , "" ) )
}
2020-02-21 11:42:21 +00:00
2020-07-14 21:50:29 +00:00
func patch31 ( scanner * bufio . Scanner ) ( e error ) {
addKey := func ( tbl , col string , tk qgen . DBTableKey ) error {
2021-04-07 14:23:11 +00:00
/ * e := execStmt ( qgen . Builder . RemoveIndex ( tbl , col ) )
if e != nil {
return e
2020-07-14 21:50:29 +00:00
} * /
return execStmt ( qgen . Builder . AddKey ( tbl , col , tk ) )
2020-02-21 11:42:21 +00:00
}
2021-04-07 14:23:11 +00:00
e = addKey ( "topics" , "title" , tK { "title" , "fulltext" , "" , false } )
if e != nil {
return e
2020-02-21 11:42:21 +00:00
}
2021-04-07 14:23:11 +00:00
e = addKey ( "topics" , "content" , tK { "content" , "fulltext" , "" , false } )
if e != nil {
return e
2020-02-21 11:42:21 +00:00
}
2020-07-14 21:50:29 +00:00
return addKey ( "replies" , "content" , tK { "content" , "fulltext" , "" , false } )
}
func createTable ( tbl , charset , collation string , cols [ ] tC , keys [ ] tK ) error {
2021-04-07 14:23:11 +00:00
e := execStmt ( qgen . Builder . DropTable ( tbl ) )
if e != nil {
return e
2020-02-21 11:42:21 +00:00
}
2020-07-14 21:50:29 +00:00
return execStmt ( qgen . Builder . CreateTable ( tbl , charset , collation , cols , keys ) )
2020-03-21 08:55:15 +00:00
}
2020-02-23 09:08:47 +00:00
func patch32 ( scanner * bufio . Scanner ) error {
2020-03-21 08:55:15 +00:00
return createTable ( "perfchunks" , "" , "" ,
2020-02-26 10:34:38 +00:00
[ ] tC {
2021-01-06 06:41:08 +00:00
{ "low" , "int" , 0 , false , false , "0" } ,
{ "high" , "int" , 0 , false , false , "0" } ,
{ "avg" , "int" , 0 , false , false , "0" } ,
{ "createdAt" , "datetime" , 0 , false , false , "" } ,
2020-02-26 10:34:38 +00:00
} , nil ,
2020-03-21 08:55:15 +00:00
)
2020-02-26 10:34:38 +00:00
}
func patch33 ( scanner * bufio . Scanner ) error {
return execStmt ( qgen . Builder . AddColumn ( "viewchunks" , tC { "avg" , "int" , 0 , false , false , "0" } , nil ) )
}
2020-07-14 21:50:29 +00:00
func patch34 ( scanner * bufio . Scanner ) error {
/ * err := createTable ( "tables" , "" , "" ,
[ ] tC {
2021-01-06 06:41:08 +00:00
{ "id" , "int" , 0 , false , true , "" } ,
2020-07-14 21:50:29 +00:00
ccol ( "name" , 200 , "" ) ,
} ,
[ ] tK {
2021-01-06 06:41:08 +00:00
{ "id" , "primary" , "" , false } ,
{ "name" , "unique" , "" , false } ,
2020-07-14 21:50:29 +00:00
} ,
)
if err != nil {
return err
}
insert := func ( tbl , cols , fields string ) {
if err != nil {
return
}
err = execStmt ( qgen . Builder . SimpleInsert ( tbl , cols , fields ) )
}
insert ( "tables" , "name" , "forums" )
insert ( "tables" , "name" , "topics" )
insert ( "tables" , "name" , "replies" )
// ! Hold onto freplies for a while longer
insert ( "tables" , "name" , "freplies" ) * /
/ * err := execStmt ( qgen . Builder . AddColumn ( "topics" , tC { "attachCount" , "int" , 0 , false , false , "0" } , nil ) )
if err != nil {
return err
} * /
overwriteColumn := func ( tbl , col string , tc qgen . DBTableColumn ) error {
/ * e := execStmt ( qgen . Builder . DropColumn ( tbl , col ) )
if e != nil {
return e
} * /
return execStmt ( qgen . Builder . AddColumn ( tbl , tc , nil ) )
}
err := overwriteColumn ( "users" , "profile_comments" , tC { "profile_comments" , "int" , 0 , false , false , "0" } )
if err != nil {
return err
}
err = overwriteColumn ( "users" , "who_can_convo" , tC { "who_can_convo" , "int" , 0 , false , false , "0" } )
if err != nil {
return err
}
setDefault := func ( tbl , col , typ , val string ) {
if err != nil {
return
}
err = execStmt ( qgen . Builder . SetDefaultColumn ( tbl , col , typ , val ) )
}
setDefault ( "users_groups" , "permissions" , "text" , "{}" )
setDefault ( "users_groups" , "plugin_perms" , "text" , "{}" )
setDefault ( "forums_permissions" , "permissions" , "text" , "{}" )
setDefault ( "topics" , "content" , "text" , "" )
setDefault ( "topics" , "parsed_content" , "text" , "" )
setDefault ( "replies" , "content" , "text" , "" )
setDefault ( "replies" , "parsed_content" , "text" , "" )
//setDefault("revisions", "content", "text", "")
setDefault ( "users_replies" , "content" , "text" , "" )
setDefault ( "users_replies" , "parsed_content" , "text" , "" )
setDefault ( "pages" , "body" , "text" , "" )
setDefault ( "pages" , "allowedGroups" , "text" , "" )
setDefault ( "moderation_logs" , "extra" , "text" , "" )
setDefault ( "administration_logs" , "extra" , "text" , "" )
if err != nil {
return err
}
return nil
}
2021-01-02 21:46:24 +00:00
func patch35 ( scanner * bufio . Scanner ) error {
2021-04-07 14:23:11 +00:00
e := execStmt ( qgen . Builder . AddColumn ( "topics" , tC { "weekEvenViews" , "int" , 0 , false , false , "0" } , nil ) )
if e != nil {
return e
2021-01-02 21:46:24 +00:00
}
return execStmt ( qgen . Builder . AddColumn ( "topics" , tC { "weekOddViews" , "int" , 0 , false , false , "0" } , nil ) )
}
2021-04-07 14:23:11 +00:00
func patch36 ( scanner * bufio . Scanner ) error {
e := createTable ( "forums_actions" , "utf8mb4" , "utf8mb4_general_ci" ,
[ ] tC {
{ "faid" , "int" , 0 , false , true , "" } ,
{ "fid" , "int" , 0 , false , false , "" } ,
bcol ( "runOnTopicCreation" , false ) ,
{ "runDaysAfterTopicCreation" , "int" , 0 , false , false , "0" } ,
{ "runDaysAfterTopicLastReply" , "int" , 0 , false , false , "0" } ,
ccol ( "action" , 50 , "" ) ,
ccol ( "extra" , 200 , "''" ) ,
} ,
[ ] tK {
{ "faid" , "primary" , "" , false } ,
} ,
)
if e != nil {
return e
}
//qgen.Install.SimpleInsert("settings", "name, content, type, constraints", "'activation_type','1','list','1-3'")
return execStmt ( qgen . Builder . SimpleInsert ( "settings" , "name, content, type" , "'avatar_visibility','0','list','0-1'" ) )
}