1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-19 16:46:23 -07:00

Add migration stuff for filter tables

This commit is contained in:
Eggbertx 2024-08-10 20:01:33 -07:00
parent c7f15e3d25
commit e12b2fb982
19 changed files with 295 additions and 47 deletions

View file

@ -25,7 +25,7 @@ func TestBuildJS(t *testing.T) {
}
outDir := t.TempDir()
config.SetVersion("3.10.2")
config.SetVersion("3.11.0")
systemCriticalCfg := config.GetSystemCriticalConfig()
systemCriticalCfg.DocumentRoot = path.Join(outDir, "html")
systemCriticalCfg.TemplateDir = path.Join(testRoot, "templates")
@ -156,7 +156,7 @@ func TestBuildFrontPage(t *testing.T) {
}
t.Run(driver, func(t *testing.T) {
outDir := t.TempDir()
config.SetVersion("3.10.2")
config.SetVersion("3.11.0")
systemCriticalCfg := config.GetSystemCriticalConfig()
systemCriticalCfg.DocumentRoot = path.Join(outDir, "html")
systemCriticalCfg.TemplateDir = path.Join(testRoot, "templates")

View file

@ -7,7 +7,7 @@ var defaultStyle = "test1.css";
var webroot = "/chan";
var serverTZ = 8;
var fileTypes = [];`
expectedMinifiedFront = `<!doctype html><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>Gochan</title><link rel=stylesheet href=/chan/css/global.css><link id=theme rel=stylesheet href=/chan/css/test1.css><link rel="shortcut icon" href=/chan/favicon.png><script src=/chan/js/consts.js></script><script src=/chan/js/gochan.js></script><div id=topbar><div class=topbar-section><a href=/chan/ class=topbar-item>home</a></div><div class=topbar-section><a href=/chan/test/ class=topbar-item title="Testing board">/test/</a><a href=/chan/test2/ class=topbar-item title="Testing board 2">/test2/</a></div></div><div id=content><div id=top-pane><span id=site-title>Gochan</span><br><span id=site-slogan></span></div><br><div id=frontpage><div class=section-block style="margin: 16px 64px 16px 64px;"><div class="section-body front-intro">Welcome to Gochan!</div></div><div class=section-block><div class=section-title-block><b>Boards</b></div><div class=section-body><ul style="float:left; list-style: none"><li style="text-align: center; font-weight: bold"><b><u>Main</u></b><li><a href=/chan/test/ title="Board for testing description">/test/</a> — Testing board<li><a href=/chan/test2/ title="Board for testing description 2">/test2/</a> — Testing board 2</ul></div></div><div class=section-block><div class=section-title-block><b>Recent Posts</b></div><div class=section-body><div id=recent-posts><div class=recent-post><a href=/chan/test/res/1.html#1 class=front-reply target=_blank><img src=/chan/test/thumb alt="post thumbnail"></a><br><br><a href=/chan/test/>/test/</a><hr>message_raw</div><div class=recent-post><a href=/chan/test/res/1.html#2 class=front-reply target=_blank><img src=/chan/test/thumb alt="post thumbnail"></a><br><br><a href=/chan/test/>/test/</a><hr>message_raw</div></div></div></div></div><div id=footer>Powered by <a href=http://github.com/gochan-org/gochan/>Gochan 3.10.2</a><br></div></div>`
expectedMinifiedFront = `<!doctype html><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>Gochan</title><link rel=stylesheet href=/chan/css/global.css><link id=theme rel=stylesheet href=/chan/css/test1.css><link rel="shortcut icon" href=/chan/favicon.png><script src=/chan/js/consts.js></script><script src=/chan/js/gochan.js></script><div id=topbar><div class=topbar-section><a href=/chan/ class=topbar-item>home</a></div><div class=topbar-section><a href=/chan/test/ class=topbar-item title="Testing board">/test/</a><a href=/chan/test2/ class=topbar-item title="Testing board 2">/test2/</a></div></div><div id=content><div id=top-pane><span id=site-title>Gochan</span><br><span id=site-slogan></span></div><br><div id=frontpage><div class=section-block style="margin: 16px 64px 16px 64px;"><div class="section-body front-intro">Welcome to Gochan!</div></div><div class=section-block><div class=section-title-block><b>Boards</b></div><div class=section-body><ul style="float:left; list-style: none"><li style="text-align: center; font-weight: bold"><b><u>Main</u></b><li><a href=/chan/test/ title="Board for testing description">/test/</a> — Testing board<li><a href=/chan/test2/ title="Board for testing description 2">/test2/</a> — Testing board 2</ul></div></div><div class=section-block><div class=section-title-block><b>Recent Posts</b></div><div class=section-body><div id=recent-posts><div class=recent-post><a href=/chan/test/res/1.html#1 class=front-reply target=_blank><img src=/chan/test/thumb alt="post thumbnail"></a><br><br><a href=/chan/test/>/test/</a><hr>message_raw</div><div class=recent-post><a href=/chan/test/res/1.html#2 class=front-reply target=_blank><img src=/chan/test/thumb alt="post thumbnail"></a><br><br><a href=/chan/test/>/test/</a><hr>message_raw</div></div></div></div></div><div id=footer>Powered by <a href=http://github.com/gochan-org/gochan/>Gochan 3.11.0</a><br></div></div>`
expectedUnminifiedFront = `<!DOCTYPE html>
<html>
<head>
@ -74,7 +74,7 @@ var fileTypes = [];`
</div>
</div>
<div id="footer">
Powered by <a href="http://github.com/gochan-org/gochan/">Gochan 3.10.2</a><br />
Powered by <a href="http://github.com/gochan-org/gochan/">Gochan 3.11.0</a><br />
</div>
</div>
</body>

View file

@ -3,6 +3,7 @@ package gcsql
import (
"errors"
"fmt"
"strconv"
"github.com/gochan-org/gochan/pkg/config"
"github.com/gochan-org/gochan/pkg/gcutil"
@ -15,17 +16,16 @@ const (
DBModernButBehind
DBUpToDate
DBModernButAhead
targetDatabaseVersion = 3
)
var (
// ErrInvalidVersion is used when the db contains a database_version table
// but zero or more than one versions were found
ErrInvalidVersion = errors.New("database contains database_version table but zero or more than one versions were found")
ErrCorruptedDB = errors.New("database contains gochan prefixed tables but is missing versioning tables (possibly corrupted)")
ErrDeprecatedDB = errors.New("database layout is deprecated, please run gochan-migration -updatedb")
ErrInvalidDBVersion = errors.New("invalid version flag returned by GetCompleteDatabaseVersion()")
ErrInvalidVersion = errors.New("database contains database_version table but zero or more than one versions were found")
ErrCorruptedDB = errors.New("database contains gochan prefixed tables but is missing versioning tables (possibly corrupted)")
ErrDeprecatedDB = errors.New("database layout is deprecated, please run gochan-migration -updatedb")
ErrInvalidDBVersion = errors.New("invalid version flag returned by GetCompleteDatabaseVersion()")
targetDatabaseVersion = 3
)
func initDB(initFile string) error {
@ -83,7 +83,12 @@ func GetCompleteDatabaseVersion() (dbVersion, dbFlag int, err error) {
}
// CheckAndInitializeDatabase checks the validity of the database and initialises it if it is empty
func CheckAndInitializeDatabase(dbType string) error {
func CheckAndInitializeDatabase(dbType string, targetDbVersionStr string) (err error) {
targetDatabaseVersion, err = strconv.Atoi(targetDbVersionStr)
if err != nil {
return err
}
dbVersion, versionFlag, err := GetCompleteDatabaseVersion()
if err != nil {
return err