create_database.rkt 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #lang racket/base
  2. ;; This program creates a sqlite3 database and then creates an empty table
  3. ;; for information on proposals.
  4. (require db
  5. "config.rkt") ; load configuration file
  6. ; create the database and create the table
  7. (define (createdb dbloc)
  8. (write-string (string-append "Creating database " dbloc "\n"))
  9. (define conn (sqlite3-connect #:database dbloc
  10. #:mode 'create))
  11. (query-exec conn "CREATE TABLE proposals (ID INTEGER PRIMARY KEY,
  12. type TEXT NOT NULL,
  13. organization TEXT NOT NULL,
  14. solicitation TEXT NOT NULL,
  15. telescope TEXT DEFAULT '',
  16. orgpropID TEXT NOT NULL,
  17. PI TEXT NOT NULL,
  18. title TEXT NOT NULL,
  19. CoI TEXT NOT NULL,
  20. status TEXT NOT NULL,
  21. submitteddate TEXT NOT NULL,
  22. resultdate TEXT DEFAULT '')")
  23. (disconnect conn)
  24. (write-string (string-append "Database created at " dbloc "\n")))
  25. ; make sure we can use the sqlite3 connection
  26. (cond (not (sqlite3-available?))
  27. (error "Sqlite3 library not available."))
  28. ; create the database and add the `proposals` table if it doesn't exist
  29. (if (not (file-exists? dbloc))
  30. (createdb dbloc)
  31. (write-string "Database exists. Exiting."))