mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-03 07:36:23 -07:00
Merge pull request #73 from gochan-org/mysql-compatibility
Fix compatibility with mainline MySQL
This commit is contained in:
commit
5de1d61a3d
13 changed files with 122 additions and 49 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "gochan.js",
|
||||
"version": "3.5.0",
|
||||
"version": "3.5.1",
|
||||
"description": "",
|
||||
"type": "module",
|
||||
"source": "js/gochan.js",
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
<h1>404: File not found</h1>
|
||||
<img src="./lol 404.gif" border="0" alt="">
|
||||
<p>The requested file could not be found on this server.</p>
|
||||
<hr/>Site powered by <a href="https://github.com/gochan-org/gochan" target="_blank">Gochan</a> v3.5.0
|
||||
<hr/>Site powered by <a href="https://github.com/gochan-org/gochan" target="_blank">Gochan</a> v3.5.1
|
||||
</body>
|
||||
</html>
|
|
@ -7,6 +7,6 @@
|
|||
<h1>Error 500: Internal Server error</h1>
|
||||
<img src="./server500.gif" border="0" alt="">
|
||||
<p>The server encountered an error while trying to serve the page, and we apologize for the inconvenience. The <a href="https://en.wikipedia.org/wiki/Idiot">system administrator</a> will try to fix things as soon they get around to it, whenever that is. Hopefully soon.</p>
|
||||
<hr/>Site powered by <a href="https://github.com/gochan-org/gochan" target="_blank">Gochan</a> v3.5.0
|
||||
<hr/>Site powered by <a href="https://github.com/gochan-org/gochan" target="_blank">Gochan</a> v3.5.1
|
||||
</body>
|
||||
</html>
|
|
@ -7,6 +7,6 @@
|
|||
<h1>Error 502: Bad gateway</h1>
|
||||
<img src="./server500.gif" border="0" alt="">
|
||||
<p>The server encountered an error while trying to serve the page, and we apologize for the inconvenience. The <a href="https://en.wikipedia.org/wiki/Idiot">system administrator</a> will try to fix things as soon they get around to it, whenever that is. Hopefully soon.</p>
|
||||
<hr/>Site powered by <a href="https://github.com/gochan-org/gochan" target="_blank">Gochan</a> v3.5.0
|
||||
<hr/>Site powered by <a href="https://github.com/gochan-org/gochan" target="_blank">Gochan</a> v3.5.1
|
||||
</body>
|
||||
</html>
|
|
@ -4,6 +4,8 @@ import (
|
|||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/gochan-org/gochan/pkg/config"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -27,15 +29,20 @@ func RunSQLFile(path string) error {
|
|||
sqlStr := regexp.MustCompile("--.*\n?").ReplaceAllString(string(sqlBytes), " ")
|
||||
sqlArr := strings.Split(gcdb.replacer.Replace(sqlStr), ";")
|
||||
|
||||
tx, err := BeginTx()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
for _, statement := range sqlArr {
|
||||
statement = strings.Trim(statement, " \n\r\t")
|
||||
if len(statement) > 0 {
|
||||
if _, err = gcdb.db.Exec(statement); err != nil {
|
||||
if _, err = ExecTxSQL(tx, statement); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
// TODO: get gochan-migration working so this doesn't have to sit here
|
||||
|
@ -46,33 +53,87 @@ func tmpSqlAdjust() error {
|
|||
switch gcdb.driver {
|
||||
case "mysql":
|
||||
query = `SELECT COUNT(*) FROM information_schema.TABLE_CONSTRAINTS
|
||||
WHERE CONSTRAINT_NAME = 'wordfilters_staff_id_fk'
|
||||
WHERE CONSTRAINT_NAME = 'wordfilters_board_id_fk'
|
||||
AND TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'DBPREFIXwordfilters'`
|
||||
numConstraints := 3
|
||||
var numConstraints int
|
||||
if err = gcdb.QueryRowSQL(query,
|
||||
interfaceSlice(),
|
||||
interfaceSlice(&numConstraints)); err != nil {
|
||||
return err
|
||||
}
|
||||
if numConstraints > 0 {
|
||||
query = `ALTER TABLE DBPREFIXwordfilters DROP FOREIGN KEY IF EXISTS wordfilters_board_id_fk`
|
||||
query = `ALTER TABLE DBPREFIXwordfilters DROP FOREIGN KEY wordfilters_board_id_fk`
|
||||
} else {
|
||||
query = ""
|
||||
}
|
||||
query = `SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'DBPREFIXwordfilters'
|
||||
AND COLUMN_NAME = 'board_dirs'`
|
||||
var numColumns int
|
||||
if err = gcdb.QueryRowSQL(query,
|
||||
interfaceSlice(),
|
||||
interfaceSlice(&numColumns)); err != nil {
|
||||
return err
|
||||
}
|
||||
if numColumns == 0 {
|
||||
query = `ALTER TABLE DBPREFIXwordfilters ADD COLUMN board_dirs varchar(255) DEFAULT '*'`
|
||||
if _, err = ExecSQL(query); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Yay, collation! Everybody loves MySQL's default collation!
|
||||
criticalConfig := config.GetSystemCriticalConfig()
|
||||
query = `ALTER DATABASE ` + criticalConfig.DBname + ` CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci`
|
||||
if _, err = gcdb.db.Exec(query); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
query = `SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = ?`
|
||||
rows, err := QuerySQL(query, criticalConfig.DBname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var tableName string
|
||||
err = rows.Scan(&tableName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
query = `ALTER TABLE ` + tableName + ` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci`
|
||||
if _, err = gcdb.db.Exec(query); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err = nil
|
||||
case "postgres":
|
||||
query = `ALTER TABLE DBPREFIXwordfilters DROP CONSTRAINT IF EXISTS board_id_fk`
|
||||
_, err = ExecSQL(`ALTER TABLE DBPREFIXwordfilters DROP CONSTRAINT IF EXISTS board_id_fk`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
query = `ALTER TABLE DBPREFIXwordfilters ADD COLUMN IF NOT EXISTS board_dirs varchar(255) DEFAULT '*'`
|
||||
if _, err = ExecSQL(query); err != nil {
|
||||
return err
|
||||
}
|
||||
case "sqlite3":
|
||||
_, err = ExecSQL(`PRAGMA foreign_keys = ON`)
|
||||
return err
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
query = `SELECT COUNT(*) FROM PRAGMA_TABLE_INFO('DBPREFIXwordfilters') WHERE name = 'board_dirs'`
|
||||
var numColumns int
|
||||
if err = QueryRowSQL(query, interfaceSlice(), interfaceSlice(&numColumns)); err != nil {
|
||||
return err
|
||||
}
|
||||
if numColumns == 0 {
|
||||
query = `ALTER TABLE DBPREFIXwordfilters ADD COLUMN board_dirs varchar(255) DEFAULT '*'`
|
||||
if _, err = ExecSQL(query); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if _, err = gcdb.ExecSQL(query); err != nil {
|
||||
return err
|
||||
}
|
||||
query = `ALTER TABLE DBPREFIXwordfilters DROP COLUMN IF EXISTS board_id`
|
||||
if _, err = gcdb.ExecSQL(query); err != nil {
|
||||
return err
|
||||
}
|
||||
query = `ALTER TABLE DBPREFIXwordfilters ADD COLUMN IF NOT EXISTS board_dirs varchar(255) DEFAULT '*'`
|
||||
_, err = gcdb.ExecSQL(query)
|
||||
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ func CheckAndInitializeDatabase(dbType string) error {
|
|||
func buildNewDatabase(dbType string) error {
|
||||
var err error
|
||||
if err = initDB("initdb_" + dbType + ".sql"); err != nil {
|
||||
return errors.New("database initialization failed: " + err.Error())
|
||||
return err
|
||||
}
|
||||
if err = createDefaultAdminIfNoStaff(); err != nil {
|
||||
return errors.New("failed creating default admin account: " + err.Error())
|
||||
|
|
|
@ -116,7 +116,7 @@ CREATE TABLE DBPREFIXstaff(
|
|||
CREATE TABLE DBPREFIXsessions(
|
||||
id {serial pk},
|
||||
staff_id {fk to serial} NOT NULL,
|
||||
expires TIMESTAMP NOT NULL,
|
||||
expires TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
data VARCHAR(45) NOT NULL,
|
||||
CONSTRAINT sessions_staff_id_fk FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id) ON DELETE CASCADE
|
||||
);
|
||||
|
@ -147,9 +147,9 @@ CREATE TABLE DBPREFIXip_ban(
|
|||
is_thread_ban BOOL NOT NULL,
|
||||
is_active BOOL NOT NULL,
|
||||
ip VARCHAR(45) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL,
|
||||
appeal_at TIMESTAMP NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
appeal_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
expires_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
permanent BOOL NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
|
@ -165,8 +165,8 @@ CREATE TABLE DBPREFIXip_ban_audit(
|
|||
staff_id {fk to serial} NOT NULL,
|
||||
is_active BOOL NOT NULL,
|
||||
is_thread_ban BOOL NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL,
|
||||
appeal_at TIMESTAMP NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
appeal_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
permanent BOOL NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
|
|
|
@ -116,7 +116,7 @@ CREATE TABLE DBPREFIXstaff(
|
|||
CREATE TABLE DBPREFIXsessions(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
staff_id BIGINT NOT NULL,
|
||||
expires TIMESTAMP NOT NULL,
|
||||
expires TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
data VARCHAR(45) NOT NULL,
|
||||
CONSTRAINT sessions_staff_id_fk FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id) ON DELETE CASCADE
|
||||
);
|
||||
|
@ -147,9 +147,9 @@ CREATE TABLE DBPREFIXip_ban(
|
|||
is_thread_ban BOOL NOT NULL,
|
||||
is_active BOOL NOT NULL,
|
||||
ip VARCHAR(45) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL,
|
||||
appeal_at TIMESTAMP NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
appeal_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
expires_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
permanent BOOL NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
|
@ -165,8 +165,8 @@ CREATE TABLE DBPREFIXip_ban_audit(
|
|||
staff_id BIGINT NOT NULL,
|
||||
is_active BOOL NOT NULL,
|
||||
is_thread_ban BOOL NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL,
|
||||
appeal_at TIMESTAMP NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
appeal_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
permanent BOOL NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
|
|
|
@ -116,7 +116,7 @@ CREATE TABLE DBPREFIXstaff(
|
|||
CREATE TABLE DBPREFIXsessions(
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
staff_id BIGINT NOT NULL,
|
||||
expires TIMESTAMP NOT NULL,
|
||||
expires TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
data VARCHAR(45) NOT NULL,
|
||||
CONSTRAINT sessions_staff_id_fk FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id) ON DELETE CASCADE
|
||||
);
|
||||
|
@ -147,9 +147,9 @@ CREATE TABLE DBPREFIXip_ban(
|
|||
is_thread_ban BOOL NOT NULL,
|
||||
is_active BOOL NOT NULL,
|
||||
ip VARCHAR(45) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL,
|
||||
appeal_at TIMESTAMP NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
appeal_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
expires_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
permanent BOOL NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
|
@ -165,8 +165,8 @@ CREATE TABLE DBPREFIXip_ban_audit(
|
|||
staff_id BIGINT NOT NULL,
|
||||
is_active BOOL NOT NULL,
|
||||
is_thread_ban BOOL NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL,
|
||||
appeal_at TIMESTAMP NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
appeal_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
permanent BOOL NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
|
|
|
@ -116,7 +116,7 @@ CREATE TABLE DBPREFIXstaff(
|
|||
CREATE TABLE DBPREFIXsessions(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
staff_id BIGINT NOT NULL,
|
||||
expires TIMESTAMP NOT NULL,
|
||||
expires TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
data VARCHAR(45) NOT NULL,
|
||||
CONSTRAINT sessions_staff_id_fk FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id) ON DELETE CASCADE
|
||||
);
|
||||
|
@ -147,9 +147,9 @@ CREATE TABLE DBPREFIXip_ban(
|
|||
is_thread_ban BOOL NOT NULL,
|
||||
is_active BOOL NOT NULL,
|
||||
ip VARCHAR(45) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL,
|
||||
appeal_at TIMESTAMP NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
appeal_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
expires_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
permanent BOOL NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
|
@ -165,8 +165,8 @@ CREATE TABLE DBPREFIXip_ban_audit(
|
|||
staff_id BIGINT NOT NULL,
|
||||
is_active BOOL NOT NULL,
|
||||
is_thread_ban BOOL NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL,
|
||||
appeal_at TIMESTAMP NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
appeal_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
permanent BOOL NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
|
|
1
vagrant/Vagrantfile
vendored
1
vagrant/Vagrantfile
vendored
|
@ -31,6 +31,7 @@ Vagrant.configure("2") do |config|
|
|||
config.vm.provision :shell, path: "bootstrap.sh", env: {
|
||||
:DBTYPE => DBTYPE,
|
||||
:GOPATH => "/home/vagrant/go",
|
||||
:MYSQL_MAINLINE => ENV.fetch("GC_MYSQL_MAINLINE", ""),
|
||||
:FROMDOCKER => ""
|
||||
}, args: "install"
|
||||
end
|
||||
|
|
|
@ -17,7 +17,13 @@ apt-get -y update && apt-get -y upgrade
|
|||
|
||||
if [ "$DBTYPE" == "mysql" ]; then
|
||||
# Using MySQL (stable)
|
||||
apt-get -y install mariadb-server mariadb-client
|
||||
if [ "$MYSQL_MAINLINE" == "1" ]; then
|
||||
echo "using mainline MySQL instead of MariaDB"
|
||||
apt-get -y install mysql-server mysql-client
|
||||
else
|
||||
echo "using MariaDB fork of MySQL (default)"
|
||||
apt-get -y install mariadb-server mariadb-client
|
||||
fi
|
||||
mysql -uroot <<- EOF
|
||||
CREATE DATABASE IF NOT EXISTS gochan;
|
||||
GRANT USAGE ON *.* TO gochan IDENTIFIED BY 'gochan'; \
|
||||
|
@ -25,8 +31,13 @@ if [ "$DBTYPE" == "mysql" ]; then
|
|||
SET PASSWORD FOR 'gochan'@'%' = PASSWORD('gochan');
|
||||
FLUSH PRIVILEGES;
|
||||
EOF
|
||||
systemctl enable mariadb
|
||||
systemctl start mariadb &
|
||||
if [ "$MYSQL_MAINLINE" == "1" ]; then
|
||||
systemctl enable mysql
|
||||
systemctl start mysql &
|
||||
else
|
||||
systemctl enable mariadb
|
||||
systemctl start mariadb &
|
||||
fi
|
||||
wait
|
||||
if [ -d /lib/systemd ]; then
|
||||
cp /vagrant/sample-configs/gochan-mysql.service /lib/systemd/system/gochan.service
|
||||
|
|
2
version
2
version
|
@ -1 +1 @@
|
|||
3.5.0
|
||||
3.5.1
|
Loading…
Add table
Add a link
Reference in a new issue