From 0b4c9ba9b3e5eefe49b5c17d3c43ac5ab704f2ef Mon Sep 17 00:00:00 2001 From: Jason Ng <116290832+jason490@users.noreply.github.com> Date: Mon, 8 Jul 2024 11:57:00 -0400 Subject: [PATCH 1/3] fixed-database --- api/.env | 2 +- api/init.sql | 22 ++++++++++++++++++++ api/pollination/models.py | 39 +++++++++++++++++++++++++++++------ api/setup.py | 10 +++++++++ client/app/css/colors.css | 0 client/app/templates/base.jsx | 0 6 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 api/init.sql create mode 100644 api/setup.py create mode 100644 client/app/css/colors.css create mode 100644 client/app/templates/base.jsx diff --git a/api/.env b/api/.env index cc9b202..9575c5c 100644 --- a/api/.env +++ b/api/.env @@ -1,3 +1,3 @@ SECRET_KEY='DEVElOPMENTONLY' -SQLALCHEMY_DATABASE_URI='postgresql://usr:pwd@postgres:5433/master' +SQLALCHEMY_DATABASE_URI='postgresql://usr:pwd@postgres:5432/master' diff --git a/api/init.sql b/api/init.sql new file mode 100644 index 0000000..572f3b0 --- /dev/null +++ b/api/init.sql @@ -0,0 +1,22 @@ +CREATE TABLE "User" ( + "id" SERIAL UNIQUE PRIMARY KEY, + "session_id" uuid UNIQUE, + "email" TEXT UNIQUE, + "password" uuid +); + +CREATE TABLE "Files" ( + "id" SERIAL UNIQUE PRIMARY KEY, + "user_id" INTEGER UNIQUE, + "location" TEXT, + "bug_name" TEXT, + "file_name" TEXT, + FOREIGN KEY ("user_id") REFERENCES "User"("id")a +); + +CREATE TABLE "Species" ( + "id" SERIAL UNIQUE PRIMARY KEY, + "name" TEXT, + "description" TEXT, + "remove" BOOLEAN +); diff --git a/api/pollination/models.py b/api/pollination/models.py index 5ae1faa..091463f 100644 --- a/api/pollination/models.py +++ b/api/pollination/models.py @@ -1,7 +1,6 @@ ''' Contains the table representations of the database ''' - import string import random from uuid import uuid4 @@ -29,12 +28,40 @@ class User(db.Model): id = db.Column(db.String(32), primary_key=True, unique=True, default=get_uuid) alt_id = db.Column(db.String(6), unique=True, default=get_basic_id) + username = db.Column(db.Text, unique=True) - team_name = db.Column(db.String(20), unique=True) - track_value = db.relationship('Track_value', back_populates='team') - - user = db.relationship('User', back_populates='team') + file = db.Relationship('File', back_populates='user', + cascade='all, delete', passive_deletes=True) # Determine what access level the function is at def __repr__(self): - return f"Team('{self.team_name}','{ self.alt_id }')" + return f"Team('{self.name}','{ self.alt_id }')" + + +class File(db.Model): + ''' + Correlates the file location with the User + ''' + __tablename__ = "File" + id = db.Column(db.Integer, primary_key=True, unique=True) + user_id = db.Column(db.String(32), db.ForeignKey('User.id', + ondelete="CASCADE"), nullable=False) + location = db.Column(db.Text) + bug_name = db.Column(db.Text) + file_name = db.Column(db.Text) + user = db.Relationship('User', back_populates='file') + + def __repr__(self): + return f"File('{self.location}', '{self.bug_name}', \ + '{self.file_name}')" + + +class Species(db.Model): + __tablename__ = "Species" + id = db.Column(db.Integer, primary_key=True, unique=True) + plant = db.Column(db.Boolean) + name = db.Column(db.Text) + description = db.Column(db.Text) + native = db.Column(db.Boolean) + location = db.Column(db.Text) + image_location = db.Column(db.Text) diff --git a/api/setup.py b/api/setup.py new file mode 100644 index 0000000..e5e58f1 --- /dev/null +++ b/api/setup.py @@ -0,0 +1,10 @@ +from pollination import db +from pollination.models import User + +if __name__ == "__main__": + db.drop_all() + db.create_all() + + user = User(name="moo", email="testing@gmail.com") + db.session.add(user) + db.session.commit() diff --git a/client/app/css/colors.css b/client/app/css/colors.css new file mode 100644 index 0000000..e69de29 diff --git a/client/app/templates/base.jsx b/client/app/templates/base.jsx new file mode 100644 index 0000000..e69de29 From f6c42c1a7e5a125e554010ea4f1588f61a2a903e Mon Sep 17 00:00:00 2001 From: Jason Ng <116290832+jason490@users.noreply.github.com> Date: Mon, 8 Jul 2024 12:08:35 -0400 Subject: [PATCH 2/3] linted --- api/pollination/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/pollination/models.py b/api/pollination/models.py index 091463f..68395bb 100644 --- a/api/pollination/models.py +++ b/api/pollination/models.py @@ -57,6 +57,9 @@ def __repr__(self): class Species(db.Model): + ''' + Contains a database of species to search for + ''' __tablename__ = "Species" id = db.Column(db.Integer, primary_key=True, unique=True) plant = db.Column(db.Boolean) From f3b75029a8bb4cdf65684549606c7156cf3f77c3 Mon Sep 17 00:00:00 2001 From: Jason Ng <116290832+jason490@users.noreply.github.com> Date: Mon, 8 Jul 2024 12:13:14 -0400 Subject: [PATCH 3/3] linted --- api/setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/api/setup.py b/api/setup.py index e5e58f1..24055bc 100644 --- a/api/setup.py +++ b/api/setup.py @@ -1,3 +1,4 @@ +# pylint: skip-file from pollination import db from pollination.models import User