mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-28 08:06:24 -07:00
Made master sql template + builder
SQL all follows one master sql files with the use of queries.
This commit is contained in:
parent
2be7e772d5
commit
6351fe1bd8
5 changed files with 835 additions and 417 deletions
38
build_initdb.py
Normal file
38
build_initdb.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
class macro():
|
||||
def __init__(self, macroname, postgres, sqlite, 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")
|
||||
]
|
||||
masterfile = open("initdb_master.sql").read()
|
||||
|
||||
postgresProcessed = masterfile
|
||||
sqliteProcessed = masterfile
|
||||
mysqlProcessed = masterfile
|
||||
|
||||
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
|
||||
|
||||
error = hasError(postgresProcessed)
|
||||
error = error or hasError(mysqlProcessed)
|
||||
error = error or hasError(sqliteProcessed)
|
||||
|
||||
open("initdb_postgres.sql", 'w').write(postgresProcessed)
|
||||
open("initdb_mysql.sql", 'w').write(mysqlProcessed)
|
||||
open("initdb_sqlite3.sql", 'w').write(sqliteProcessed)
|
||||
|
||||
if error:
|
||||
input("Error processing macros, files still contain curly braces (might be in comments?), press any key to continue")
|
263
initdb_master.sql
Normal file
263
initdb_master.sql
Normal file
|
@ -0,0 +1,263 @@
|
|||
-- 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 database_version(
|
||||
version int NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO database_version(version)
|
||||
VALUES(1);
|
||||
|
||||
CREATE TABLE sections(
|
||||
id {serial pk},
|
||||
name TEXT NOT NULL,
|
||||
abbreviation TEXT NOT NULL,
|
||||
position SMALLINT NOT NULL,
|
||||
hidden BOOL NOT NULL,
|
||||
UNIQUE(position)
|
||||
);
|
||||
|
||||
create table boards(
|
||||
id {serial pk},
|
||||
section_id {fk to serial} NOT NULL,
|
||||
uri text 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 SMALLINT NOT NULL,
|
||||
max_threads SMALLINT NOT NULL,
|
||||
default_style VARCHAR(45) NOT NULL,
|
||||
locked bool NOT NULL,
|
||||
created_at timestamp NOT NULL,
|
||||
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,
|
||||
redictect_to_thread bool NOT NULL,
|
||||
require_file bool NOT NULL,
|
||||
enable_catalog bool NOT NULL,
|
||||
FOREIGN KEY(section_id) REFERENCES sections(id),
|
||||
UNIQUE(dir),
|
||||
UNIQUE(uri),
|
||||
UNIQUE(navbar_position)
|
||||
);
|
||||
|
||||
create table threads(
|
||||
id {serial pk},
|
||||
board_id {fk to serial} NOT NULL,
|
||||
locked bool NOT NULL,
|
||||
stickied bool NOT NULL,
|
||||
anchored bool NOT NULL,
|
||||
cyclical bool NOT NULL,
|
||||
last_bump timestamp NOT NULL,
|
||||
deleted_at timestamp NOT NULL,
|
||||
is_deleted bool NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id)
|
||||
);
|
||||
|
||||
CREATE INDEX thread_deleted_index ON threads(is_deleted);
|
||||
|
||||
create table posts(
|
||||
id {serial pk},
|
||||
thread_id {fk to serial} NOT NULL,
|
||||
is_top_post bool NOT NULL,
|
||||
ip int NOT NULL,
|
||||
created_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
name VARCHAR(50) NOT NULL,
|
||||
tripcode VARCHAR(10) NOT NULL,
|
||||
is_role_signature bool NOT NULL DEFAULT FALSE,
|
||||
email VARCHAR(50) NOT NULL,
|
||||
subject VARCHAR(100) NOT NULL,
|
||||
message text NOT NULL,
|
||||
message_raw text NOT NULL,
|
||||
password text NOT NULL,
|
||||
deleted_at timestamp NOT NULL,
|
||||
is_deleted bool NOT NULL,
|
||||
banned_message text,
|
||||
FOREIGN KEY(thread_id) REFERENCES threads(id)
|
||||
);
|
||||
|
||||
CREATE INDEX top_post_index ON posts(is_top_post);
|
||||
|
||||
create table files(
|
||||
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,
|
||||
checksum int NOT NULL,
|
||||
file_size int NOT NULL,
|
||||
is_spoilered bool NOT NULL,
|
||||
FOREIGN KEY(post_id) REFERENCES posts(id),
|
||||
UNIQUE(post_id, file_order)
|
||||
);
|
||||
|
||||
create table staff(
|
||||
id {serial pk},
|
||||
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,
|
||||
is_active bool NOT NULL DEFAULT TRUE,
|
||||
UNIQUE(username)
|
||||
);
|
||||
|
||||
create table sessions(
|
||||
id {serial pk},
|
||||
staff_id {fk to serial} NOT NULL,
|
||||
expires TIMESTAMP NOT NULL,
|
||||
data varchar(45) NOT NULL,
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table board_staff(
|
||||
board_id {fk to serial} NOT NULL,
|
||||
staff_id {fk to serial} NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table announcements(
|
||||
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,
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table ip_ban(
|
||||
id {serial pk},
|
||||
staff_id {fk to serial} NOT NULL,
|
||||
board_id {fk to serial} NOT NULL,
|
||||
banned_for_post_id {fk to serial} NOT NULL,
|
||||
copy_post_text text NOT NULL,
|
||||
is_active bool NOT NULL,
|
||||
ip int 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 boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id),
|
||||
FOREIGN KEY(banned_for_post_id) REFERENCES posts(id)
|
||||
);
|
||||
|
||||
create table ip_ban_audit(
|
||||
ip_ban_id {fk to serial} NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
staff_id {fk to serial} NOT NULL,
|
||||
is_active 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 ip_ban(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table ip_ban_appeals(
|
||||
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,
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id),
|
||||
FOREIGN KEY(ip_ban_id) REFERENCES ip_ban(id)
|
||||
);
|
||||
|
||||
create table ip_ban_appeals_audit(
|
||||
appeal_id {fk to serial} NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
staff_id {fk to serial},
|
||||
appeal_text text NOT NULL,
|
||||
staff_response text,
|
||||
is_denied bool NOT NULL,
|
||||
PRIMARY KEY(appeal_id, timestamp),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id),
|
||||
FOREIGN KEY(appeal_id) REFERENCES ip_ban_appeals(id)
|
||||
);
|
||||
|
||||
create table reports(
|
||||
id {serial pk},
|
||||
handled_by_staff_id {fk to serial},
|
||||
post_id {fk to serial} NOT NULL,
|
||||
ip int NOT NULL,
|
||||
reason text NOT NULL,
|
||||
is_cleared bool NOT NULL,
|
||||
FOREIGN KEY(handled_by_staff_id) REFERENCES staff(id),
|
||||
FOREIGN KEY(post_id) REFERENCES posts(id)
|
||||
);
|
||||
|
||||
create table reports_audit(
|
||||
report_id {fk to serial} NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
handled_by_staff_id {fk to serial},
|
||||
is_cleared bool NOT NULL,
|
||||
FOREIGN KEY(handled_by_staff_id) REFERENCES staff(id),
|
||||
FOREIGN KEY(report_id) REFERENCES reports(id)
|
||||
);
|
||||
|
||||
create table filename_ban(
|
||||
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,
|
||||
is_regex bool NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table username_ban(
|
||||
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,
|
||||
is_regex bool NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table file_ban(
|
||||
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 int NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table wordfilters(
|
||||
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 <> ''),
|
||||
is_regex bool NOT NULL,
|
||||
change_to VARCHAR(75) NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
446
initdb_mysql.sql
446
initdb_mysql.sql
|
@ -1,215 +1,263 @@
|
|||
-- Gochan MySQL startup/update script
|
||||
-- DO NOT DELETE
|
||||
-- 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 IF NOT EXISTS `DBPREFIXannouncements` (
|
||||
`id` SERIAL,
|
||||
`subject` VARCHAR(45) NOT NULL DEFAULT '',
|
||||
`message` TEXT NOT NULL CHECK (message <> ''),
|
||||
`poster` VARCHAR(45) NOT NULL CHECK (poster <> ''),
|
||||
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
CREATE TABLE database_version(
|
||||
version int NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DBPREFIXappeals` (
|
||||
`id` SERIAL,
|
||||
`ban` INT(11) UNSIGNED NOT NULL CHECK (ban <> 0),
|
||||
`message` TEXT NOT NULL CHECK (message <> ''),
|
||||
`timestamp` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
`denied` BOOLEAN DEFAULT false,
|
||||
`staff_response` TEXT NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
INSERT INTO database_version(version)
|
||||
VALUES(1);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DBPREFIXbanlist` (
|
||||
`id` SERIAL,
|
||||
`allow_read` BOOLEAN DEFAULT TRUE,
|
||||
`ip` VARCHAR(45) NOT NULL DEFAULT '',
|
||||
`name` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`name_is_regex` BOOLEAN DEFAULT FALSE,
|
||||
`filename` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`file_checksum` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`boards` VARCHAR(255) NOT NULL DEFAULT '*',
|
||||
`staff` VARCHAR(50) NOT NULL DEFAULT '',
|
||||
`timestamp` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
`expires` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`permaban` BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
`reason` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`type` SMALLINT NOT NULL DEFAULT 3,
|
||||
`staff_note` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`appeal_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`can_appeal` BOOLEAN NOT NULL DEFAULT true,
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
ALTER TABLE `DBPREFIXbanlist`
|
||||
CHANGE IF EXISTS `banned_by` `staff` VARCHAR(50) NOT NULL DEFAULT '',
|
||||
CHANGE IF EXISTS `id` `id` SERIAL,
|
||||
CHANGE IF EXISTS `expires` `expires` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CHANGE IF EXISTS `boards` `boards` VARCHAR(255) NOT NULL DEFAULT '*',
|
||||
ADD COLUMN IF NOT EXISTS `type` TINYINT UNSIGNED NOT NULL DEFAULT 3,
|
||||
ADD COLUMN IF NOT EXISTS `name_is_regex` BOOLEAN DEFAULT FALSE,
|
||||
ADD COLUMN IF NOT EXISTS `filename` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS `file_checksum` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
ADD COLUMN IF NOT EXISTS `permaban` BOOLEAN DEFAULT FALSE,
|
||||
ADD COLUMN IF NOT EXISTS `can_appeal` BOOLEAN DEFAULT TRUE,
|
||||
DROP COLUMN IF EXISTS `message`;
|
||||
CREATE TABLE sections(
|
||||
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,
|
||||
UNIQUE(position)
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS `DBPREFIXbannedhashes`;
|
||||
create table boards(
|
||||
id bigint NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
section_id bigint NOT NULL,
|
||||
uri text 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 SMALLINT NOT NULL,
|
||||
max_threads SMALLINT NOT NULL,
|
||||
default_style VARCHAR(45) NOT NULL,
|
||||
locked bool NOT NULL,
|
||||
created_at timestamp NOT NULL,
|
||||
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,
|
||||
redictect_to_thread bool NOT NULL,
|
||||
require_file bool NOT NULL,
|
||||
enable_catalog bool NOT NULL,
|
||||
FOREIGN KEY(section_id) REFERENCES sections(id),
|
||||
UNIQUE(dir),
|
||||
UNIQUE(uri),
|
||||
UNIQUE(navbar_position)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DBPREFIXboards` (
|
||||
`id` SERIAL,
|
||||
`list_order` TINYINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`dir` VARCHAR(45) NOT NULL CHECK (dir <> ''),
|
||||
`type` TINYINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`upload_type` TINYINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`title` VARCHAR(45) NOT NULL CHECK (title <> ''),
|
||||
`subtitle` VARCHAR(64) NOT NULL DEFAULT '',
|
||||
`description` VARCHAR(64) NOT NULL DEFAULT '',
|
||||
`section` INT NOT NULL DEFAULT 1,
|
||||
`max_file_size` INT UNSIGNED NOT NULL DEFAULT 4718592,
|
||||
`max_pages` TINYINT UNSIGNED NOT NULL DEFAULT 11,
|
||||
`default_style` VARCHAR(45) NOT NULL DEFAULT '',
|
||||
`locked` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
`created_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`anonymous` VARCHAR(45) NOT NULL DEFAULT 'Anonymous',
|
||||
`forced_anon` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
`max_age` INT(20) UNSIGNED NOT NULL DEFAULT 0,
|
||||
`autosage_after` INT(5) UNSIGNED NOT NULL DEFAULT 200,
|
||||
`no_images_after` INT(5) UNSIGNED NOT NULL DEFAULT 0,
|
||||
`max_message_length` INT(10) UNSIGNED NOT NULL DEFAULT 8192,
|
||||
`embeds_allowed` BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
`redirect_to_thread` BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
`require_file` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
`enable_catalog` BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE (`dir`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
ALTER TABLE `DBPREFIXboards`
|
||||
CHANGE COLUMN IF EXISTS `order` `list_order` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
CHANGE COLUMN IF EXISTS `max_image_size` `max_file_size` INT UNSIGNED NOT NULL DEFAULT 4718592,
|
||||
CHANGE COLUMN IF EXISTS `default_style` `default_style` VARCHAR(45) NOT NULL DEFAULT '',
|
||||
DROP COLUMN IF EXISTS `locale`;
|
||||
create table threads(
|
||||
id bigint NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
board_id bigint NOT NULL,
|
||||
locked bool NOT NULL,
|
||||
stickied bool NOT NULL,
|
||||
anchored bool NOT NULL,
|
||||
cyclical bool NOT NULL,
|
||||
last_bump timestamp NOT NULL,
|
||||
deleted_at timestamp NOT NULL,
|
||||
is_deleted bool NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DBPREFIXembeds` (
|
||||
`id` SERIAL,
|
||||
`filetype` VARCHAR(3) NOT NULL,
|
||||
`name` VARCHAR(45) NOT NULL,
|
||||
`video_url` VARCHAR(255) NOT NULL,
|
||||
`width` SMALLINT UNSIGNED NOT NULL,
|
||||
`height` SMALLINT UNSIGNED NOT NULL,
|
||||
`embed_code` TEXT NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
CREATE INDEX thread_deleted_index ON threads(is_deleted);
|
||||
|
||||
DROP TABLE IF EXISTS `DBPREFIXfrontpage`;
|
||||
create table posts(
|
||||
id bigint NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
thread_id bigint NOT NULL,
|
||||
is_top_post bool NOT NULL,
|
||||
ip int NOT NULL,
|
||||
created_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
name VARCHAR(50) NOT NULL,
|
||||
tripcode VARCHAR(10) NOT NULL,
|
||||
is_role_signature bool NOT NULL DEFAULT FALSE,
|
||||
email VARCHAR(50) NOT NULL,
|
||||
subject VARCHAR(100) NOT NULL,
|
||||
message text NOT NULL,
|
||||
message_raw text NOT NULL,
|
||||
password text NOT NULL,
|
||||
deleted_at timestamp NOT NULL,
|
||||
is_deleted bool NOT NULL,
|
||||
banned_message text,
|
||||
FOREIGN KEY(thread_id) REFERENCES threads(id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DBPREFIXinfo` (
|
||||
`name` VARCHAR(45) NOT NULL,
|
||||
`value` TEXT NOT NULL,
|
||||
PRIMARY KEY (`name`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
CREATE INDEX top_post_index ON posts(is_top_post);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DBPREFIXlinks` (
|
||||
`id` SERIAL,
|
||||
`title` VARCHAR(45) NOT NULL,
|
||||
`url` VARCHAR(255) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
create table files(
|
||||
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 int NOT NULL,
|
||||
file_size int NOT NULL,
|
||||
is_spoilered bool NOT NULL,
|
||||
FOREIGN KEY(post_id) REFERENCES posts(id),
|
||||
UNIQUE(post_id, file_order)
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS `DBPREFIXloginattempts`;
|
||||
DROP TABLE IF EXISTS `DBPREFIXpluginsettings`;
|
||||
create table staff(
|
||||
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,
|
||||
is_active bool NOT NULL DEFAULT TRUE,
|
||||
UNIQUE(username)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DBPREFIXposts` (
|
||||
`id` SERIAL,
|
||||
`boardid` INT NOT NULL,
|
||||
`parentid` INT(10) UNSIGNED NOT NULL DEFAULT '0',
|
||||
`name` VARCHAR(50) NOT NULL,
|
||||
`tripcode` VARCHAR(10) NOT NULL,
|
||||
`email` VARCHAR(50) NOT NULL,
|
||||
`subject` VARCHAR(100) NOT NULL,
|
||||
`message` TEXT NOT NULL,
|
||||
`message_raw` TEXT NOT NULL,
|
||||
`password` VARCHAR(45) NOT NULL,
|
||||
`filename` VARCHAR(45) NOT NULL DEFAULT '',
|
||||
`filename_original` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`file_checksum` VARCHAR(45) NOT NULL DEFAULT '',
|
||||
`filesize` INT(20) UNSIGNED NOT NULL DEFAULT 0,
|
||||
`image_w` SMALLINT(5) UNSIGNED NOT NULL DEFAULT 0,
|
||||
`image_h` SMALLINT(5) UNSIGNED NOT NULL DEFAULT 0,
|
||||
`thumb_w` SMALLINT(5) UNSIGNED NOT NULL DEFAULT 0,
|
||||
`thumb_h` SMALLINT(5) UNSIGNED NOT NULL DEFAULT 0,
|
||||
`ip` VARCHAR(45) NOT NULL DEFAULT '',
|
||||
`tag` VARCHAR(5) NOT NULL DEFAULT '',
|
||||
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`autosage` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
`deleted_timestamp` TIMESTAMP,
|
||||
`bumped` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`stickied` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
`locked` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
`reviewed` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY (`boardid`,`id`),
|
||||
KEY `parentid` (`parentid`),
|
||||
KEY `bumped` (`bumped`),
|
||||
KEY `file_checksum` (`file_checksum`),
|
||||
KEY `stickied` (`stickied`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
ALTER TABLE `DBPREFIXposts`
|
||||
DROP COLUMN IF EXISTS `sillytag`,
|
||||
DROP COLUMN IF EXISTS `poster_authority`;
|
||||
create table sessions(
|
||||
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 staff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DBPREFIXreports` (
|
||||
`id` SERIAL,
|
||||
`board` VARCHAR(45) NOT NULL,
|
||||
`postid` INT(10) UNSIGNED NOT NULL,
|
||||
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`ip` VARCHAR(45) NOT NULL,
|
||||
`reason` VARCHAR(255) NOT NULL,
|
||||
`cleared` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
`istemp` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
create table board_staff(
|
||||
board_id bigint NOT NULL,
|
||||
staff_id bigint NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DBPREFIXsections` (
|
||||
`id` SERIAL,
|
||||
`list_order` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`hidden` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
`name` VARCHAR(45) NOT NULL,
|
||||
`abbreviation` VARCHAR(10) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
ALTER TABLE `DBPREFIXsections`
|
||||
CHANGE COLUMN IF EXISTS `order` `list_order` INT UNSIGNED NOT NULL DEFAULT 0;
|
||||
create table announcements(
|
||||
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 staff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DBPREFIXsessions` (
|
||||
`id` SERIAL,
|
||||
`name` CHAR(16) NOT NULL,
|
||||
`sessiondata` VARCHAR(45) NOT NULL,
|
||||
`expires` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MEMORY DEFAULT CHARSET=utf8mb4;
|
||||
ALTER TABLE `DBPREFIXsessions`
|
||||
CHANGE IF EXISTS `key` `name` CHAR(16) NOT NULL,
|
||||
CHANGE IF EXISTS `data` `sessiondata` VARCHAR(45) NOT NULL;
|
||||
create table ip_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 NOT NULL,
|
||||
copy_post_text text NOT NULL,
|
||||
is_active bool NOT NULL,
|
||||
ip int 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 boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id),
|
||||
FOREIGN KEY(banned_for_post_id) REFERENCES posts(id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DBPREFIXstaff` (
|
||||
`id` SERIAL,
|
||||
`username` VARCHAR(45) NOT NULL,
|
||||
`password_checksum` VARCHAR(120) NOT NULL,
|
||||
`rank` TINYINT(1) UNSIGNED NOT NULL DEFAULT 2,
|
||||
`boards` VARCHAR(128) NOT NULL DEFAULT '*',
|
||||
`added_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`last_active` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE (`username`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
ALTER TABLE `DBPREFIXstaff`
|
||||
CHANGE IF EXISTS `boards` `boards` VARCHAR(128) NOT NULL DEFAULT '*',
|
||||
DROP COLUMN IF EXISTS `salt`;
|
||||
create table ip_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,
|
||||
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 ip_ban(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DBPREFIXwordfilters` (
|
||||
`id` SERIAL,
|
||||
`search` VARCHAR(75) NOT NULL CHECK (search <> ''),
|
||||
`change_to` VARCHAR(75) NOT NULL DEFAULT '',
|
||||
`boards` VARCHAR(128) NOT NULL DEFAULT '*',
|
||||
`regex` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
create table ip_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 staff(id),
|
||||
FOREIGN KEY(ip_ban_id) REFERENCES ip_ban(id)
|
||||
);
|
||||
|
||||
create table ip_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 staff(id),
|
||||
FOREIGN KEY(appeal_id) REFERENCES ip_ban_appeals(id)
|
||||
);
|
||||
|
||||
create table reports(
|
||||
id bigint NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY,
|
||||
handled_by_staff_id bigint,
|
||||
post_id bigint NOT NULL,
|
||||
ip int NOT NULL,
|
||||
reason text NOT NULL,
|
||||
is_cleared bool NOT NULL,
|
||||
FOREIGN KEY(handled_by_staff_id) REFERENCES staff(id),
|
||||
FOREIGN KEY(post_id) REFERENCES posts(id)
|
||||
);
|
||||
|
||||
create table reports_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 staff(id),
|
||||
FOREIGN KEY(report_id) REFERENCES reports(id)
|
||||
);
|
||||
|
||||
create table filename_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 boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table username_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 boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table file_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 int NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table wordfilters(
|
||||
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 boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
-- Gochan postgresql new database script
|
||||
-- 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
|
||||
|
||||
|
@ -10,18 +12,17 @@ INSERT INTO database_version(version)
|
|||
VALUES(1);
|
||||
|
||||
CREATE TABLE sections(
|
||||
id serial,
|
||||
id bigserial PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
abbreviation TEXT NOT NULL,
|
||||
position SMALLINT NOT NULL,
|
||||
hidden BOOL NOT NULL,
|
||||
PRIMARY KEY(id),
|
||||
UNIQUE(position)
|
||||
);
|
||||
|
||||
create table boards(
|
||||
id serial,
|
||||
section_id int NOT NULL,
|
||||
id bigserial PRIMARY KEY,
|
||||
section_id bigint NOT NULL,
|
||||
uri text NOT NULL,
|
||||
dir varchar(45) NOT NULL,
|
||||
navbar_position SMALLINT NOT NULL,
|
||||
|
@ -43,7 +44,6 @@ create table boards(
|
|||
redictect_to_thread bool NOT NULL,
|
||||
require_file bool NOT NULL,
|
||||
enable_catalog bool NOT NULL,
|
||||
PRIMARY KEY(id),
|
||||
FOREIGN KEY(section_id) REFERENCES sections(id),
|
||||
UNIQUE(dir),
|
||||
UNIQUE(uri),
|
||||
|
@ -51,8 +51,8 @@ create table boards(
|
|||
);
|
||||
|
||||
create table threads(
|
||||
id serial,
|
||||
board_id int NOT NULL,
|
||||
id bigserial PRIMARY KEY,
|
||||
board_id bigint NOT NULL,
|
||||
locked bool NOT NULL,
|
||||
stickied bool NOT NULL,
|
||||
anchored bool NOT NULL,
|
||||
|
@ -60,15 +60,14 @@ create table threads(
|
|||
last_bump timestamp NOT NULL,
|
||||
deleted_at timestamp NOT NULL,
|
||||
is_deleted bool NOT NULL,
|
||||
PRIMARY KEY(id),
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id)
|
||||
);
|
||||
|
||||
CREATE INDEX thread_deleted_index ON threads(is_deleted);
|
||||
|
||||
create table posts(
|
||||
id serial,
|
||||
thread_id int NOT NULL,
|
||||
id bigserial PRIMARY KEY,
|
||||
thread_id bigint NOT NULL,
|
||||
is_top_post bool NOT NULL,
|
||||
ip int NOT NULL,
|
||||
created_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
@ -83,69 +82,64 @@ create table posts(
|
|||
deleted_at timestamp NOT NULL,
|
||||
is_deleted bool NOT NULL,
|
||||
banned_message text,
|
||||
PRIMARY KEY(id),
|
||||
FOREIGN KEY(thread_id) REFERENCES threads(id)
|
||||
);
|
||||
|
||||
CREATE INDEX top_post_index ON posts(is_top_post);
|
||||
|
||||
create table files(
|
||||
id serial,
|
||||
post_id int NOT NULL,
|
||||
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 int NOT NULL,
|
||||
file_size int NOT NULL,
|
||||
is_spoilered bool NOT NULL,
|
||||
PRIMARY KEY(id),
|
||||
FOREIGN KEY(post_id) REFERENCES posts(id),
|
||||
UNIQUE(post_id, file_order)
|
||||
);
|
||||
|
||||
create table staff(
|
||||
id serial,
|
||||
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,
|
||||
is_active bool NOT NULL DEFAULT TRUE,
|
||||
PRIMARY KEY(id),
|
||||
UNIQUE(username)
|
||||
);
|
||||
|
||||
create table sessions(
|
||||
id serial,
|
||||
staff_id int NOT NULL,
|
||||
id bigserial PRIMARY KEY,
|
||||
staff_id bigint NOT NULL,
|
||||
expires TIMESTAMP NOT NULL,
|
||||
data varchar(45) NOT NULL,
|
||||
PRIMARY KEY(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table board_staff(
|
||||
board_id int NOT NULL,
|
||||
staff_id int NOT NULL,
|
||||
board_id bigint NOT NULL,
|
||||
staff_id bigint NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table announcements(
|
||||
id serial,
|
||||
staff_id int NOT NULL,
|
||||
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,
|
||||
PRIMARY KEY(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table ip_ban(
|
||||
id serial,
|
||||
staff_id int NOT NULL,
|
||||
board_id int NOT NULL,
|
||||
banned_for_post_id int NOT NULL,
|
||||
id bigserial PRIMARY KEY,
|
||||
staff_id bigint NOT NULL,
|
||||
board_id bigint NOT NULL,
|
||||
banned_for_post_id bigint NOT NULL,
|
||||
copy_post_text text NOT NULL,
|
||||
is_active bool NOT NULL,
|
||||
ip int NOT NULL,
|
||||
|
@ -156,17 +150,15 @@ create table ip_ban(
|
|||
staff_note VARCHAR(255) NOT NULL,
|
||||
message text NOT NULL,
|
||||
can_appeal bool NOT NULL,
|
||||
PRIMARY KEY(id),
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id),
|
||||
FOREIGN KEY(banned_for_post_id) REFERENCES posts(id)
|
||||
);
|
||||
|
||||
create table ip_ban_audit(
|
||||
ip_ban_id int NOT NULL,
|
||||
ip_ban_id bigint NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
staff_id int NOT NULL,
|
||||
board_id int NOT NULL,
|
||||
staff_id bigint NOT NULL,
|
||||
is_active bool NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL,
|
||||
appeal_at TIMESTAMP NOT NULL,
|
||||
|
@ -180,21 +172,20 @@ create table ip_ban_audit(
|
|||
);
|
||||
|
||||
create table ip_ban_appeals(
|
||||
id serial,
|
||||
staff_id int,
|
||||
ip_ban_id int NOT NULL,
|
||||
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,
|
||||
PRIMARY KEY(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id),
|
||||
FOREIGN KEY(ip_ban_id) REFERENCES ip_ban(id)
|
||||
);
|
||||
|
||||
create table ip_ban_appeals_audit(
|
||||
appeal_id int NOT NULL,
|
||||
appeal_id bigint NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
staff_id int,
|
||||
staff_id bigint,
|
||||
appeal_text text NOT NULL,
|
||||
staff_response text,
|
||||
is_denied bool NOT NULL,
|
||||
|
@ -204,74 +195,69 @@ create table ip_ban_appeals_audit(
|
|||
);
|
||||
|
||||
create table reports(
|
||||
id serial,
|
||||
handled_by_staff_id int,
|
||||
post_id int NOT NULL,
|
||||
id bigserial PRIMARY KEY,
|
||||
handled_by_staff_id bigint,
|
||||
post_id bigint NOT NULL,
|
||||
ip int NOT NULL,
|
||||
reason text NOT NULL,
|
||||
is_cleared bool NOT NULL,
|
||||
PRIMARY KEY(id),
|
||||
FOREIGN KEY(handled_by_staff_id) REFERENCES staff(id),
|
||||
FOREIGN KEY(post_id) REFERENCES posts(id)
|
||||
);
|
||||
|
||||
create table reports_audit(
|
||||
report_id int NOT NULL,
|
||||
report_id bigint NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
handled_by_staff_id int,
|
||||
handled_by_staff_id bigint,
|
||||
is_cleared bool NOT NULL,
|
||||
FOREIGN KEY(handled_by_staff_id) REFERENCES staff(id),
|
||||
FOREIGN KEY(report_id) REFERENCES reports(id)
|
||||
);
|
||||
|
||||
create table filename_ban(
|
||||
id serial,
|
||||
board_id int,
|
||||
staff_id int NOT NULL,
|
||||
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,
|
||||
PRIMARY KEY(id),
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table username_ban(
|
||||
id serial,
|
||||
board_id int,
|
||||
staff_id int NOT NULL,
|
||||
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,
|
||||
PRIMARY KEY(id),
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table file_ban(
|
||||
id serial,
|
||||
board_id int,
|
||||
staff_id int NOT NULL,
|
||||
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 int NOT NULL,
|
||||
PRIMARY KEY(id),
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table wordfilters(
|
||||
id serial,
|
||||
board_id int,
|
||||
staff_id int NOT NULL,
|
||||
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,
|
||||
PRIMARY KEY(id),
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
|
|
@ -1,180 +1,263 @@
|
|||
-- Gochan SQLite startup/update script
|
||||
-- DO NOT DELETE
|
||||
-- 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 IF NOT EXISTS DBPREFIXannouncements (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
subject VARCHAR(45) NOT NULL DEFAULT '',
|
||||
message TEXT NOT NULL CHECK (message <> ''),
|
||||
poster VARCHAR(45) NOT NULL CHECK (poster <> ''),
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
CREATE TABLE database_version(
|
||||
version int NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DBPREFIXappeals (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
ban INT NOT NULL CHECK (ban <> 0),
|
||||
message TEXT NOT NULL CHECK (message <> ''),
|
||||
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
denied BOOLEAN DEFAULT FALSE,
|
||||
staff_response TEXT NOT NULL
|
||||
INSERT INTO database_version(version)
|
||||
VALUES(1);
|
||||
|
||||
CREATE TABLE sections(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
abbreviation TEXT NOT NULL,
|
||||
position SMALLINT NOT NULL,
|
||||
hidden BOOL NOT NULL,
|
||||
UNIQUE(position)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DBPREFIXbanlist (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
allow_read BOOLEAN DEFAULT TRUE,
|
||||
ip VARCHAR(45) NOT NULL DEFAULT '',
|
||||
name VARCHAR(255) NOT NULL DEFAULT '',
|
||||
name_is_regex BOOLEAN DEFAULT FALSE,
|
||||
filename VARCHAR(255) NOT NULL DEFAULT '',
|
||||
file_checksum VARCHAR(255) NOT NULL DEFAULT '',
|
||||
boards VARCHAR(255) NOT NULL DEFAULT '*',
|
||||
staff VARCHAR(50) NOT NULL DEFAULT '',
|
||||
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
expires TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
permaban BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
reason VARCHAR(255) NOT NULL DEFAULT '',
|
||||
type SMALLINT NOT NULL DEFAULT 3,
|
||||
staff_note VARCHAR(255) NOT NULL DEFAULT '',
|
||||
appeal_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
can_appeal BOOLEAN NOT NULL DEFAULT true
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DBPREFIXboards (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
list_order SMALLINT NOT NULL DEFAULT 0,
|
||||
dir VARCHAR(45) UNIQUE NOT NULL CHECK (dir <> ''),
|
||||
type SMALLINT NOT NULL DEFAULT 0,
|
||||
upload_type SMALLINT NOT NULL DEFAULT 0,
|
||||
title VARCHAR(45) NOT NULL CHECK (title <> ''),
|
||||
subtitle VARCHAR(64) NOT NULL DEFAULT '',
|
||||
description VARCHAR(64) NOT NULL DEFAULT '',
|
||||
section INT NOT NULL DEFAULT 1,
|
||||
max_file_size INT NOT NULL DEFAULT 4718592,
|
||||
max_pages SMALLINT NOT NULL DEFAULT 11,
|
||||
default_style VARCHAR(45) NOT NULL DEFAULT '',
|
||||
locked BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
anonymous VARCHAR(45) NOT NULL DEFAULT 'Anonymous',
|
||||
forced_anon BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
max_age INT NOT NULL DEFAULT 0,
|
||||
autosage_after INT NOT NULL DEFAULT 200,
|
||||
no_images_after INT NOT NULL DEFAULT 0,
|
||||
max_message_length INT NOT NULL DEFAULT 8192,
|
||||
embeds_allowed BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
redirect_to_thread BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
require_file BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
enable_catalog BOOLEAN NOT NULL DEFAULT TRUE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DBPREFIXembeds (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
filetype VARCHAR(3) NOT NULL,
|
||||
name VARCHAR(45) NOT NULL,
|
||||
video_url VARCHAR(255) NOT NULL,
|
||||
width SMALLINT NOT NULL,
|
||||
height SMALLINT NOT NULL,
|
||||
embed_code TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DBPREFIXinfo (
|
||||
name VARCHAR(45) PRIMARY KEY NOT NULL,
|
||||
value TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DBPREFIXlinks (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
create table boards(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
section_id INTEGER NOT NULL,
|
||||
uri text NOT NULL,
|
||||
dir varchar(45) NOT NULL,
|
||||
navbar_position SMALLINT NOT NULL,
|
||||
title VARCHAR(45) NOT NULL,
|
||||
url VARCHAR(255) NOT NULL
|
||||
subtitle VARCHAR(64) NOT NULL,
|
||||
description VARCHAR(64) NOT NULL,
|
||||
max_file_size SMALLINT NOT NULL,
|
||||
max_threads SMALLINT NOT NULL,
|
||||
default_style VARCHAR(45) NOT NULL,
|
||||
locked bool NOT NULL,
|
||||
created_at timestamp NOT NULL,
|
||||
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,
|
||||
redictect_to_thread bool NOT NULL,
|
||||
require_file bool NOT NULL,
|
||||
enable_catalog bool NOT NULL,
|
||||
FOREIGN KEY(section_id) REFERENCES sections(id),
|
||||
UNIQUE(dir),
|
||||
UNIQUE(uri),
|
||||
UNIQUE(navbar_position)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DBPREFIXposts (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
boardid INT NOT NULL,
|
||||
parentid INT NOT NULL DEFAULT '0',
|
||||
create table threads(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
board_id INTEGER NOT NULL,
|
||||
locked bool NOT NULL,
|
||||
stickied bool NOT NULL,
|
||||
anchored bool NOT NULL,
|
||||
cyclical bool NOT NULL,
|
||||
last_bump timestamp NOT NULL,
|
||||
deleted_at timestamp NOT NULL,
|
||||
is_deleted bool NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id)
|
||||
);
|
||||
|
||||
CREATE INDEX thread_deleted_index ON threads(is_deleted);
|
||||
|
||||
create table posts(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
thread_id INTEGER NOT NULL,
|
||||
is_top_post bool NOT NULL,
|
||||
ip int NOT NULL,
|
||||
created_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
name VARCHAR(50) NOT NULL,
|
||||
tripcode VARCHAR(10) NOT NULL,
|
||||
is_role_signature bool NOT NULL DEFAULT FALSE,
|
||||
email VARCHAR(50) NOT NULL,
|
||||
subject VARCHAR(100) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
message_raw TEXT NOT NULL,
|
||||
password VARCHAR(45) NOT NULL,
|
||||
filename VARCHAR(45) NOT NULL DEFAULT '',
|
||||
filename_original VARCHAR(255) NOT NULL DEFAULT '',
|
||||
file_checksum VARCHAR(45) NOT NULL DEFAULT '',
|
||||
filesize INT NOT NULL DEFAULT 0,
|
||||
image_w SMALLINT NOT NULL DEFAULT 0,
|
||||
image_h SMALLINT NOT NULL DEFAULT 0,
|
||||
thumb_w SMALLINT NOT NULL DEFAULT 0,
|
||||
thumb_h SMALLINT NOT NULL DEFAULT 0,
|
||||
ip VARCHAR(45) NOT NULL DEFAULT '',
|
||||
tag VARCHAR(5) NOT NULL DEFAULT '',
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
autosage BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
deleted_timestamp TIMESTAMP,
|
||||
bumped TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
stickied BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
locked BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
reviewed BOOLEAN NOT NULL DEFAULT FALSE
|
||||
message text NOT NULL,
|
||||
message_raw text NOT NULL,
|
||||
password text NOT NULL,
|
||||
deleted_at timestamp NOT NULL,
|
||||
is_deleted bool NOT NULL,
|
||||
banned_message text,
|
||||
FOREIGN KEY(thread_id) REFERENCES threads(id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DBPREFIXreports (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
board VARCHAR(45) NOT NULL,
|
||||
postid INT NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
ip VARCHAR(45) NOT NULL,
|
||||
reason VARCHAR(255) NOT NULL,
|
||||
cleared BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
istemp BOOLEAN NOT NULL DEFAULT FALSE
|
||||
CREATE INDEX top_post_index ON posts(is_top_post);
|
||||
|
||||
create table files(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
post_id INTEGER NOT NULL,
|
||||
file_order int NOT NULL,
|
||||
original_filename VARCHAR(255) NOT NULL,
|
||||
filename VARCHAR(45) NOT NULL,
|
||||
checksum int NOT NULL,
|
||||
file_size int NOT NULL,
|
||||
is_spoilered bool NOT NULL,
|
||||
FOREIGN KEY(post_id) REFERENCES posts(id),
|
||||
UNIQUE(post_id, file_order)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DBPREFIXsections (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
list_order SMALLINT NOT NULL DEFAULT 0,
|
||||
hidden SMALLINT NOT NULL,
|
||||
name VARCHAR(45) NOT NULL,
|
||||
abbreviation VARCHAR(10) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DBPREFIXsessions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
name CHAR(16) NOT NULL,
|
||||
sessiondata VARCHAR(45) NOT NULL,
|
||||
expires TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DBPREFIXstaff (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
username VARCHAR(45) UNIQUE NOT NULL,
|
||||
create table staff(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username VARCHAR(45) NOT NULL,
|
||||
password_checksum VARCHAR(120) NOT NULL,
|
||||
rank SMALLINT NOT NULL,
|
||||
boards VARCHAR(128) NOT NULL DEFAULT '*',
|
||||
global_rank int,
|
||||
added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
last_active TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
last_login TIMESTAMP NOT NULL,
|
||||
is_active bool NOT NULL DEFAULT TRUE,
|
||||
UNIQUE(username)
|
||||
);
|
||||
|
||||
-- Because SQLite doesn't have DROP COLUMN :(
|
||||
BEGIN TRANSACTION;
|
||||
CREATE TABLE IF NOT EXISTS _DBPREFIXstaff (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
username VARCHAR(45) UNIQUE NOT NULL,
|
||||
password_checksum VARCHAR(120) NOT NULL,
|
||||
rank SMALLINT NOT NULL,
|
||||
boards VARCHAR(128) NOT NULL DEFAULT '*',
|
||||
added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
last_active TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
INSERT INTO _DBPREFIXstaff
|
||||
(id,username,password_checksum,rank,boards,added_on,last_active)
|
||||
SELECT id,username,password_checksum,rank,boards,added_on,last_active
|
||||
FROM DBPREFIXstaff;
|
||||
DROP TABLE DBPREFIXstaff;
|
||||
ALTER TABLE _DBPREFIXstaff RENAME TO DBPREFIXstaff;
|
||||
COMMIT;
|
||||
create table sessions(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
staff_id INTEGER NOT NULL,
|
||||
expires TIMESTAMP NOT NULL,
|
||||
data varchar(45) NOT NULL,
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DBPREFIXwordfilters (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
create table board_staff(
|
||||
board_id INTEGER NOT NULL,
|
||||
staff_id INTEGER NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table announcements(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
staff_id INTEGER NOT NULL,
|
||||
subject VARCHAR(45) NOT NULL,
|
||||
message text NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table ip_ban(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
staff_id INTEGER NOT NULL,
|
||||
board_id INTEGER NOT NULL,
|
||||
banned_for_post_id INTEGER NOT NULL,
|
||||
copy_post_text text NOT NULL,
|
||||
is_active bool NOT NULL,
|
||||
ip int 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 boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id),
|
||||
FOREIGN KEY(banned_for_post_id) REFERENCES posts(id)
|
||||
);
|
||||
|
||||
create table ip_ban_audit(
|
||||
ip_ban_id INTEGER NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
staff_id INTEGER NOT NULL,
|
||||
is_active 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 ip_ban(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table ip_ban_appeals(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
staff_id INTEGER,
|
||||
ip_ban_id INTEGER NOT NULL,
|
||||
appeal_text text NOT NULL,
|
||||
staff_response text,
|
||||
is_denied bool NOT NULL,
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id),
|
||||
FOREIGN KEY(ip_ban_id) REFERENCES ip_ban(id)
|
||||
);
|
||||
|
||||
create table ip_ban_appeals_audit(
|
||||
appeal_id INTEGER NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
staff_id INTEGER,
|
||||
appeal_text text NOT NULL,
|
||||
staff_response text,
|
||||
is_denied bool NOT NULL,
|
||||
PRIMARY KEY(appeal_id, timestamp),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id),
|
||||
FOREIGN KEY(appeal_id) REFERENCES ip_ban_appeals(id)
|
||||
);
|
||||
|
||||
create table reports(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
handled_by_staff_id INTEGER,
|
||||
post_id INTEGER NOT NULL,
|
||||
ip int NOT NULL,
|
||||
reason text NOT NULL,
|
||||
is_cleared bool NOT NULL,
|
||||
FOREIGN KEY(handled_by_staff_id) REFERENCES staff(id),
|
||||
FOREIGN KEY(post_id) REFERENCES posts(id)
|
||||
);
|
||||
|
||||
create table reports_audit(
|
||||
report_id INTEGER NOT NULL,
|
||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
handled_by_staff_id INTEGER,
|
||||
is_cleared bool NOT NULL,
|
||||
FOREIGN KEY(handled_by_staff_id) REFERENCES staff(id),
|
||||
FOREIGN KEY(report_id) REFERENCES reports(id)
|
||||
);
|
||||
|
||||
create table filename_ban(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
board_id INTEGER,
|
||||
staff_id INTEGER 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 boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table username_ban(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
board_id INTEGER,
|
||||
staff_id INTEGER 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 boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table file_ban(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
board_id INTEGER,
|
||||
staff_id INTEGER NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
checksum int NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
||||
create table wordfilters(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
board_id INTEGER,
|
||||
staff_id INTEGER NOT NULL,
|
||||
staff_note VARCHAR(255) NOT NULL,
|
||||
issued_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
search VARCHAR(75) NOT NULL CHECK (search <> ''),
|
||||
change_to VARCHAR(75) NOT NULL DEFAULT '',
|
||||
boards VARCHAR(128) NOT NULL DEFAULT '*',
|
||||
regex BOOLEAN NOT NULL DEFAULT FALSE
|
||||
is_regex bool NOT NULL,
|
||||
change_to VARCHAR(75) NOT NULL,
|
||||
FOREIGN KEY(board_id) REFERENCES boards(id),
|
||||
FOREIGN KEY(staff_id) REFERENCES staff(id)
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue