فهرست منبع

Added database upgrade script, to add code column to existing database

deadtom 2 هفته پیش
والد
کامیت
44d90c43f3
3فایلهای تغییر یافته به همراه22 افزوده شده و 2 حذف شده
  1. 1 1
      ownchatbot/schema.sql
  2. 2 0
      ownchatbot/update_db.sql
  3. 19 1
      update.sh

+ 1 - 1
ownchatbot/schema.sql

@@ -9,7 +9,7 @@ CREATE TABLE IF NOT EXISTS points (
   points INTEGER,  
   user_authed BOOLEAN NOT NULL,
   email TEXT,
-  code integer
+  code INTEGER
 );
 
 CREATE TABLE goals (

+ 2 - 0
ownchatbot/update_db.sql

@@ -0,0 +1,2 @@
+ALTER TABLE points ADD COLUMN code INTEGER;
+

+ 19 - 1
update.sh

@@ -1,4 +1,22 @@
 #!/bin/bash
 #
 
-echo "No updates to make this time around."
+set -e  #  Exit immediately if any command exits with a non-zero status
+
+activate_venv() {
+    source env/bin/activate
+}
+
+update_db() {  # Create the database. This also populates it with some goals and votes from the default rewards.py
+    export FLASK_APP=ownchatbot
+    if python -m flask update-db; then
+        echo "Database updated successfully."
+    else
+        echo "Failed to update the database. Please check for errors."
+        exit 1  # Exit the script with a non-zero status
+    fi
+}
+
+activate_venv
+update_db
+deactivate