mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-28 08:06:24 -07:00
Drop sqlite support in sql
Move migration sql
This commit is contained in:
parent
c69072f00f
commit
0277d88301
8 changed files with 898 additions and 120 deletions
|
@ -1,50 +1,52 @@
|
|||
from os import path
|
||||
|
||||
#
|
||||
# Use a macro like this {exact macro name}
|
||||
#
|
||||
class macro():
|
||||
def __init__(self, macroname, postgres, sqlite, mysql):
|
||||
def __init__(self, macroname, postgres, mysql):
|
||||
self.macroname = macroname
|
||||
self.postgres = postgres
|
||||
self.sqlite = sqlite
|
||||
self.mysql = mysql
|
||||
|
||||
# macros
|
||||
macros = [
|
||||
macro("serial pk", "BIGSERIAL PRIMARY KEY", "INTEGER PRIMARY KEY AUTOINCREMENT", "BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY"),
|
||||
macro("fk to serial", "BIGINT", "INTEGER", "BIGINT")
|
||||
]
|
||||
masterfileIn = open(path.join("..", "initdb_master.sql"), 'r')
|
||||
masterfile = masterfileIn.read()
|
||||
masterfileIn.close()
|
||||
macro("serial pk", "BIGSERIAL PRIMARY KEY", "BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY"),
|
||||
macro("fk to serial", "BIGINT", "BIGINT"),
|
||||
macro("drop fk", "DROP CONSTRAINT", "DROP FOREIGN KEY")
|
||||
]
|
||||
|
||||
postgresProcessed = masterfile
|
||||
sqliteProcessed = masterfile
|
||||
mysqlProcessed = masterfile
|
||||
def dofile(filestart):
|
||||
print("building " + filestart + " sql file")
|
||||
masterfileIn = open(filestart + "master.sql", 'r')
|
||||
masterfile = masterfileIn.read()
|
||||
masterfileIn.close()
|
||||
|
||||
for item in macros:
|
||||
macroCode = "{" + item.macroname + "}"
|
||||
postgresProcessed = postgresProcessed.replace(macroCode, item.postgres)
|
||||
mysqlProcessed = mysqlProcessed.replace(macroCode, item.mysql)
|
||||
sqliteProcessed = sqliteProcessed.replace(macroCode, item.sqlite)
|
||||
|
||||
def hasError(text):
|
||||
if '{' in text or '}' in text:
|
||||
return True
|
||||
postgresProcessed = masterfile
|
||||
mysqlProcessed = masterfile
|
||||
|
||||
for item in macros:
|
||||
macroCode = "{" + item.macroname + "}"
|
||||
postgresProcessed = postgresProcessed.replace(macroCode, item.postgres)
|
||||
mysqlProcessed = mysqlProcessed.replace(macroCode, item.mysql)
|
||||
|
||||
error = hasError(postgresProcessed)
|
||||
error = error or hasError(mysqlProcessed)
|
||||
error = error or hasError(sqliteProcessed)
|
||||
def hasError(text):
|
||||
if '{' in text or '}' in text:
|
||||
return True
|
||||
|
||||
error = hasError(postgresProcessed)
|
||||
error = error or hasError(mysqlProcessed)
|
||||
|
||||
i = open(path.join("..", "initdb_postgres.sql"), 'w')
|
||||
i.write(postgresProcessed)
|
||||
i.close()
|
||||
i = open(filestart + "postgres.sql", 'w')
|
||||
i.write(postgresProcessed)
|
||||
i.close()
|
||||
|
||||
i = open(path.join("..", "initdb_mysql.sql"), 'w')
|
||||
i.write(mysqlProcessed)
|
||||
i.close()
|
||||
|
||||
i = open(path.join("..", "initdb_sqlite3.sql"), 'w')
|
||||
i.write(sqliteProcessed)
|
||||
i.close()
|
||||
i = open(filestart + "mysql.sql", 'w')
|
||||
i.write(mysqlProcessed)
|
||||
i.close()
|
||||
|
||||
if error:
|
||||
input("Error processing macros, files still contain curly braces (might be in comments?), press any key to continue")
|
||||
|
||||
if error:
|
||||
input("Error processing macros, files still contain curly braces (might be in comments?), press any key to continue")
|
||||
dofile(path.join("..", "initdb_"))
|
||||
dofile(path.join("..", "sql", "preapril2020migration", "initdb_"))
|
||||
dofile(path.join("..", "sql", "preapril2020migration", "oldDBMigration_"))
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
Migrates the pre-refactor database of april 2020 to database verion 1
|
||||
|
||||
rename all tables to table_old
|
||||
run version 1 population script
|
||||
filter, copy change data
|
||||
*/
|
||||
|
||||
INSERT INTO DBPREFIXsections (id, name, abbreviation, position, hidden)
|
||||
SELECT id, name, abbreviation, list_order, hidden > 0
|
||||
FROM DBPREFIXsections_old;
|
||||
|
||||
INSERT INTO DBPREFIXboards (
|
||||
id,
|
||||
section_id,
|
||||
uri,
|
||||
dir,
|
||||
navbar_position,
|
||||
title,
|
||||
subtitle,
|
||||
description,
|
||||
max_file_size,
|
||||
max_threads,
|
||||
default_style,
|
||||
locked,
|
||||
created_at,
|
||||
anonymous_name,
|
||||
force_anonymous,
|
||||
autosage_after,
|
||||
no_images_after,
|
||||
max_message_length,
|
||||
min_message_length,
|
||||
allow_embeds,
|
||||
redirect_to_thread,
|
||||
require_file,
|
||||
enable_catalog)
|
||||
SELECT id, section, dir, dir, list_order, title, subtitle, description, max_file_size, 1000,
|
||||
default_style, locked, created_on, anonymous, forced_anon, autosage_after, no_images_after, max_message_length, 0, embeds_allowed,
|
||||
redirect_to_thread, require_file, enable_catalog
|
||||
FROM DBPREFIXboards_old;
|
|
@ -9,7 +9,7 @@ CREATE TABLE DBPREFIXdatabase_version(
|
|||
);
|
||||
|
||||
CREATE TABLE DBPREFIXsections(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
id {serial pk},
|
||||
name TEXT NOT NULL,
|
||||
abbreviation TEXT NOT NULL,
|
||||
position SMALLINT NOT NULL,
|
||||
|
@ -17,8 +17,8 @@ CREATE TABLE DBPREFIXsections(
|
|||
);
|
||||
|
||||
CREATE TABLE DBPREFIXboards(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
section_id INTEGER NOT NULL,
|
||||
id {serial pk},
|
||||
section_id {fk to serial} NOT NULL,
|
||||
uri VARCHAR(45) NOT NULL,
|
||||
dir VARCHAR(45) NOT NULL,
|
||||
navbar_position SMALLINT NOT NULL,
|
||||
|
@ -46,8 +46,8 @@ CREATE TABLE DBPREFIXboards(
|
|||
);
|
||||
|
||||
CREATE TABLE DBPREFIXthreads(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
board_id INTEGER NOT NULL,
|
||||
id {serial pk},
|
||||
board_id {fk to serial} NOT NULL,
|
||||
locked BOOL NOT NULL DEFAULT FALSE,
|
||||
stickied BOOL NOT NULL DEFAULT FALSE,
|
||||
anchored BOOL NOT NULL DEFAULT FALSE,
|
||||
|
@ -61,8 +61,8 @@ CREATE TABLE DBPREFIXthreads(
|
|||
CREATE INDEX thread_deleted_index ON DBPREFIXthreads(is_deleted);
|
||||
|
||||
CREATE TABLE DBPREFIXposts(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
thread_id INTEGER NOT NULL,
|
||||
id {serial pk},
|
||||
thread_id {fk to serial} NOT NULL,
|
||||
is_top_post BOOL NOT NULL DEFAULT FALSE,
|
||||
ip VARCHAR(45) NOT NULL,
|
||||
created_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
@ -83,8 +83,8 @@ CREATE TABLE DBPREFIXposts(
|
|||
CREATE INDEX top_post_index ON DBPREFIXposts(is_top_post);
|
||||
|
||||
CREATE TABLE DBPREFIXfiles(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
post_id INTEGER NOT NULL,
|
||||
id {serial pk},
|
||||
post_id {fk to serial} NOT NULL,
|
||||
file_order INT NOT NULL,
|
||||
original_filename VARCHAR(255) NOT NULL,
|
||||
filename VARCHAR(45) NOT NULL,
|
||||
|
@ -100,7 +100,7 @@ CREATE TABLE DBPREFIXfiles(
|
|||
);
|
||||
|
||||
CREATE TABLE DBPREFIXstaff(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
id {serial pk},
|
||||
username VARCHAR(45) NOT NULL,
|
||||
password_checksum VARCHAR(120) NOT NULL,
|
||||
global_rank INT,
|
||||
|
@ -111,23 +111,23 @@ CREATE TABLE DBPREFIXstaff(
|
|||
);
|
||||
|
||||
CREATE TABLE DBPREFIXsessions(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
staff_id INTEGER NOT NULL,
|
||||
id {serial pk},
|
||||
staff_id {fk to serial} NOT NULL,
|
||||
expires TIMESTAMP NOT NULL,
|
||||
data VARCHAR(45) NOT NULL,
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXboard_staff(
|
||||
board_id INTEGER NOT NULL,
|
||||
staff_id INTEGER NOT NULL,
|
||||
board_id {fk to serial} NOT NULL,
|
||||
staff_id {fk to serial} NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES DBPREFIXboards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXannouncements(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
staff_id INTEGER NOT NULL,
|
||||
id {serial pk},
|
||||
staff_id {fk to serial} NOT NULL,
|
||||
subject VARCHAR(45) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
@ -135,10 +135,10 @@ CREATE TABLE DBPREFIXannouncements(
|
|||
);
|
||||
|
||||
CREATE TABLE DBPREFIXip_ban(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
staff_id INTEGER NOT NULL,
|
||||
board_id INTEGER NOT NULL,
|
||||
banned_for_post_id INTEGER,
|
||||
id {serial pk},
|
||||
staff_id {fk to serial} NOT NULL,
|
||||
board_id {fk to serial} NOT NULL,
|
||||
banned_for_post_id {fk to serial},
|
||||
copy_post_text TEXT NOT NULL,
|
||||
is_thread_ban BOOL NOT NULL,
|
||||
is_active BOOL NOT NULL,
|
||||
|
@ -156,9 +156,9 @@ CREATE TABLE DBPREFIXip_ban(
|
|||
);
|
||||
|
||||
CREATE TABLE DBPREFIXip_ban_audit(
|
||||
ip_ban_id INTEGER NOT NULL,
|
||||
ip_ban_id {fk to serial} NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
staff_id INTEGER NOT NULL,
|
||||
staff_id {fk to serial} NOT NULL,
|
||||
is_active BOOL NOT NULL,
|
||||
is_thread_ban BOOL NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL,
|
||||
|
@ -173,9 +173,9 @@ CREATE TABLE DBPREFIXip_ban_audit(
|
|||
);
|
||||
|
||||
CREATE TABLE DBPREFIXip_ban_appeals(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
staff_id INTEGER,
|
||||
ip_ban_id INTEGER NOT NULL,
|
||||
id {serial pk},
|
||||
staff_id {fk to serial},
|
||||
ip_ban_id {fk to serial} NOT NULL,
|
||||
appeal_text TEXT NOT NULL,
|
||||
staff_response TEXT,
|
||||
is_denied BOOL NOT NULL,
|
||||
|
@ -184,9 +184,9 @@ CREATE TABLE DBPREFIXip_ban_appeals(
|
|||
);
|
||||
|
||||
CREATE TABLE DBPREFIXip_ban_appeals_audit(
|
||||
appeal_id INTEGER NOT NULL,
|
||||
appeal_id {fk to serial} NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
staff_id INTEGER,
|
||||
staff_id {fk to serial},
|
||||
appeal_text TEXT NOT NULL,
|
||||
staff_response TEXT,
|
||||
is_denied BOOL NOT NULL,
|
||||
|
@ -196,9 +196,9 @@ CREATE TABLE DBPREFIXip_ban_appeals_audit(
|
|||
);
|
||||
|
||||
CREATE TABLE DBPREFIXreports(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
handled_by_staff_id INTEGER,
|
||||
post_id INTEGER NOT NULL,
|
||||
id {serial pk},
|
||||
handled_by_staff_id {fk to serial},
|
||||
post_id {fk to serial} NOT NULL,
|
||||
ip VARCHAR(45) NOT NULL,
|
||||
reason TEXT NOT NULL,
|
||||
is_cleared BOOL NOT NULL,
|
||||
|
@ -207,18 +207,18 @@ CREATE TABLE DBPREFIXreports(
|
|||
);
|
||||
|
||||
CREATE TABLE DBPREFIXreports_audit(
|
||||
report_id INTEGER NOT NULL,
|
||||
report_id {fk to serial} NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
handled_by_staff_id INTEGER,
|
||||
handled_by_staff_id {fk to serial},
|
||||
is_cleared BOOL NOT NULL,
|
||||
FOREIGN KEY(handled_by_staff_id) REFERENCES DBPREFIXstaff(id),
|
||||
FOREIGN KEY(report_id) REFERENCES DBPREFIXreports(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXfilename_ban(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
board_id INTEGER,
|
||||
staff_id INTEGER NOT NULL,
|
||||
id {serial pk},
|
||||
board_id {fk to serial},
|
||||
staff_id {fk to serial} NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
filename VARCHAR(255) NOT NULL,
|
||||
|
@ -228,9 +228,9 @@ CREATE TABLE DBPREFIXfilename_ban(
|
|||
);
|
||||
|
||||
CREATE TABLE DBPREFIXusername_ban(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
board_id INTEGER,
|
||||
staff_id INTEGER NOT NULL,
|
||||
id {serial pk},
|
||||
board_id {fk to serial},
|
||||
staff_id {fk to serial} NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
username VARCHAR(255) NOT NULL,
|
||||
|
@ -240,9 +240,9 @@ CREATE TABLE DBPREFIXusername_ban(
|
|||
);
|
||||
|
||||
CREATE TABLE DBPREFIXfile_ban(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
board_id INTEGER,
|
||||
staff_id INTEGER NOT NULL,
|
||||
id {serial pk},
|
||||
board_id {fk to serial},
|
||||
staff_id {fk to serial} NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
checksum TEXT NOT NULL,
|
||||
|
@ -251,9 +251,9 @@ CREATE TABLE DBPREFIXfile_ban(
|
|||
);
|
||||
|
||||
CREATE TABLE DBPREFIXwordfilters(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
board_id INTEGER,
|
||||
staff_id INTEGER NOT NULL,
|
||||
id {serial pk},
|
||||
board_id {fk to serial},
|
||||
staff_id {fk to serial} NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
search VARCHAR(75) NOT NULL CHECK (search <> ''),
|
267
sql/preapril2020migration/initdb_mysql.sql
Normal file
267
sql/preapril2020migration/initdb_mysql.sql
Normal file
|
@ -0,0 +1,267 @@
|
|||
-- Gochan master template for new database script
|
||||
-- Contains macros in the form [curlybrace open]macro text[curlybrace close]
|
||||
-- Macros are substituted by build_initdb.py to the supported database files. Must not contain extra spaces
|
||||
-- Versioning numbering goes by whole numbers. Upgrade script migrate existing databases between versions
|
||||
-- Database version: 1
|
||||
|
||||
CREATE TABLE DBPREFIXdatabase_version(
|
||||
version INT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXsections(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
abbreviation TEXT NOT NULL,
|
||||
position SMALLINT NOT NULL,
|
||||
hidden BOOL NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXboards(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
section_id BIGINT NOT NULL,
|
||||
uri VARCHAR(45) NOT NULL,
|
||||
dir VARCHAR(45) NOT NULL,
|
||||
navbar_position SMALLINT NOT NULL,
|
||||
title VARCHAR(45) NOT NULL,
|
||||
subtitle VARCHAR(64) NOT NULL,
|
||||
description VARCHAR(64) NOT NULL,
|
||||
max_file_size INT NOT NULL,
|
||||
max_threads SMALLINT NOT NULL,
|
||||
default_style VARCHAR(45) NOT NULL,
|
||||
locked BOOL NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
anonymous_name VARCHAR(45) NOT NULL DEFAULT 'Anonymous',
|
||||
force_anonymous BOOL NOT NULL,
|
||||
autosage_after SMALLINT NOT NULL,
|
||||
no_images_after SMALLINT NOT NULL,
|
||||
max_message_length SMALLINT NOT NULL,
|
||||
min_message_length SMALLINT NOT NULL,
|
||||
allow_embeds BOOL NOT NULL,
|
||||
redirect_to_thread BOOL NOT NULL,
|
||||
require_file BOOL NOT NULL,
|
||||
enable_catalog BOOL NOT NULL,
|
||||
FOREIGN KEY(section_id) REFERENCES DBPREFIXsections(id),
|
||||
UNIQUE(dir),
|
||||
UNIQUE(uri)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXthreads(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
board_id BIGINT NOT NULL,
|
||||
locked BOOL NOT NULL DEFAULT FALSE,
|
||||
stickied BOOL NOT NULL DEFAULT FALSE,
|
||||
anchored BOOL NOT NULL DEFAULT FALSE,
|
||||
cyclical BOOL NOT NULL DEFAULT FALSE,
|
||||
last_bump TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
is_deleted BOOL NOT NULL DEFAULT FALSE,
|
||||
FOREIGN KEY(board_id) REFERENCES DBPREFIXboards(id)
|
||||
);
|
||||
|
||||
CREATE INDEX thread_deleted_index ON DBPREFIXthreads(is_deleted);
|
||||
|
||||
CREATE TABLE DBPREFIXposts(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
thread_id BIGINT NOT NULL,
|
||||
is_top_post BOOL NOT NULL DEFAULT FALSE,
|
||||
ip VARCHAR(45) NOT NULL,
|
||||
created_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
name VARCHAR(50) NOT NULL DEFAULT '',
|
||||
tripcode VARCHAR(10) NOT NULL DEFAULT '',
|
||||
is_role_signature BOOL NOT NULL DEFAULT FALSE,
|
||||
email VARCHAR(50) NOT NULL DEFAULT '',
|
||||
subject VARCHAR(100) NOT NULL DEFAULT '',
|
||||
message TEXT NOT NULL,
|
||||
message_raw TEXT NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
deleted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
is_deleted BOOL NOT NULL DEFAULT FALSE,
|
||||
banned_message TEXT,
|
||||
FOREIGN KEY(thread_id) REFERENCES DBPREFIXthreads(id)
|
||||
);
|
||||
|
||||
CREATE INDEX top_post_index ON DBPREFIXposts(is_top_post);
|
||||
|
||||
CREATE TABLE DBPREFIXfiles(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
post_id BIGINT NOT NULL,
|
||||
file_order INT NOT NULL,
|
||||
original_filename VARCHAR(255) NOT NULL,
|
||||
filename VARCHAR(45) NOT NULL,
|
||||
checksum TEXT NOT NULL,
|
||||
file_size INT NOT NULL,
|
||||
is_spoilered BOOL NOT NULL,
|
||||
thumbnail_width INT NOT NULL,
|
||||
thumbnail_height INT NOT NULL,
|
||||
width INT NOT NULL,
|
||||
height INT NOT NULL,
|
||||
FOREIGN KEY(post_id) REFERENCES DBPREFIXposts(id),
|
||||
UNIQUE(post_id, file_order)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXstaff(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
username VARCHAR(45) NOT NULL,
|
||||
password_checksum VARCHAR(120) NOT NULL,
|
||||
global_rank INT,
|
||||
added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
last_login TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
is_active BOOL NOT NULL DEFAULT TRUE,
|
||||
UNIQUE(username)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXsessions(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
staff_id BIGINT NOT NULL,
|
||||
expires TIMESTAMP NOT NULL,
|
||||
data VARCHAR(45) NOT NULL,
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXboard_staff(
|
||||
board_id BIGINT NOT NULL,
|
||||
staff_id BIGINT NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES DBPREFIXboards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXannouncements(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
staff_id BIGINT NOT NULL,
|
||||
subject VARCHAR(45) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXip_ban(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
staff_id BIGINT NOT NULL,
|
||||
board_id BIGINT NOT NULL,
|
||||
banned_for_post_id BIGINT,
|
||||
copy_post_text TEXT NOT NULL,
|
||||
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,
|
||||
permanent BOOL NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
can_appeal BOOL NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES DBPREFIXboards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id),
|
||||
FOREIGN KEY(banned_for_post_id) REFERENCES DBPREFIXposts(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXip_ban_audit(
|
||||
ip_ban_id BIGINT NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
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,
|
||||
permanent BOOL NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
can_appeal BOOL NOT NULL,
|
||||
PRIMARY KEY(ip_ban_id, timestamp),
|
||||
FOREIGN KEY(ip_ban_id) REFERENCES DBPREFIXip_ban(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXip_ban_appeals(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
staff_id BIGINT,
|
||||
ip_ban_id BIGINT NOT NULL,
|
||||
appeal_text TEXT NOT NULL,
|
||||
staff_response TEXT,
|
||||
is_denied BOOL NOT NULL,
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id),
|
||||
FOREIGN KEY(ip_ban_id) REFERENCES DBPREFIXip_ban(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXip_ban_appeals_audit(
|
||||
appeal_id BIGINT NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
staff_id BIGINT,
|
||||
appeal_text TEXT NOT NULL,
|
||||
staff_response TEXT,
|
||||
is_denied BOOL NOT NULL,
|
||||
PRIMARY KEY(appeal_id, timestamp),
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id),
|
||||
FOREIGN KEY(appeal_id) REFERENCES DBPREFIXip_ban_appeals(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXreports(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
handled_by_staff_id BIGINT,
|
||||
post_id BIGINT NOT NULL,
|
||||
ip VARCHAR(45) NOT NULL,
|
||||
reason TEXT NOT NULL,
|
||||
is_cleared BOOL NOT NULL,
|
||||
FOREIGN KEY(handled_by_staff_id) REFERENCES DBPREFIXstaff(id),
|
||||
FOREIGN KEY(post_id) REFERENCES DBPREFIXposts(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXreports_audit(
|
||||
report_id BIGINT NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
handled_by_staff_id BIGINT,
|
||||
is_cleared BOOL NOT NULL,
|
||||
FOREIGN KEY(handled_by_staff_id) REFERENCES DBPREFIXstaff(id),
|
||||
FOREIGN KEY(report_id) REFERENCES DBPREFIXreports(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXfilename_ban(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
board_id BIGINT,
|
||||
staff_id BIGINT NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
filename VARCHAR(255) NOT NULL,
|
||||
is_regex BOOL NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES DBPREFIXboards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXusername_ban(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
board_id BIGINT,
|
||||
staff_id BIGINT NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
username VARCHAR(255) NOT NULL,
|
||||
is_regex BOOL NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES DBPREFIXboards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXfile_ban(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
board_id BIGINT,
|
||||
staff_id BIGINT NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
checksum TEXT NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES DBPREFIXboards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXwordfilters(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
board_id BIGINT,
|
||||
staff_id BIGINT NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
search VARCHAR(75) NOT NULL CHECK (search <> ''),
|
||||
is_regex BOOL NOT NULL,
|
||||
change_to VARCHAR(75) NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES DBPREFIXboards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
INSERT INTO DBPREFIXdatabase_version(version)
|
||||
VALUES(1);
|
267
sql/preapril2020migration/initdb_postgres.sql
Normal file
267
sql/preapril2020migration/initdb_postgres.sql
Normal file
|
@ -0,0 +1,267 @@
|
|||
-- Gochan master template for new database script
|
||||
-- Contains macros in the form [curlybrace open]macro text[curlybrace close]
|
||||
-- Macros are substituted by build_initdb.py to the supported database files. Must not contain extra spaces
|
||||
-- Versioning numbering goes by whole numbers. Upgrade script migrate existing databases between versions
|
||||
-- Database version: 1
|
||||
|
||||
CREATE TABLE DBPREFIXdatabase_version(
|
||||
version INT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXsections(
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
abbreviation TEXT NOT NULL,
|
||||
position SMALLINT NOT NULL,
|
||||
hidden BOOL NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXboards(
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
section_id BIGINT NOT NULL,
|
||||
uri VARCHAR(45) NOT NULL,
|
||||
dir VARCHAR(45) NOT NULL,
|
||||
navbar_position SMALLINT NOT NULL,
|
||||
title VARCHAR(45) NOT NULL,
|
||||
subtitle VARCHAR(64) NOT NULL,
|
||||
description VARCHAR(64) NOT NULL,
|
||||
max_file_size INT NOT NULL,
|
||||
max_threads SMALLINT NOT NULL,
|
||||
default_style VARCHAR(45) NOT NULL,
|
||||
locked BOOL NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
anonymous_name VARCHAR(45) NOT NULL DEFAULT 'Anonymous',
|
||||
force_anonymous BOOL NOT NULL,
|
||||
autosage_after SMALLINT NOT NULL,
|
||||
no_images_after SMALLINT NOT NULL,
|
||||
max_message_length SMALLINT NOT NULL,
|
||||
min_message_length SMALLINT NOT NULL,
|
||||
allow_embeds BOOL NOT NULL,
|
||||
redirect_to_thread BOOL NOT NULL,
|
||||
require_file BOOL NOT NULL,
|
||||
enable_catalog BOOL NOT NULL,
|
||||
FOREIGN KEY(section_id) REFERENCES DBPREFIXsections(id),
|
||||
UNIQUE(dir),
|
||||
UNIQUE(uri)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXthreads(
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
board_id BIGINT NOT NULL,
|
||||
locked BOOL NOT NULL DEFAULT FALSE,
|
||||
stickied BOOL NOT NULL DEFAULT FALSE,
|
||||
anchored BOOL NOT NULL DEFAULT FALSE,
|
||||
cyclical BOOL NOT NULL DEFAULT FALSE,
|
||||
last_bump TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
is_deleted BOOL NOT NULL DEFAULT FALSE,
|
||||
FOREIGN KEY(board_id) REFERENCES DBPREFIXboards(id)
|
||||
);
|
||||
|
||||
CREATE INDEX thread_deleted_index ON DBPREFIXthreads(is_deleted);
|
||||
|
||||
CREATE TABLE DBPREFIXposts(
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
thread_id BIGINT NOT NULL,
|
||||
is_top_post BOOL NOT NULL DEFAULT FALSE,
|
||||
ip VARCHAR(45) NOT NULL,
|
||||
created_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
name VARCHAR(50) NOT NULL DEFAULT '',
|
||||
tripcode VARCHAR(10) NOT NULL DEFAULT '',
|
||||
is_role_signature BOOL NOT NULL DEFAULT FALSE,
|
||||
email VARCHAR(50) NOT NULL DEFAULT '',
|
||||
subject VARCHAR(100) NOT NULL DEFAULT '',
|
||||
message TEXT NOT NULL,
|
||||
message_raw TEXT NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
deleted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
is_deleted BOOL NOT NULL DEFAULT FALSE,
|
||||
banned_message TEXT,
|
||||
FOREIGN KEY(thread_id) REFERENCES DBPREFIXthreads(id)
|
||||
);
|
||||
|
||||
CREATE INDEX top_post_index ON DBPREFIXposts(is_top_post);
|
||||
|
||||
CREATE TABLE DBPREFIXfiles(
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
post_id BIGINT NOT NULL,
|
||||
file_order INT NOT NULL,
|
||||
original_filename VARCHAR(255) NOT NULL,
|
||||
filename VARCHAR(45) NOT NULL,
|
||||
checksum TEXT NOT NULL,
|
||||
file_size INT NOT NULL,
|
||||
is_spoilered BOOL NOT NULL,
|
||||
thumbnail_width INT NOT NULL,
|
||||
thumbnail_height INT NOT NULL,
|
||||
width INT NOT NULL,
|
||||
height INT NOT NULL,
|
||||
FOREIGN KEY(post_id) REFERENCES DBPREFIXposts(id),
|
||||
UNIQUE(post_id, file_order)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXstaff(
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
username VARCHAR(45) NOT NULL,
|
||||
password_checksum VARCHAR(120) NOT NULL,
|
||||
global_rank INT,
|
||||
added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
last_login TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
is_active BOOL NOT NULL DEFAULT TRUE,
|
||||
UNIQUE(username)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXsessions(
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
staff_id BIGINT NOT NULL,
|
||||
expires TIMESTAMP NOT NULL,
|
||||
data VARCHAR(45) NOT NULL,
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXboard_staff(
|
||||
board_id BIGINT NOT NULL,
|
||||
staff_id BIGINT NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES DBPREFIXboards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXannouncements(
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
staff_id BIGINT NOT NULL,
|
||||
subject VARCHAR(45) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXip_ban(
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
staff_id BIGINT NOT NULL,
|
||||
board_id BIGINT NOT NULL,
|
||||
banned_for_post_id BIGINT,
|
||||
copy_post_text TEXT NOT NULL,
|
||||
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,
|
||||
permanent BOOL NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
can_appeal BOOL NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES DBPREFIXboards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id),
|
||||
FOREIGN KEY(banned_for_post_id) REFERENCES DBPREFIXposts(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXip_ban_audit(
|
||||
ip_ban_id BIGINT NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
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,
|
||||
permanent BOOL NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
can_appeal BOOL NOT NULL,
|
||||
PRIMARY KEY(ip_ban_id, timestamp),
|
||||
FOREIGN KEY(ip_ban_id) REFERENCES DBPREFIXip_ban(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXip_ban_appeals(
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
staff_id BIGINT,
|
||||
ip_ban_id BIGINT NOT NULL,
|
||||
appeal_text TEXT NOT NULL,
|
||||
staff_response TEXT,
|
||||
is_denied BOOL NOT NULL,
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id),
|
||||
FOREIGN KEY(ip_ban_id) REFERENCES DBPREFIXip_ban(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXip_ban_appeals_audit(
|
||||
appeal_id BIGINT NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
staff_id BIGINT,
|
||||
appeal_text TEXT NOT NULL,
|
||||
staff_response TEXT,
|
||||
is_denied BOOL NOT NULL,
|
||||
PRIMARY KEY(appeal_id, timestamp),
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id),
|
||||
FOREIGN KEY(appeal_id) REFERENCES DBPREFIXip_ban_appeals(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXreports(
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
handled_by_staff_id BIGINT,
|
||||
post_id BIGINT NOT NULL,
|
||||
ip VARCHAR(45) NOT NULL,
|
||||
reason TEXT NOT NULL,
|
||||
is_cleared BOOL NOT NULL,
|
||||
FOREIGN KEY(handled_by_staff_id) REFERENCES DBPREFIXstaff(id),
|
||||
FOREIGN KEY(post_id) REFERENCES DBPREFIXposts(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXreports_audit(
|
||||
report_id BIGINT NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
handled_by_staff_id BIGINT,
|
||||
is_cleared BOOL NOT NULL,
|
||||
FOREIGN KEY(handled_by_staff_id) REFERENCES DBPREFIXstaff(id),
|
||||
FOREIGN KEY(report_id) REFERENCES DBPREFIXreports(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXfilename_ban(
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
board_id BIGINT,
|
||||
staff_id BIGINT NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
filename VARCHAR(255) NOT NULL,
|
||||
is_regex BOOL NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES DBPREFIXboards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXusername_ban(
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
board_id BIGINT,
|
||||
staff_id BIGINT NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
username VARCHAR(255) NOT NULL,
|
||||
is_regex BOOL NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES DBPREFIXboards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXfile_ban(
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
board_id BIGINT,
|
||||
staff_id BIGINT NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
checksum TEXT NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES DBPREFIXboards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE DBPREFIXwordfilters(
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
board_id BIGINT,
|
||||
staff_id BIGINT NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
search VARCHAR(75) NOT NULL CHECK (search <> ''),
|
||||
is_regex BOOL NOT NULL,
|
||||
change_to VARCHAR(75) NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES DBPREFIXboards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES DBPREFIXstaff(id)
|
||||
);
|
||||
|
||||
INSERT INTO DBPREFIXdatabase_version(version)
|
||||
VALUES(1);
|
94
sql/preapril2020migration/oldDBMigration_master.sql
Normal file
94
sql/preapril2020migration/oldDBMigration_master.sql
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
Migrates the pre-refactor database of april 2020 to database verion 1
|
||||
|
||||
rename all tables to table_old
|
||||
run version 1 population script
|
||||
filter, copy change data
|
||||
*/
|
||||
|
||||
INSERT INTO DBPREFIXsections (id, name, abbreviation, position, hidden)
|
||||
SELECT id, name, abbreviation, list_order, hidden > 0
|
||||
FROM DBPREFIXsections_old;
|
||||
|
||||
INSERT INTO DBPREFIXboards (
|
||||
id,
|
||||
section_id,
|
||||
uri,
|
||||
dir,
|
||||
navbar_position,
|
||||
title,
|
||||
subtitle,
|
||||
description,
|
||||
max_file_size,
|
||||
max_threads,
|
||||
default_style,
|
||||
locked,
|
||||
created_at,
|
||||
anonymous_name,
|
||||
force_anonymous,
|
||||
autosage_after,
|
||||
no_images_after,
|
||||
max_message_length,
|
||||
min_message_length,
|
||||
allow_embeds,
|
||||
redirect_to_thread,
|
||||
require_file,
|
||||
enable_catalog)
|
||||
SELECT id, section, dir, dir, list_order, title, subtitle, description, max_file_size, 1000,
|
||||
default_style, locked, created_on, anonymous, forced_anon, autosage_after, no_images_after, max_message_length, 0, embeds_allowed,
|
||||
redirect_to_thread, require_file, enable_catalog
|
||||
FROM DBPREFIXboards_old;
|
||||
|
||||
/*
|
||||
---Migrating posts
|
||||
add oldpostid to thread table, make it unique
|
||||
add oldselfid, oldparentid and oldboardid to posts table
|
||||
add oldselfid and oldboardid to files
|
||||
remove foreign key constraint on thread_id in posts
|
||||
remove foreign key constraint on post_id in files
|
||||
create thread per top post, add id of said old post to oldpostid
|
||||
insert top posts with old parent id being own old id and old board id being board id
|
||||
insert child posts with old parent id being old parent post id and old board id being board id
|
||||
---
|
||||
UPDATE posts, threads
|
||||
SET posts.thread_id = threads.id
|
||||
WHERE threads.oldpostid = posts.oldparentid AND threads.boardid = posts.oldboardid
|
||||
---
|
||||
insert into files values where file values exist
|
||||
---
|
||||
UPDATE posts, files
|
||||
SET files.post_id = posts.id
|
||||
WHERE files.oldpostid = posts.oldselfid AND files.oldboardid = posts.oldboardid
|
||||
---
|
||||
remove all dummy columns
|
||||
add foreign key constraint on thread_id in posts
|
||||
add foreign key constraint on post_id in files
|
||||
*/
|
||||
|
||||
ALTER TABLE DBPREFIXthreads ADD oldpostid int;
|
||||
ALTER TABLE DBPREFIXposts ADD oldselfid int;
|
||||
ALTER TABLE DBPREFIXposts ADD oldparentid int;
|
||||
ALTER TABLE DBPREFIXposts ADD oldboardid int;
|
||||
ALTER TABLE DBPREFIXposts {drop fk} thread_id;
|
||||
ALTER TABLE DBPREFIXfiles ADD oldpostid int;
|
||||
ALTER TABLE DBPREFIXfiles ADD oldboardid int;
|
||||
ALTER TABLE DBPREFIXfiles {drop fk} post_id;
|
||||
|
||||
INSERT INTO DBPREFIXthreads(board_id, locked, stickied, anchored, last_bump, is_deleted, deleted_at, oldpostid)
|
||||
SELECT boardid, locked, stickied, autosage, bumped, deleted_timestamp > '2000-01-01', deleted_timestamp, id FROM DBPREFIXposts_old WHERE parentid = 0;
|
||||
|
||||
INSERT INTO DBPREFIXposts(is_top_post, ip, created_on, name, tripcode, is_role_signature, email, subject, message, message_raw, password, deleted_at, is_deleted, oldparentid, oldboardid)
|
||||
SELECT parentid = 0, ip, timestamp, name, tripcode, false, email, subject,
|
||||
message, message_raw, password, deleted_timestamp, deleted_timestamp > '2000-01-01', CASE WHEN parentid = 0 THEN id ELSE parentid, boardid from DBPREFIXposts_old;
|
||||
|
||||
UPDATE DBPREFIXposts as posts, DBPREFIXthreads as threads
|
||||
SET posts.thread_id = thread.id
|
||||
WHERE threads.oldpostid = posts.oldparentid AND thread.board_id = posts.oldboardid;
|
||||
|
||||
INSERT INTO DBPREFIXfiles(file_oder, original_filename, filename, checksum, file_size, is_spoilered, width, height, thumbnail_width, thumbnail_height, oldpostid, oldboardid)
|
||||
SELECT 1, filename_original, filename, file_checksum, filesize, false, image_w, image_h, thumb_w, thumb_h, id, boardid FROM DBPREFIXposts_old WHERE filename != '';
|
||||
|
||||
UPDATE DBPREFIXfiles as files, DBPREFIXposts as posts
|
||||
SET files.post_id = posts.id
|
||||
WHERE files.oldpostid = posts.oldselfid AND files.oldboardid = posts.oldboardid;
|
||||
|
94
sql/preapril2020migration/oldDBMigration_mysql.sql
Normal file
94
sql/preapril2020migration/oldDBMigration_mysql.sql
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
Migrates the pre-refactor database of april 2020 to database verion 1
|
||||
|
||||
rename all tables to table_old
|
||||
run version 1 population script
|
||||
filter, copy change data
|
||||
*/
|
||||
|
||||
INSERT INTO DBPREFIXsections (id, name, abbreviation, position, hidden)
|
||||
SELECT id, name, abbreviation, list_order, hidden > 0
|
||||
FROM DBPREFIXsections_old;
|
||||
|
||||
INSERT INTO DBPREFIXboards (
|
||||
id,
|
||||
section_id,
|
||||
uri,
|
||||
dir,
|
||||
navbar_position,
|
||||
title,
|
||||
subtitle,
|
||||
description,
|
||||
max_file_size,
|
||||
max_threads,
|
||||
default_style,
|
||||
locked,
|
||||
created_at,
|
||||
anonymous_name,
|
||||
force_anonymous,
|
||||
autosage_after,
|
||||
no_images_after,
|
||||
max_message_length,
|
||||
min_message_length,
|
||||
allow_embeds,
|
||||
redirect_to_thread,
|
||||
require_file,
|
||||
enable_catalog)
|
||||
SELECT id, section, dir, dir, list_order, title, subtitle, description, max_file_size, 1000,
|
||||
default_style, locked, created_on, anonymous, forced_anon, autosage_after, no_images_after, max_message_length, 0, embeds_allowed,
|
||||
redirect_to_thread, require_file, enable_catalog
|
||||
FROM DBPREFIXboards_old;
|
||||
|
||||
/*
|
||||
---Migrating posts
|
||||
add oldpostid to thread table, make it unique
|
||||
add oldselfid, oldparentid and oldboardid to posts table
|
||||
add oldselfid and oldboardid to files
|
||||
remove foreign key constraint on thread_id in posts
|
||||
remove foreign key constraint on post_id in files
|
||||
create thread per top post, add id of said old post to oldpostid
|
||||
insert top posts with old parent id being own old id and old board id being board id
|
||||
insert child posts with old parent id being old parent post id and old board id being board id
|
||||
---
|
||||
UPDATE posts, threads
|
||||
SET posts.thread_id = threads.id
|
||||
WHERE threads.oldpostid = posts.oldparentid AND threads.boardid = posts.oldboardid
|
||||
---
|
||||
insert into files values where file values exist
|
||||
---
|
||||
UPDATE posts, files
|
||||
SET files.post_id = posts.id
|
||||
WHERE files.oldpostid = posts.oldselfid AND files.oldboardid = posts.oldboardid
|
||||
---
|
||||
remove all dummy columns
|
||||
add foreign key constraint on thread_id in posts
|
||||
add foreign key constraint on post_id in files
|
||||
*/
|
||||
|
||||
ALTER TABLE DBPREFIXthreads ADD oldpostid int;
|
||||
ALTER TABLE DBPREFIXposts ADD oldselfid int;
|
||||
ALTER TABLE DBPREFIXposts ADD oldparentid int;
|
||||
ALTER TABLE DBPREFIXposts ADD oldboardid int;
|
||||
ALTER TABLE DBPREFIXposts DROP FOREIGN KEY thread_id;
|
||||
ALTER TABLE DBPREFIXfiles ADD oldpostid int;
|
||||
ALTER TABLE DBPREFIXfiles ADD oldboardid int;
|
||||
ALTER TABLE DBPREFIXfiles DROP FOREIGN KEY post_id;
|
||||
|
||||
INSERT INTO DBPREFIXthreads(board_id, locked, stickied, anchored, last_bump, is_deleted, deleted_at, oldpostid)
|
||||
SELECT boardid, locked, stickied, autosage, bumped, deleted_timestamp > '2000-01-01', deleted_timestamp, id FROM DBPREFIXposts_old WHERE parentid = 0;
|
||||
|
||||
INSERT INTO DBPREFIXposts(is_top_post, ip, created_on, name, tripcode, is_role_signature, email, subject, message, message_raw, password, deleted_at, is_deleted, oldparentid, oldboardid)
|
||||
SELECT parentid = 0, ip, timestamp, name, tripcode, false, email, subject,
|
||||
message, message_raw, password, deleted_timestamp, deleted_timestamp > '2000-01-01', CASE WHEN parentid = 0 THEN id ELSE parentid, boardid from DBPREFIXposts_old;
|
||||
|
||||
UPDATE DBPREFIXposts as posts, DBPREFIXthreads as threads
|
||||
SET posts.thread_id = thread.id
|
||||
WHERE threads.oldpostid = posts.oldparentid AND thread.board_id = posts.oldboardid;
|
||||
|
||||
INSERT INTO DBPREFIXfiles(file_oder, original_filename, filename, checksum, file_size, is_spoilered, width, height, thumbnail_width, thumbnail_height, oldpostid, oldboardid)
|
||||
SELECT 1, filename_original, filename, file_checksum, filesize, false, image_w, image_h, thumb_w, thumb_h, id, boardid FROM DBPREFIXposts_old WHERE filename != '';
|
||||
|
||||
UPDATE DBPREFIXfiles as files, DBPREFIXposts as posts
|
||||
SET files.post_id = posts.id
|
||||
WHERE files.oldpostid = posts.oldselfid AND files.oldboardid = posts.oldboardid;
|
||||
|
94
sql/preapril2020migration/oldDBMigration_postgres.sql
Normal file
94
sql/preapril2020migration/oldDBMigration_postgres.sql
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
Migrates the pre-refactor database of april 2020 to database verion 1
|
||||
|
||||
rename all tables to table_old
|
||||
run version 1 population script
|
||||
filter, copy change data
|
||||
*/
|
||||
|
||||
INSERT INTO DBPREFIXsections (id, name, abbreviation, position, hidden)
|
||||
SELECT id, name, abbreviation, list_order, hidden > 0
|
||||
FROM DBPREFIXsections_old;
|
||||
|
||||
INSERT INTO DBPREFIXboards (
|
||||
id,
|
||||
section_id,
|
||||
uri,
|
||||
dir,
|
||||
navbar_position,
|
||||
title,
|
||||
subtitle,
|
||||
description,
|
||||
max_file_size,
|
||||
max_threads,
|
||||
default_style,
|
||||
locked,
|
||||
created_at,
|
||||
anonymous_name,
|
||||
force_anonymous,
|
||||
autosage_after,
|
||||
no_images_after,
|
||||
max_message_length,
|
||||
min_message_length,
|
||||
allow_embeds,
|
||||
redirect_to_thread,
|
||||
require_file,
|
||||
enable_catalog)
|
||||
SELECT id, section, dir, dir, list_order, title, subtitle, description, max_file_size, 1000,
|
||||
default_style, locked, created_on, anonymous, forced_anon, autosage_after, no_images_after, max_message_length, 0, embeds_allowed,
|
||||
redirect_to_thread, require_file, enable_catalog
|
||||
FROM DBPREFIXboards_old;
|
||||
|
||||
/*
|
||||
---Migrating posts
|
||||
add oldpostid to thread table, make it unique
|
||||
add oldselfid, oldparentid and oldboardid to posts table
|
||||
add oldselfid and oldboardid to files
|
||||
remove foreign key constraint on thread_id in posts
|
||||
remove foreign key constraint on post_id in files
|
||||
create thread per top post, add id of said old post to oldpostid
|
||||
insert top posts with old parent id being own old id and old board id being board id
|
||||
insert child posts with old parent id being old parent post id and old board id being board id
|
||||
---
|
||||
UPDATE posts, threads
|
||||
SET posts.thread_id = threads.id
|
||||
WHERE threads.oldpostid = posts.oldparentid AND threads.boardid = posts.oldboardid
|
||||
---
|
||||
insert into files values where file values exist
|
||||
---
|
||||
UPDATE posts, files
|
||||
SET files.post_id = posts.id
|
||||
WHERE files.oldpostid = posts.oldselfid AND files.oldboardid = posts.oldboardid
|
||||
---
|
||||
remove all dummy columns
|
||||
add foreign key constraint on thread_id in posts
|
||||
add foreign key constraint on post_id in files
|
||||
*/
|
||||
|
||||
ALTER TABLE DBPREFIXthreads ADD oldpostid int;
|
||||
ALTER TABLE DBPREFIXposts ADD oldselfid int;
|
||||
ALTER TABLE DBPREFIXposts ADD oldparentid int;
|
||||
ALTER TABLE DBPREFIXposts ADD oldboardid int;
|
||||
ALTER TABLE DBPREFIXposts DROP CONSTRAINT thread_id;
|
||||
ALTER TABLE DBPREFIXfiles ADD oldpostid int;
|
||||
ALTER TABLE DBPREFIXfiles ADD oldboardid int;
|
||||
ALTER TABLE DBPREFIXfiles DROP CONSTRAINT post_id;
|
||||
|
||||
INSERT INTO DBPREFIXthreads(board_id, locked, stickied, anchored, last_bump, is_deleted, deleted_at, oldpostid)
|
||||
SELECT boardid, locked, stickied, autosage, bumped, deleted_timestamp > '2000-01-01', deleted_timestamp, id FROM DBPREFIXposts_old WHERE parentid = 0;
|
||||
|
||||
INSERT INTO DBPREFIXposts(is_top_post, ip, created_on, name, tripcode, is_role_signature, email, subject, message, message_raw, password, deleted_at, is_deleted, oldparentid, oldboardid)
|
||||
SELECT parentid = 0, ip, timestamp, name, tripcode, false, email, subject,
|
||||
message, message_raw, password, deleted_timestamp, deleted_timestamp > '2000-01-01', CASE WHEN parentid = 0 THEN id ELSE parentid, boardid from DBPREFIXposts_old;
|
||||
|
||||
UPDATE DBPREFIXposts as posts, DBPREFIXthreads as threads
|
||||
SET posts.thread_id = thread.id
|
||||
WHERE threads.oldpostid = posts.oldparentid AND thread.board_id = posts.oldboardid;
|
||||
|
||||
INSERT INTO DBPREFIXfiles(file_oder, original_filename, filename, checksum, file_size, is_spoilered, width, height, thumbnail_width, thumbnail_height, oldpostid, oldboardid)
|
||||
SELECT 1, filename_original, filename, file_checksum, filesize, false, image_w, image_h, thumb_w, thumb_h, id, boardid FROM DBPREFIXposts_old WHERE filename != '';
|
||||
|
||||
UPDATE DBPREFIXfiles as files, DBPREFIXposts as posts
|
||||
SET files.post_id = posts.id
|
||||
WHERE files.oldpostid = posts.oldselfid AND files.oldboardid = posts.oldboardid;
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue