create_database.rkt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. ; create the database and create the table
  6. (define (createdb dbloc)
  7. (write-string (string-append "Creating database " dbloc "\n"))
  8. (define conn (sqlite3-connect #:database dbloc
  9. #:mode 'create))
  10. (query-exec conn "CREATE TABLE proposals (ID INTEGER PRIMARY KEY,
  11. type TEXT NOT NULL,
  12. organization TEXT NOT NULL,
  13. solicitation TEXT NOT NULL,
  14. telescope TEXT DEFAULT '',
  15. orgpropID TEXT NOT NULL,
  16. PI TEXT NOT NULL,
  17. title TEXT NOT NULL,
  18. CoI TEXT NOT NULL,
  19. status TEXT NOT NULL,
  20. submitteddate TEXT NOT NULL,
  21. resultdate TEXT DEFAULT '')")
  22. (disconnect conn)
  23. (write-string (string-append "Database created at " dbloc "\n")))
  24. ; load configuration file
  25. (require (file "config.rkt"))
  26. ; make sure we can use the sqlite3 connection
  27. (cond (not (sqlite3-available?))
  28. (error "Sqlite3 library not available."))
  29. ; create the database and add the `proposals` table if it doesn't exist
  30. (if (not (file-exists? dbloc))
  31. (createdb dbloc)
  32. (write-string "Database exists. Exiting."))