mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-02 02:36:24 -07:00
Remove SQLite support due to instability
This commit is contained in:
parent
31f9c57a35
commit
a69b6748c7
16 changed files with 22 additions and 97 deletions
|
@ -6,5 +6,4 @@ Split tripcode from username during migration
|
|||
|
||||
Mysql: SERIAL = uint64 NOT NULL AUTO_INCREMENT UNIQUE
|
||||
Postgres SERIAL = int32 NOT NULL AUTO_INCREMENT UNIQUE
|
||||
sqlite INTEGER = variable INTEGER
|
||||
|
||||
|
|
4
Makefile
4
Makefile
|
@ -69,7 +69,6 @@ dependencies:
|
|||
github.com/aquilax/tripcode \
|
||||
golang.org/x/crypto/bcrypt \
|
||||
github.com/frustra/bbcode \
|
||||
github.com/mattn/go-sqlite3 \
|
||||
github.com/tdewolff/minify \
|
||||
github.com/mojocn/base64Captcha
|
||||
|
||||
|
@ -88,7 +87,7 @@ install:
|
|||
$(info cp sample-configs/gochan.example.json /etc/gochan/gochan.json)
|
||||
ifeq (${GCOS_NAME},linux)
|
||||
$(info If your distro has systemd, you will also need to run the following commands)
|
||||
$(info cp sample-configs/gochan-[mysql|postgresql|sqlite3].service /lib/systemd/system/gochan.service)
|
||||
$(info cp sample-configs/gochan-[mysql|postgresql].service /lib/systemd/system/gochan.service)
|
||||
$(info systemctl daemon-reload)
|
||||
$(info systemctl enable gochan.service)
|
||||
$(info systemctl start gochan.service)
|
||||
|
@ -140,7 +139,6 @@ else ifeq (${GCOS_NAME},windows)
|
|||
else
|
||||
cp sample-configs/gochan-mysql.service ${RELEASE_DIR}/sample-configs/
|
||||
cp sample-configs/gochan-postgresql.service ${RELEASE_DIR}/sample-configs/
|
||||
cp sample-configs/gochan-sqlite3.service ${RELEASE_DIR}/sample-configs/
|
||||
tar -C releases -zcvf ${RELEASE_DIR}.tar.gz ${RELEASE_NAME}
|
||||
endif
|
||||
|
||||
|
|
|
@ -17,10 +17,9 @@ Demo installation: https://gochan.org
|
|||
5. Go to http://[gochan url]/manage?action=staff, log in (default username/password is admin/password), and create a new admin user (and any other staff users as necessary). Then delete the admin user for security.
|
||||
|
||||
## Configuration
|
||||
1. Make sure to set `DBtype`, `DBhost`, `DBname`, `DBusername`, and `DBpassword`, since these are required to connect to your SQL database. Valid `DBtype` values are "mysql", "postgres", and "sqlite3".
|
||||
1. Make sure to set `DBtype`, `DBhost`, `DBname`, `DBusername`, and `DBpassword`, since these are required to connect to your SQL database. Valid `DBtype` values are "mysql" and "postgres" (sqlite3 is no longer supported for stability reasons).
|
||||
1. To connect to a MySQL database, set `DBhost` to "tcp(ip:3306)" or a different port, if necessary.
|
||||
2. To connect to a PostgreSQL database, set `DBhost` to the IP address or hostname. Using a UNIX socket may work as well, but it is currently untested.
|
||||
3. To connect to a SQLite database, set `DBhost` to the path of the database file. It will be created if it does not already exist.
|
||||
2. Set `DomainRegex`,`SiteDomain`, since these are necessary in order to post and log in as a staff member.
|
||||
3. If you want to see debugging info/noncritical warnings, set verbosity to 1.
|
||||
|
||||
|
@ -29,7 +28,7 @@ See [`docker/README.md`](docker/README.md)
|
|||
|
||||
## For developers (using Vagrant)
|
||||
1. Install Vagrant and Virtualbox. Vagrant lets you create a virtual machine and run a custom setup/installation script to make installation easier and faster.
|
||||
2. From the command line, cd into vagrant/ and run `vagrant up`. By default, MySQL/MariaDB is used, but if you want to test with a different SQL type, run `GC_DBTYPE=dbtype vagrant up`, replacing "dbtype" with either mysql, postgresql, or sqlite3.
|
||||
2. From the command line, cd into vagrant/ and run `vagrant up`. By default, MySQL/MariaDB is used, but if you want to test with a different SQL type, run `GC_DBTYPE=dbtype vagrant up`, replacing "dbtype" with either mysql or postgresql
|
||||
3. After it finishes installing the Ubuntu VM, follow the printed instructions.
|
||||
|
||||
# Theme development
|
||||
|
|
|
@ -65,7 +65,6 @@ function dependencies {
|
|||
github.com/aquilax/tripcode `
|
||||
golang.org/x/crypto/bcrypt `
|
||||
github.com/frustra/bbcode `
|
||||
github.com/mattn/go-sqlite3 `
|
||||
github.com/tdewolff/minify `
|
||||
github.com/mojocn/base64Captcha
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import (
|
|||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/lib/pq"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -3,7 +3,6 @@ FROM golang:1.13.9-alpine3.11
|
|||
RUN apk --no-cache add \
|
||||
postgresql-client \
|
||||
mariadb-client \
|
||||
sqlite \
|
||||
nginx \
|
||||
ffmpeg \
|
||||
make \
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
set -euo pipefail
|
||||
|
||||
if [ -z "$DBTYPE" ]; then
|
||||
echo "DBTYPE environment variable not set, must be 'mysql', 'postgresql', or 'sqlite3'"
|
||||
echo "DBTYPE environment variable not set, must be 'mysql' or 'postgresql' (sqlite3 no longer supported)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
@ -88,10 +88,6 @@ if [ "$DBTYPE" = "postgresql" ]; then
|
|||
sed -i /etc/gochan/gochan.json \
|
||||
-e 's/"DBtype": ".*"/"DBtype": "postgres"/' \
|
||||
-e 's/"DBhost": ".*"/"DBhost": "127.0.0.1"/'
|
||||
elif [ "$DBTYPE" = "sqlite3" ]; then
|
||||
sed -i /etc/gochan/gochan.json \
|
||||
-e 's/"DBtype": ".*"/"DBtype": "sqlite3"/' \
|
||||
-e 's/"DBhost": ".*"/"DBhost": "/usr/local/share/gochan/gochan.db"/'
|
||||
fi
|
||||
|
||||
echo
|
||||
|
|
1
go.mod
1
go.mod
|
@ -8,7 +8,6 @@ require (
|
|||
github.com/frustra/bbcode v0.0.0-20180807171629-48be21ce690c
|
||||
github.com/go-sql-driver/mysql v1.5.0
|
||||
github.com/lib/pq v1.5.2
|
||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible
|
||||
github.com/mojocn/base64Captcha v1.3.1
|
||||
github.com/nranchev/go-libGeoIP v0.0.0-20170629073846-d6d4a9a4c7e8 // indirect
|
||||
github.com/tdewolff/minify v2.3.6+incompatible
|
||||
|
|
2
go.sum
2
go.sum
|
@ -12,8 +12,6 @@ github.com/lib/pq v1.4.0 h1:TmtCFbH+Aw0AixwyttznSMQDgbR5Yed/Gg6S8Funrhc=
|
|||
github.com/lib/pq v1.4.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.5.2 h1:yTSXVswvWUOQ3k1sd7vJfDrbSl8lKuscqFJRqjC0ifw=
|
||||
github.com/lib/pq v1.5.2/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
|
||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/mojocn/base64Captcha v1.2.2 h1:NTFnThPVrb3tR66JO/N8/ZHsyFrNc7ho+xRpxBUEIlo=
|
||||
github.com/mojocn/base64Captcha v1.2.2/go.mod h1:wAQCKEc5bDujxKRmbT6/vTnTt5CjStQ8bRfPWUuz/iY=
|
||||
github.com/mojocn/base64Captcha v1.3.1 h1:2Wbkt8Oc8qjmNJ5GyOfSo4tgVQPsbKMftqASnq8GlT0=
|
||||
|
|
|
@ -190,7 +190,7 @@ func InitConfig(versionStr string) {
|
|||
"TemplateDir not set in gochan.json or unable to locate template directory, halting.")
|
||||
|
||||
Config.checkString(Config.DBtype, "", true,
|
||||
"DBtype not set in gochan.json, halting (currently supported values: mysql,postgresql,sqlite3)")
|
||||
"DBtype not set in gochan.json, halting (currently supported values: mysql,postgresql)")
|
||||
Config.checkString(Config.DBhost, "", true,
|
||||
"DBhost not set in gochan.json, halting.")
|
||||
Config.DBname = Config.checkString(Config.DBname, "gochan", false,
|
||||
|
|
|
@ -39,14 +39,9 @@ func ConnectToDB(host string, dbType string, dbName string, username string, pas
|
|||
connStr = fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=disable",
|
||||
username, password, host, dbName)
|
||||
nilTimestamp = "0001-01-01 00:00:00"
|
||||
case "sqlite3":
|
||||
gclog.Print(gclog.LStdLog, "sqlite3 support is still flaky, consider using mysql or postgres")
|
||||
connStr = fmt.Sprintf("file:%s?mode=rwc&_auth&_auth_user=%s&_auth_pass=%s&cache=shared",
|
||||
host, username, password)
|
||||
nilTimestamp = "0001-01-01 00:00:00+00:00"
|
||||
default:
|
||||
gclog.Printf(FatalSQLFlags,
|
||||
`Invalid DBtype %q in gochan.json, valid values are "mysql", "postgres", and "sqlite3"`, dbType)
|
||||
`Invalid DBtype %q in gochan.json, valid values are "mysql" and "postgres" (sqlite3 is no longer supported for stability reasons)`, dbType)
|
||||
}
|
||||
dbDriver = dbType
|
||||
var err error
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
var (
|
||||
ErrMultipleDBVersions = errors.New("More than one version in database")
|
||||
ErrNilBoard = errors.New("Board is nil")
|
||||
ErrUnsupportedDB = errors.New("Unsupported DBtype")
|
||||
)
|
||||
|
||||
// GetAllNondeletedMessageRaw gets all the raw message texts from the database, saved per id
|
||||
|
@ -597,7 +598,7 @@ func InsertPost(post *Post, bump bool) error {
|
|||
}
|
||||
|
||||
//Retrieves next free ID, explicitly inserts it, keeps retrying until succesfull insert or until a non-pk error is encountered.
|
||||
//This is done because mysql/sqlite doesnt support RETURNING and both LAST_INSERT_ID() and last_row_id() are not thread-safe
|
||||
//This is done because mysql doesnt support RETURNING and both LAST_INSERT_ID() and last_row_id() are not thread-safe
|
||||
isPrimaryKeyError := true
|
||||
for isPrimaryKeyError {
|
||||
nextFreeID, err := getNextFreeID("DBPREFIXposts")
|
||||
|
@ -630,7 +631,7 @@ func InsertPost(post *Post, bump bool) error {
|
|||
func createThread(boardID int, locked bool, stickied bool, anchored bool, cyclical bool) (threadID int, err error) {
|
||||
const sql = `INSERT INTO DBPREFIXthreads (board_id, locked, stickied, anchored, cyclical) VALUES (?,?,?,?,?)`
|
||||
//Retrieves next free ID, explicitly inserts it, keeps retrying until succesfull insert or until a non-pk error is encountered.
|
||||
//This is done because mysql/sqlite doesnt support RETURNING and both LAST_INSERT_ID() and last_row_id() are not thread-safe
|
||||
//This is done because mysql doesnt support RETURNING and both LAST_INSERT_ID() and last_row_id() are not thread-safe
|
||||
isPrimaryKeyError := true
|
||||
for isPrimaryKeyError {
|
||||
threadID, err = getNextFreeID("DBPREFIXthreads")
|
||||
|
@ -992,25 +993,12 @@ func getNextFreeID(tableName string) (ID int, err error) {
|
|||
}
|
||||
|
||||
func doesTableExist(tableName string) (bool, error) {
|
||||
const mysqlPostgresql = `SELECT COUNT(*)
|
||||
const existQuery = `SELECT COUNT(*)
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
WHERE TABLE_NAME = ?`
|
||||
const sqlite = `SELECT
|
||||
COUNT(name)
|
||||
FROM
|
||||
sqlite_master
|
||||
WHERE
|
||||
type ='table' AND
|
||||
name NOT LIKE 'sqlite_%' AND name = ?;`
|
||||
var sql string
|
||||
switch config.Config.DBtype {
|
||||
case "mysql":
|
||||
sql = mysqlPostgresql
|
||||
case "postgres":
|
||||
sql = mysqlPostgresql
|
||||
}
|
||||
|
||||
var count int
|
||||
err := QueryRowSQL(sql, []interface{}{config.Config.DBprefix + tableName}, []interface{}{&count})
|
||||
err := QueryRowSQL(existQuery, []interface{}{config.Config.DBprefix + tableName}, []interface{}{&count})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -1023,27 +1011,12 @@ func doesGochanPrefixTableExist() (bool, error) {
|
|||
if config.Config.DBprefix == "" {
|
||||
return false, nil
|
||||
}
|
||||
var mysqlPostgresql = `SELECT count(*)
|
||||
var prefixTableExist = `SELECT count(*)
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
WHERE TABLE_NAME LIKE '` + config.Config.DBprefix + `%'`
|
||||
var sqlite = `SELECT
|
||||
COUNT(name)
|
||||
FROM
|
||||
sqlite_master
|
||||
WHERE
|
||||
type ='table' AND
|
||||
name LIKE '` + config.Config.DBprefix + `%';`
|
||||
var sql string
|
||||
switch config.Config.DBtype {
|
||||
case "mysql":
|
||||
sql = mysqlPostgresql
|
||||
case "postgres":
|
||||
sql = mysqlPostgresql
|
||||
case "sqlite3":
|
||||
sql = sqlite
|
||||
}
|
||||
WHERE TABLE_NAME LIKE 'DBPREFIX%'`
|
||||
|
||||
var count int
|
||||
err := QueryRowSQL(sql, []interface{}{}, []interface{}{&count})
|
||||
err := QueryRowSQL(prefixTableExist, []interface{}{}, []interface{}{&count})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -7,13 +7,12 @@ import (
|
|||
|
||||
"github.com/gochan-org/gochan/pkg/config"
|
||||
"github.com/gochan-org/gochan/pkg/gclog"
|
||||
"github.com/gochan-org/gochan/pkg/gcutil"
|
||||
)
|
||||
|
||||
const (
|
||||
MySQLDatetimeFormat = "2006-01-02 15:04:05"
|
||||
unsupportedSQLVersionMsg = `Received syntax error while preparing a SQL string.
|
||||
This means that either there is a bug in gochan's code (hopefully not) or that you are using an unsupported My/Postgre/SQLite version.
|
||||
This means that either there is a bug in gochan's code (hopefully not) or that you are using an unsupported My/Postgre version.
|
||||
Before reporting an error, make sure that you are using the up to date version of your selected SQL server.
|
||||
Error text: %s`
|
||||
)
|
||||
|
@ -32,10 +31,6 @@ func sqlVersionErr(err error, query *string) error {
|
|||
if !strings.Contains(errText, "syntax error at or near") {
|
||||
return err
|
||||
}
|
||||
case "sqlite3":
|
||||
if !strings.Contains(errText, "Error: near ") {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if config.Config.DebugMode {
|
||||
return fmt.Errorf(unsupportedSQLVersionMsg+"\nQuery: "+*query, errText)
|
||||
|
@ -49,8 +44,6 @@ func PrepareSQL(query string) (*sql.Stmt, error) {
|
|||
switch dbDriver {
|
||||
case "mysql":
|
||||
fallthrough
|
||||
case "sqlite3":
|
||||
preparedStr = query
|
||||
case "postgres":
|
||||
arr := strings.Split(query, "?")
|
||||
for i := range arr {
|
||||
|
@ -60,6 +53,8 @@ func PrepareSQL(query string) (*sql.Stmt, error) {
|
|||
arr[i] += fmt.Sprintf("$%d", i+1)
|
||||
}
|
||||
preparedStr = strings.Join(arr, "")
|
||||
default:
|
||||
return nil, ErrUnsupportedDB
|
||||
}
|
||||
stmt, err := db.Prepare(sqlReplacer.Replace(preparedStr))
|
||||
if err != nil {
|
||||
|
@ -168,11 +163,6 @@ func errFilterDuplicatePrimaryKey(err error) (isPKerror bool, nonPKerror error)
|
|||
if !strings.Contains(err.Error(), "duplicate key value violates unique constraint") {
|
||||
return false, err
|
||||
}
|
||||
case "sqlite3":
|
||||
return false, gcutil.ErrNotImplemented
|
||||
// if !strings.Contains(err.Error(), "Error: near ") {//TODO fill in correct error string
|
||||
// return false, err
|
||||
// }
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
[Unit]
|
||||
Description=gochan Daemon
|
||||
After=network.target
|
||||
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/local/bin/gochan
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
4
vagrant/Vagrantfile
vendored
4
vagrant/Vagrantfile
vendored
|
@ -2,8 +2,8 @@
|
|||
# vi: set ft=ruby :
|
||||
|
||||
DBTYPE = ENV.fetch("GC_DBTYPE", "mysql")
|
||||
if DBTYPE != "mysql" && DBTYPE != "postgresql" && DBTYPE != "sqlite3"
|
||||
puts "Invalid GC_DBTYPE environment variable, must be mysql, postgresql, or sqlite3, got #{DBTYPE}"
|
||||
if DBTYPE != "mysql" && DBTYPE != "postgresql"
|
||||
puts "Invalid GC_DBTYPE environment variable, must be mysql or postgresql, got #{DBTYPE}"
|
||||
abort
|
||||
end
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ set -euo pipefail
|
|||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
if [ -z "$DBTYPE" ]; then
|
||||
echo "DBTYPE environment variable not set, must be 'mysql', 'postgresql', or 'sqlite3'"
|
||||
echo "DBTYPE environment variable not set, must be 'mysql' or 'postgresql' (sqlite3 no longer supported)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
@ -52,9 +52,6 @@ elif [ "$DBTYPE" == "postgresql" ]; then
|
|||
systemctl daemon-reload
|
||||
systemctl enable gochan.service
|
||||
fi
|
||||
elif [ "$DBTYPE" == "sqlite3" ]; then
|
||||
# using SQLite (mostly stable)
|
||||
apt-get -y install sqlite3
|
||||
elif [ "$DBTYPE" == "mssql" ]; then
|
||||
# using Microsoft SQL Server (currently unsupported)
|
||||
echo "Microsoft SQL Server not supported yet";
|
||||
|
@ -99,10 +96,6 @@ if [ "$DBTYPE" = "postgresql" ]; then
|
|||
sed -i /etc/gochan/gochan.json \
|
||||
-e 's/"DBtype": ".*"/"DBtype": "postgres"/' \
|
||||
-e 's/"DBhost": ".*"/"DBhost": "127.0.0.1"/'
|
||||
elif [ "$DBTYPE" = "sqlite3" ]; then
|
||||
sed -i /etc/gochan/gochan.json \
|
||||
-e 's/"DBtype": ".*"/"DBtype": "sqlite3"/' \
|
||||
-e 's/"DBhost": ".*"/"DBhost": "gochan.db"/'
|
||||
fi
|
||||
|
||||
# a convenient script for connecting to the db, whichever type we're using
|
||||
|
@ -113,8 +106,6 @@ if [ "$DBTYPE" = "mysql" ] || [ -z "$DBTYPE" ]; then
|
|||
mysql -stu gochan -D gochan -pgochan
|
||||
elif [ "$DBTYPE" = "postgresql" ]; then
|
||||
psql -U gochan -h 127.0.0.1 gochan
|
||||
elif [ "$DBTYPE" = "sqlite3" ]; then
|
||||
sqlite3 ~/gochan/gochan.db
|
||||
else
|
||||
echo "DB type '$DBTYPE' not supported"
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue