From f7c8651d51b6aed6b0ea752fff612b9369470800 Mon Sep 17 00:00:00 2001 From: woogerboy21 Date: Fri, 30 Dec 2016 16:45:28 -0800 Subject: [PATCH] Added privilege level start/end columns (#2328) * Added privilege level start/end columns Added 2 new columns to the users table to indicate when a users privilege level date / time was recognised and when the privilege level should end. * Updated database header Always forget about the database header file... * Added priv level maintenance script Added a bash maintenance script that can be run on a scheduled basis that will demote privileged users that have the end times on the accounts that are prior to the date/time the script is executed. * Added donations table Added donations table to db for tracking user donations --- .../migrations/servatrice_0019_to_0020.sql | 20 +++++++++++++++++++ servatrice/scripts/linux/maint_privlevel | 8 ++++++++ servatrice/servatrice.sql | 16 ++++++++++++++- .../src/servatrice_database_interface.h | 2 +- 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 servatrice/migrations/servatrice_0019_to_0020.sql create mode 100644 servatrice/scripts/linux/maint_privlevel diff --git a/servatrice/migrations/servatrice_0019_to_0020.sql b/servatrice/migrations/servatrice_0019_to_0020.sql new file mode 100644 index 00000000..337e27fb --- /dev/null +++ b/servatrice/migrations/servatrice_0019_to_0020.sql @@ -0,0 +1,20 @@ +-- Servatrice db migration from version 19 to version 20 + +alter table cockatrice_users add column privlevelStartDate datetime NOT NULL; +alter table cockatrice_users add column privlevelEndDate datetime NOT NULL; +update cockatrice_users set privlevelStartDate = NOW() where privlevel != 'NONE'; +update cockatrice_users set privlevelEndDate = DATE_ADD(NOW() , INTERVAL 30 DAY) where privlevel != 'NONE'; + +CREATE TABLE IF NOT EXISTS `cockatrice_donations` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `username` varchar(255) DEFAULT NULL, + `email` varchar(255) DEFAULT NULL, + `payment_pre_fee` double DEFAULT NULL, + `payment_post_fee` double DEFAULT NULL, + `term_length` int(11) DEFAULT NULL, + `date` varchar(255) DEFAULT NULL, + `pp_type` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +UPDATE cockatrice_schema_version SET version=20 WHERE version=19; diff --git a/servatrice/scripts/linux/maint_privlevel b/servatrice/scripts/linux/maint_privlevel new file mode 100644 index 00000000..cced056e --- /dev/null +++ b/servatrice/scripts/linux/maint_privlevel @@ -0,0 +1,8 @@ +#!/bin/bash + +# SCHEDULE WITH CRONTAB TO RUN ON A REGULAR BASIS + +DBNAME="servatrice" #set this to the database name used +TABLEPREFIX="cockatrice" #set this to the prefix used for the table names in the database (do not inclue the _) +SQLCONFFILE="./mysql.cnf" #set this to the path that contains the mysql.cnf file +mysql --defaults-file=$SQLCONFFILE -h localhost -e "update ""$DBNAME"".""$TABLEPREFIX""_users set privlevel = 'NONE' where privelevel != 'NONE" AND privlevelEndDate < NOW()" diff --git a/servatrice/servatrice.sql b/servatrice/servatrice.sql index dbc16a1a..c1e84f53 100644 --- a/servatrice/servatrice.sql +++ b/servatrice/servatrice.sql @@ -20,7 +20,7 @@ CREATE TABLE IF NOT EXISTS `cockatrice_schema_version` ( PRIMARY KEY (`version`) ) ENGINE=INNODB DEFAULT CHARSET=utf8; -INSERT INTO cockatrice_schema_version VALUES(19); +INSERT INTO cockatrice_schema_version VALUES(20); -- users and user data tables CREATE TABLE IF NOT EXISTS `cockatrice_users` ( @@ -38,6 +38,8 @@ CREATE TABLE IF NOT EXISTS `cockatrice_users` ( `token` binary(16), `clientid` varchar(15) NOT NULL, `privlevel` enum("NONE","VIP","DONATOR") NOT NULL, + `privlevelStartDate` datetime NOT NULL, + `privlevelEndDate` datetime NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`), KEY `token` (`token`), @@ -244,3 +246,15 @@ CREATE TABLE IF NOT EXISTS `cockatrice_user_analytics` ( PRIMARY KEY (`id`), FOREIGN KEY(`id`) REFERENCES `cockatrice_users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=INNODB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `cockatrice_donations` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `username` varchar(255) DEFAULT NULL, + `email` varchar(255) DEFAULT NULL, + `payment_pre_fee` double DEFAULT NULL, + `payment_post_fee` double DEFAULT NULL, + `term_length` int(11) DEFAULT NULL, + `date` varchar(255) DEFAULT NULL, + `pp_type` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/servatrice/src/servatrice_database_interface.h b/servatrice/src/servatrice_database_interface.h index 741a0e7b..8d921b46 100644 --- a/servatrice/src/servatrice_database_interface.h +++ b/servatrice/src/servatrice_database_interface.h @@ -9,7 +9,7 @@ #include "server.h" #include "server_database_interface.h" -#define DATABASE_SCHEMA_VERSION 19 +#define DATABASE_SCHEMA_VERSION 20 class Servatrice;