Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scripts to and update readme SQL #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ CREATE TABLE `%%BOARD%%` (
`op` tinyint(1) NOT NULL DEFAULT 0,
`timestamp` int(10) unsigned NOT NULL,
`timestamp_expired` int(10) unsigned NOT NULL,
`preview_orig` varchar(20) DEFAULT NULL,
`preview_orig` varchar(23) DEFAULT NULL,
`preview_w` smallint(5) unsigned NOT NULL DEFAULT 0,
`preview_h` smallint(5) unsigned NOT NULL DEFAULT 0,
`media_filename` text DEFAULT NULL,
`media_w` smallint(5) unsigned NOT NULL DEFAULT 0,
`media_h` smallint(5) unsigned NOT NULL DEFAULT 0,
`media_size` int(10) unsigned NOT NULL DEFAULT 0,
`media_hash` varchar(25) DEFAULT NULL,
`media_orig` varchar(20) DEFAULT NULL,
`media_orig` varchar(23) DEFAULT NULL,
`spoiler` tinyint(1) NOT NULL DEFAULT 0,
`deleted` tinyint(1) NOT NULL DEFAULT 0,
`capcode` varchar(1) NOT NULL DEFAULT 'N',
Expand Down Expand Up @@ -225,15 +225,15 @@ CREATE TABLE `%%BOARD%%_deleted` (
`op` tinyint(1) NOT NULL DEFAULT 0,
`timestamp` int(10) unsigned NOT NULL,
`timestamp_expired` int(10) unsigned NOT NULL,
`preview_orig` varchar(20) DEFAULT NULL,
`preview_orig` varchar(23) DEFAULT NULL,
`preview_w` smallint(5) unsigned NOT NULL DEFAULT 0,
`preview_h` smallint(5) unsigned NOT NULL DEFAULT 0,
`media_filename` text DEFAULT NULL,
`media_w` smallint(5) unsigned NOT NULL DEFAULT 0,
`media_h` smallint(5) unsigned NOT NULL DEFAULT 0,
`media_size` int(10) unsigned NOT NULL DEFAULT 0,
`media_hash` varchar(25) DEFAULT NULL,
`media_orig` varchar(20) DEFAULT NULL,
`media_orig` varchar(23) DEFAULT NULL,
`spoiler` tinyint(1) NOT NULL DEFAULT 0,
`deleted` tinyint(1) NOT NULL DEFAULT 0,
`capcode` varchar(1) NOT NULL DEFAULT 'N',
Expand Down Expand Up @@ -266,9 +266,9 @@ CREATE TABLE `%%BOARD%%_deleted` (
CREATE TABLE `%%BOARD%%_images` (
`media_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`media_hash` varchar(25) NOT NULL,
`media` varchar(20) DEFAULT NULL,
`preview_op` varchar(20) DEFAULT NULL,
`preview_reply` varchar(20) DEFAULT NULL,
`media` varchar(23) DEFAULT NULL,
`preview_op` varchar(23) DEFAULT NULL,
`preview_reply` varchar(23) DEFAULT NULL,
`total` int(10) unsigned NOT NULL DEFAULT 0,
`banned` smallint(5) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (`media_id`),
Expand Down Expand Up @@ -347,7 +347,7 @@ BEGIN
DELETE FROM `%%BOARD%%_threads` WHERE thread_num = tnum;
END;;

CREATE PROCEDURE `insert_image_%%BOARD%%` (n_media_hash VARCHAR(25), n_media VARCHAR(20), n_preview VARCHAR(20), n_op INT)
CREATE PROCEDURE `insert_image_%%BOARD%%` (n_media_hash VARCHAR(25), n_media VARCHAR(23), n_preview VARCHAR(23), n_op INT)
BEGIN
IF n_op = 1 THEN
INSERT INTO `%%BOARD%%_images` (media_hash, media, preview_op, total)
Expand Down
67 changes: 67 additions & 0 deletions scripts/change-column-sizes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash
## change-column-sizes.sh
## Modify tables for Neofuuka to be compatable with net 4chan image timestamp values.
## (This change occured during 2022-07.)
##
set -v # Print lines as they are run (bash option).
echo "#[${0##*/}]" "Starting"
echo "#[${0##*/}]" "Running as: $(whoami)@$(hostname)"


##=====< Config >=====##
mariadb_db="fourchan" # Database name.
mariadb_conf="root.my.cnf" # Superuser .my.cnf file.
boards=( # Shortnames of boards (e.g. 'mlp' or 'g' )
'g'
'a'
'c'
'k'
)
##=====< /Config >=====##


##=====< Modify tables and triggers >=====##
echo "#[${0##*/}]" "boards=$boards"
mkdir -vp tmp/ # Just a place to temporarily store the SQL for templating and execution.
for board in ${boards[@]}; do
echo "#[${0##*/}]" "Modifying columns and triggers for:" "board=$board"

## ----- < Modify columns > ----- ##
## ALTER TABLE statements have to be used here, so it needs its own SQL template file.
echo "#[${0##*/}]" "Altering tables for:" "board=$board" "[at $(date +%Y-%m-%d_%H-%M%z=@%s)]"

## Template SQL:
cp -v "modify_columns.template.sql" tmp/"modify_columns.${board}.sql"
sed -i "s/%%BOARD%%/${board}/g" tmp/"modify_columns.${board}.sql"

## Run the SQL:
## https://mariadb.com/kb/en/mysql-command-line-client/
/bin/time/ -- mysql --defaults-extra-file="${mariadb_conf}" --database="${mariadb_db}" \
< tmp/"modify_columns.${board}.sql"

echo "#[${0##*/}]" "Altered tables for:" "board=$board" "[at $(date +%Y-%m-%d_%H-%M%z=@%s)]"
## ----- < /Modify columns > ----- ##


## ----- < /Modify triggers > ----- ##
## The create triggers SQL drops triggers and recreates them already, so just copypaste it (with the appropriate column sizes fixed).
echo "#[${0##*/}]" "Creating triggers for:" "board=$board" "[at $(date +%Y-%m-%d_%H-%M%z=@%s)]"

## Template SQL:
cp -v "create_triggers.template.sql" tmp/"create_triggers.${board}.sql"
sed -i "s/%%BOARD%%/${board}/g" tmp/"create_triggers.${board}.sql"

## Run the SQL:
## https://mariadb.com/kb/en/mysql-command-line-client/
/bin/time/ -- mysql --defaults-extra-file="${mariadb_conf}" --database="${mariadb_db}" --progress-reports \
< tmp/"create_triggers.${board}.sql"

echo "#[${0##*/}]" "Created triggers for:" "board=$board" "[at $(date +%Y-%m-%d_%H-%M%z=@%s)]"
## ----- < /Modify triggers > ----- ##

echo "#[${0##*/}]" "Modified:" "board=$board"
done
##=====< /Modify tables and triggers >=====##


echo "#[${0##*/}]" "Finished" "[at $(date +%Y-%m-%d_%H-%M%z=@%s)]"
40 changes: 40 additions & 0 deletions scripts/create-triggers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
## create-triggers.sh
## Create triggers for specified boards.
##
set -v # Print lines as they are run (bash option).
echo "#[${0##*/}]" "Starting" "[at $(date +%Y-%m-%d_%H-%M%z=@%s)]"
echo "#[${0##*/}]" "Running as: $(whoami)@$(hostname) in $(pwd)"


##=====< Config >=====##
mariadb_db="fourchan" # Database name.
mariadb_conf="root.my.cnf" # Superuser .my.cnf file.
boards=( # Shortnames of boards (e.g. 'mlp' or 'g' )
'h'
'i'
)
##=====< /Config >=====##


##=====< Create triggers >=====##
echo "#[${0##*/}]" "boards=$boards"
mkdir -vp tmp/
for board in ${boards[@]}; do
echo "#[${0##*/}]" "Creating triggers for:" "board=$board" "[at $(date +%Y-%m-%d_%H-%M%z=@%s)]"

## Template SQL:
cp -v "create_triggers.template.sql" tmp/"create_triggers.${board}.sql"
sed -i "s/%%BOARD%%/${board}/g" tmp/"create_triggers.${board}.sql"

## Run the SQL:
## https://mariadb.com/kb/en/mysql-command-line-client/
/bin/time/ -- mysql --defaults-extra-file="${mariadb_conf}" --database="${mariadb_db}" --progress-reports \
< tmp/"create_triggers.${board}.sql"

echo "#[${0##*/}]" "Created triggers for:" "board=$board" "[at $(date +%Y-%m-%d_%H-%M%z=@%s)]"
done
##=====< /Create triggers >=====##


echo "#[${0##*/}]" "Finished" "[at $(date +%Y-%m-%d_%H-%M%z=@%s)]"
40 changes: 40 additions & 0 deletions scripts/create_board_tables.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
## create_tables.sh
## Create tables for specified boards.
##
set -v # Print lines as they are run (bash option).
echo "#[${0##*/}]" "Starting" "[at $(date +%Y-%m-%d_%H-%M%z=@%s)]"
echo "#[${0##*/}]" "Running as: $(whoami)@$(hostname) in $(pwd)"


##=====< Config >=====##
mariadb_db="fourchan" # Database name.
mariadb_conf="root.my.cnf" # Superuser .my.cnf file.
boards=( # Shortnames of boards (e.g. 'mlp' or 'g' )
'h'
'i'
)
##=====< /Config >=====##


##=====< Create tables >=====##
echo "#[${0##*/}]" "boards=$boards"
mkdir -vp tmp/
for board in ${boards[@]}; do
echo "#[${0##*/}]" "Creating tables for:" "board=$board" "[at $(date +%Y-%m-%d_%H-%M%z=@%s)]"

## Template SQL:
cp -v "create_tables.template.sql" tmp/"create_tables.${board}.sql"
sed -i "s/%%BOARD%%/${board}/g" tmp/"create_tables.${board}.sql"

## Run the SQL:
## https://mariadb.com/kb/en/mysql-command-line-client/
/bin/time/ -- mysql --defaults-extra-file="${mariadb_conf}" --database="${mariadb_db}" --progress-reports \
< tmp/"create_tables.${board}.sql"

echo "#[${0##*/}]" "Created tables for:" "board=$board" "[at $(date +%Y-%m-%d_%H-%M%z=@%s)]"
done
##=====< /Create tables >=====##


echo "#[${0##*/}]" "Finished" "[at $(date +%Y-%m-%d_%H-%M%z=@%s)]"
143 changes: 143 additions & 0 deletions scripts/create_tables.template.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* create_triggers.template.sql
* Create tables for Neofuuka.
*
* $ cp -v "modify_columns.template.sql" "modify_columns.${board}.sql"
* $ sed -i "s/%%BOARD%%/${board}/g" "modify_columns.${board}.sql"
*
* $ mysql --defaults-extra-file="${mariadb_conf}" --database="${mariadb_db}" \
* < "modify_columns.${board}.sql"
*/
CREATE TABLE `%%BOARD%%` (
`doc_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`media_id` int(10) unsigned NOT NULL DEFAULT 0,
`poster_ip` decimal(39,0) unsigned NOT NULL DEFAULT 0,
`num` int(10) unsigned NOT NULL,
`subnum` int(10) unsigned NOT NULL,
`thread_num` int(10) unsigned NOT NULL DEFAULT 0,
`op` tinyint(1) NOT NULL DEFAULT 0,
`timestamp` int(10) unsigned NOT NULL,
`timestamp_expired` int(10) unsigned NOT NULL,
`preview_orig` varchar(23) DEFAULT NULL,
`preview_w` smallint(5) unsigned NOT NULL DEFAULT 0,
`preview_h` smallint(5) unsigned NOT NULL DEFAULT 0,
`media_filename` text DEFAULT NULL,
`media_w` smallint(5) unsigned NOT NULL DEFAULT 0,
`media_h` smallint(5) unsigned NOT NULL DEFAULT 0,
`media_size` int(10) unsigned NOT NULL DEFAULT 0,
`media_hash` varchar(25) DEFAULT NULL,
`media_orig` varchar(23) DEFAULT NULL,
`spoiler` tinyint(1) NOT NULL DEFAULT 0,
`deleted` tinyint(1) NOT NULL DEFAULT 0,
`capcode` varchar(1) NOT NULL DEFAULT 'N',
`email` varchar(100) DEFAULT NULL,
`name` varchar(100) DEFAULT NULL,
`trip` varchar(25) DEFAULT NULL,
`title` varchar(100) DEFAULT NULL,
`comment` text DEFAULT NULL,
`delpass` tinytext DEFAULT NULL,
`sticky` tinyint(1) NOT NULL DEFAULT 0,
`locked` tinyint(1) NOT NULL DEFAULT 0,
`poster_hash` varchar(8) DEFAULT NULL,
`poster_country` varchar(2) DEFAULT NULL,
`exif` text DEFAULT NULL,
PRIMARY KEY (`doc_id`),
UNIQUE KEY `num_subnum_index` (`num`,`subnum`),
KEY `thread_num_subnum_index` (`thread_num`,`num`,`subnum`),
KEY `subnum_index` (`subnum`),
KEY `op_index` (`op`),
KEY `media_id_index` (`media_id`),
KEY `media_hash_index` (`media_hash`),
KEY `media_orig_index` (`media_orig`),
KEY `name_trip_index` (`name`,`trip`),
KEY `trip_index` (`trip`),
KEY `email_index` (`email`),
KEY `poster_ip_index` (`poster_ip`),
KEY `timestamp_index` (`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `%%BOARD%%_deleted` (
`doc_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`media_id` int(10) unsigned NOT NULL DEFAULT 0,
`poster_ip` decimal(39,0) unsigned NOT NULL DEFAULT 0,
`num` int(10) unsigned NOT NULL,
`subnum` int(10) unsigned NOT NULL,
`thread_num` int(10) unsigned NOT NULL DEFAULT 0,
`op` tinyint(1) NOT NULL DEFAULT 0,
`timestamp` int(10) unsigned NOT NULL,
`timestamp_expired` int(10) unsigned NOT NULL,
`preview_orig` varchar(23) DEFAULT NULL,
`preview_w` smallint(5) unsigned NOT NULL DEFAULT 0,
`preview_h` smallint(5) unsigned NOT NULL DEFAULT 0,
`media_filename` text DEFAULT NULL,
`media_w` smallint(5) unsigned NOT NULL DEFAULT 0,
`media_h` smallint(5) unsigned NOT NULL DEFAULT 0,
`media_size` int(10) unsigned NOT NULL DEFAULT 0,
`media_hash` varchar(25) DEFAULT NULL,
`media_orig` varchar(23) DEFAULT NULL,
`spoiler` tinyint(1) NOT NULL DEFAULT 0,
`deleted` tinyint(1) NOT NULL DEFAULT 0,
`capcode` varchar(1) NOT NULL DEFAULT 'N',
`email` varchar(100) DEFAULT NULL,
`name` varchar(100) DEFAULT NULL,
`trip` varchar(25) DEFAULT NULL,
`title` varchar(100) DEFAULT NULL,
`comment` text DEFAULT NULL,
`delpass` tinytext DEFAULT NULL,
`sticky` tinyint(1) NOT NULL DEFAULT 0,
`locked` tinyint(1) NOT NULL DEFAULT 0,
`poster_hash` varchar(8) DEFAULT NULL,
`poster_country` varchar(2) DEFAULT NULL,
`exif` text DEFAULT NULL,
PRIMARY KEY (`doc_id`),
UNIQUE KEY `num_subnum_index` (`num`,`subnum`),
KEY `thread_num_subnum_index` (`thread_num`,`num`,`subnum`),
KEY `subnum_index` (`subnum`),
KEY `op_index` (`op`),
KEY `media_id_index` (`media_id`),
KEY `media_hash_index` (`media_hash`),
KEY `media_orig_index` (`media_orig`),
KEY `name_trip_index` (`name`,`trip`),
KEY `trip_index` (`trip`),
KEY `email_index` (`email`),
KEY `poster_ip_index` (`poster_ip`),
KEY `timestamp_index` (`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `%%BOARD%%_images` (
`media_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`media_hash` varchar(25) NOT NULL,
`media` varchar(23) DEFAULT NULL,
`preview_op` varchar(23) DEFAULT NULL,
`preview_reply` varchar(23) DEFAULT NULL,
`total` int(10) unsigned NOT NULL DEFAULT 0,
`banned` smallint(5) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (`media_id`),
UNIQUE KEY `media_hash_index` (`media_hash`),
KEY `total_index` (`total`),
KEY `banned_index` (`banned`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `%%BOARD%%_threads` (
`thread_num` int(10) unsigned NOT NULL,
`time_op` int(10) unsigned NOT NULL,
`time_last` int(10) unsigned NOT NULL,
`time_bump` int(10) unsigned NOT NULL,
`time_ghost` int(10) unsigned DEFAULT NULL,
`time_ghost_bump` int(10) unsigned DEFAULT NULL,
`time_last_modified` int(10) unsigned NOT NULL,
`nreplies` int(10) unsigned NOT NULL DEFAULT 0,
`nimages` int(10) unsigned NOT NULL DEFAULT 0,
`sticky` tinyint(1) NOT NULL DEFAULT 0,
`locked` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`thread_num`),
KEY `time_op_index` (`time_op`),
KEY `time_bump_index` (`time_bump`),
KEY `time_ghost_bump_index` (`time_ghost_bump`),
KEY `time_last_modified_index` (`time_last_modified`),
KEY `sticky_index` (`sticky`),
KEY `locked_index` (`locked`),
KEY `sticky_time_bump_index` (`sticky`,`time_bump`),
KEY `sticky_time_ghost_bump_index` (`sticky`,`time_ghost_bump`),
KEY `sticky_thread_num_index` (`sticky`,`thread_num`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Loading