]> git.rm.cloudns.org Git - xonotic/xonstatdb.git/commitdiff
Add table definitions.
authorAnt Zucaro <azucaro@gmail.com>
Tue, 18 Nov 2014 03:16:40 +0000 (22:16 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Tue, 18 Nov 2014 03:16:40 +0000 (22:16 -0500)
scripts/gen_trigger.shl

index 1746278b84ac2444d6d8387dccb358e1bb0e13d9..3a6d2e85fa0c917187111705227043f874861b7e 100755 (executable)
@@ -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"