From: Ant Zucaro Date: Tue, 18 Nov 2014 03:16:40 +0000 (-0500) Subject: Add table definitions. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=edf90be5cf862cd6ce706fe20d7090892cce3b09;p=xonotic%2Fxonstatdb.git Add table definitions. --- diff --git a/scripts/gen_trigger.shl b/scripts/gen_trigger.shl index 1746278..3a6d2e8 100755 --- a/scripts/gen_trigger.shl +++ b/scripts/gen_trigger.shl @@ -4,6 +4,31 @@ table=$1 start_year=$2 end_year=$3 +for year in `seq $start_year $end_year` +do + for qtr in "q1" "q2" "q3" "q4" + do + printf "CREATE TABLE IF NOT EXISTS xonstat.%s_%s%s ( \n" $table $year $qtr + if [[ $qtr = "q1" ]] + then + printf "\tCHECK ( create_dt >= DATE '%s-01-01' AND create_dt < DATE '%s-04-01' ) \n" $year $year + elif [[ $qtr = "q2" ]] + then + printf "\tCHECK ( create_dt >= DATE '%s-04-01' AND create_dt < DATE '%s-07-01' ) \n" $year $year + elif [[ $qtr = "q3" ]] + then + printf "\tCHECK ( create_dt >= DATE '%s-07-01' AND create_dt < DATE '%s-10-01' ) \n" $year $year + elif [[ $qtr = "q4" ]] + then + next_year=$[year + 1] + printf "\tCHECK ( create_dt >= DATE '%s-10-01' AND create_dt < DATE '%s-01-01' ) \n" $year $next_year + fi + + printf ") INHERITS (%s);\n\n" $table + done +done +printf "\n" + printf "CREATE OR REPLACE FUNCTION %s_ins()\n" $table printf "RETURNS TRIGGER AS \$\$\n" printf "BEGIN\n"