Commits

Fran Peruzzi committed dfb7087 Draft

initialization of basic database

Comments (0)

Files changed (3)

 syntax: glob
 _env
+.env
 *.swp
 *.pyc
+*.db
+
 import sqlite3
 from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash
+from contextlib import closing
 
 # configuration
 DATABASE = './nicelist.db'
 DROP TABLE IF EXISTS Person;
 CREATE TABLE Person (
-    id INT PRIMARY KEY AUTOINCREMENT,
+    id INTEGER PRIMARY KEY AUTOINCREMENT,
     name TEXT NOT NULL,
     email TEXT 
 );
 
 DROP TABLE IF EXISTS Friend;
 CREATE TABLE Friend (
-    person_id INT REFERENCES Person (id),
-    friend_id INT REFERENCES Person (id),
+    person_id INTEGER REFERENCES Person (id),
+    friend_id INTEGER REFERENCES Person (id),
     CONSTRAINT friend_pk PRIMARY KEY (person_id, friend_id) ON CONFLICT FAIL
 );
 
 DROP TABLE IF EXISTS Setting;
 CREATE TABLE Setting (
-    id INT PRIMARY KEY AUTOINCREMENT,
+    id INTEGER PRIMARY KEY AUTOINCREMENT,
     name TEXT NOT NULL,
-    default_value NOT NULL
+    default_value TEXT NOT NULL
 );
 
 DROP TABLE IF EXISTS PersonSettings;
 CREATE TABLE PersonSettings (
-    person_id INT REFERENCES Person (id),
-    setting_id INT REFERENCES Setting (id),
+    person_id INTEGER REFERENCES Person (id),
+    setting_id INTEGER REFERENCES Setting (id),
     value NOT NULL,
     CONSTRAINT personsettings_pk PRIMARY KEY (person_id, setting_id) ON CONFLICT FAIL
 );
 
 DROP TABLE IF EXISTS WishItem;
 CREATE TABLE WishItem (
-    id INT PRIMARY KEY AUTOINCREMENT,
-    person_id INT REFERENCES Person (id),
+    id INTEGER PRIMARY KEY AUTOINCREMENT,
+    person_id INTEGER REFERENCES Person (id),
     item_name TEXT NOT NULL,
     quantity NUM, 
     notes TEXT
 
 DROP TABLE IF EXISTS GiftItem;
 CREATE TABLE GiftItem (
-    wisher_id INT REFERENCES Person (id),
-    giver_id INT REFERENCES Person (id),
-    wish_item INT REFERENCES WishItem (id),
-    quantity INT,
+    wisher_id INTEGER REFERENCES Person (id),
+    giver_id INTEGER REFERENCES Person (id),
+    wish_item INTEGER REFERENCES WishItem (id),
+    quantity INTEGER,
     CONSTRAINT giftitem_pk PRIMARY KEY (wisher_id, giver_id, wish_item) ON CONFLICT FAIL
 );