Advertisement
bocajbee

createdb.py

Aug 4th, 2020 (edited)
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.16 KB | None | 0 0
  1. from cs50 import SQL
  2.  
  3. # Configure CS50 Library to use SQLite database
  4. db = SQL("sqlite:///parks.db")
  5.  
  6. def main():
  7.  
  8.     # create the users table
  9.     db.execute('CREATE TABLE "users" ("id" INTEGER NOT NULL, "username" TEXT NOT NULL, "hash" TEXT NOT NULL, PRIMARY KEY("id"));')
  10.  
  11.     # create the all_skateparks table
  12.     db.execute('CREATE TABLE "all_skateparks" ("place_id" VARCHAR(255) NOT NULL, "name" VARCHAR(255),"formatted_address" VARCHAR(512), "phone" VARCHAR(255), "website" VARCHAR(255), PRIMARY KEY("place_id"));')
  13.  
  14.     # create the user_saved_parks table
  15.     db.execute('CREATE TABLE "user_saved_parks" ("id" int NOT NULL, "place_id" VARCHAR(255) NOT NULL, FOREIGN KEY("place_id") REFERENCES "all_skateparks"("place_id"), FOREIGN KEY("id") REFERENCES "users"("id"));')
  16.  
  17.     # create the opening_hours table
  18.     db.execute('CREATE TABLE "opening_hours" ("place_id" VARCHAR(255) NOT NULL, "day_entry" VARCHAR(255), FOREIGN KEY("place_id") REFERENCES "all_skateparks"("place_id"));')
  19.  
  20.     # create the photos table
  21.     db.execute('CREATE TABLE "photos" ("place_id" VARCHAR(255) NOT NULL, "height" int NOT NULL,"width" int NOT NULL,"html_attribute" VARCAHAR(512),"photoref" VARCHAR(512), FOREIGN KEY("place_id") REFERENCES "all_skateparks"("place_id"));')
  22.  
  23.     # create the types table
  24.     db.execute('CREATE TABLE "types" ("place_id" VARCHAR(255) NOT NULL, "types" VARCHAR(255),FOREIGN KEY("place_id") REFERENCES "all_skateparks"("place_id"));')
  25.  
  26.     # create the skateparks_reviews table
  27.     db.execute('CREATE TABLE "skatepark_reviews" ("place_id" VARCHAR(255) NOT NULL, "review_author" VARCHAR(255),"review_author_url" VARCHAR(8192),"review_lang" VARCHAR(255),"review_profile_url" VARCHAR(8192), "review_rating" int NOT NULL, "relative_time_desc" VARCHAR(255), "review_text" BLOB, "review_time" VARCHAR(255),FOREIGN KEY("place_id") REFERENCES "all_skateparks"("place_id"));')
  28.  
  29.     # create the skatepark_location table
  30.     db.execute('CREATE TABLE "skatepark_location" ("place_id" VARCHAR(255) NOT NULL, "location_lat" VARCHAR(255),"location_long" VARCHAR(255), FOREIGN KEY("place_id") REFERENCES "all_skateparks"("place_id"));')
  31.  
  32. if __name__ == "__main__":
  33.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement