Преглед изворни кода

script to create a default database

George C. Privon пре 6 година
родитељ
комит
e8e19d656e
2 измењених фајлова са 37 додато и 2 уклоњено
  1. 2 2
      README.md
  2. 35 0
      create_database.rkt

+ 2 - 2
README.md

@@ -3,5 +3,5 @@
 Tools to create and manipulate a sqlite3 database with information on telescope and funding proposals.
 
 Before using, copy `config.rkt.example` to `config.rkt` and edit it with your desired database location.
-
-Using `update_database.rkt` to add new proposal entries.
+Then run `create_database.rkt` to create the sqlite3 file and create the `proposals` table.
+Then use `update_database.rkt` to add new proposal entries.

+ 35 - 0
create_database.rkt

@@ -0,0 +1,35 @@
+#lang racket
+
+(require db)
+
+; create the database and create the table
+(define (createdb dbloc)
+  (write-string (string-append "Creating database " dbloc "\n"))
+  (define conn (sqlite3-connect #:database dbloc
+                                #:mode 'create))
+  (query-exec conn "CREATE TABLE proposals (ID INTEGER PRIMARY KEY,
+type TEXT NOT NULL,
+organization TEXT NOT NULL,
+solicitation TEXT NOT NULL,
+telescope TEXT DEFAULT '',
+orgpropID TEXT NOT NULL,
+PI TEXT NOT NULL,
+title TEXT NOT NULL,
+CoI TEXT NOT NULL,
+status TEXT NOT NULL,
+submitteddate TEXT NOT NULL,
+resultdate TEXT DEFAULT '')")
+  (disconnect conn)
+  (write-string (string-append "Database created at " dbloc "\n")))
+
+; load configuration file
+(require (file "config.rkt"))
+
+; make sure we can use the sqlite3 connection
+(cond (not (sqlite3-available?))
+      (error "Sqlite3 library not available."))
+
+; create the database and add the `proposals` table if it doesn't exist
+(if (not (file-exists? dbloc))
+    (createdb dbloc)
+    (write-string "Database exists. Exiting."))