Skip to content
Snippets Groups Projects
Commit 01ae9124 authored by Shrey Patel's avatar Shrey Patel
Browse files

added phase one files

parent 2f34e8f3
No related branches found
No related tags found
No related merge requests found
main.py 0 → 100644
import mysql.connector
from mysql.connector import Error
try:
connection = mysql.connector.connect(host='localhost',
database='inventory',
user='root',
password='ENTER PASSWORD')
if connection.is_connected():
db_Info = connection.get_server_info()
print("Connected to MySQL Server version ", db_Info)
cursor = connection.cursor()
cursor.execute("select database();")
record = cursor.fetchone()
print("You're connected to database: ", record)
cursor.execute('show tables;')
tables = cursor.fetchall()
print(tables)
for i in tables:
print(i)
except Error as e:
print("Error while connecting to MySQL", e)
finally:
if connection.is_connected():
cursor.close()
connection.close()
print("MySQL connection is closed")
\ No newline at end of file
DROP DATABASE IF EXISTS inventory;
CREATE DATABASE IF NOT EXISTS inventory;
CREATE TABLE IF NOT EXISTS USER (
pid INT AUTO_INCREMENT,
lname VARCHAR(64) NOT NULL,
fname VARCHAR(64) NOT NULL,
password VARCHAR(32) NOT NULL,
phoneNumber INT,
email VARCHAR(128) NOT NULL,
PRIMARY KEY (pid)
);
CREATE TABLE IF NOT EXISTS ORGANIZATION (
organizationId INT AUTO_INCREMENT,
name VARCHAR(256) NOT NULL,
email VARCHAR(128) NOT NULL,
description VARCHAR(1024),
ownerPid INT NOT NULL,
PRIMARY KEY (organizationId),
CONSTRAINT fk_user_organization FOREIGN KEY (ownerPid) REFERENCES USER (pid)
);
CREATE TABLE IF NOT EXISTS MANAGER (
userPid INT NOT NULL,
organizationId INT NOT NULL,
PRIMARY KEY (userPid, organizationId),
CONSTRAINT fk_user_manager FOREIGN KEY (userPid) REFERENCES USER (pid),
CONSTRAINT fk_organization_manager FOREIGN KEY (organizationId) REFERENCES ORGANIZATION (organizationId)
);
CREATE TABLE IF NOT EXISTS REQUEST (
requestId INT NOT NULL,
userPid INT NOT NULL,
organizationId INT NOT NULL,
status ENUM('PENDING', 'ACCEPTED', 'DECLINED') NOT NULL,
description VARCHAR(256),
type ENUM('JOIN', 'ITEM') NOT NULL,
PRIMARY KEY (requestId),
CONSTRAINT fk_user_request FOREIGN KEY (userPid) REFERENCES USER (pid),
CONSTRAINT fk_organization_request FOREIGN KEY (organizationId) REFERENCES ORGANIZATION (organizationId)
);
CREATE TABLE IF NOT EXISTS LOCATION (
locationId INT AUTO_INCREMENT,
location VARCHAR(256),
organizationId INT NOT NULL,
PRIMARY KEY (locationId),
CONSTRAINT fk_organization_location FOREIGN KEY (organizationId) REFERENCES ORGANIZATION (organizationId)
);
CREATE TABLE IF NOT EXISTS ITEM (
itemId INT AUTO_INCREMENT,
name VARCHAR(128) NOT NULL,
description VARCHAR(256),
ownerPid INT,
quantity INT NOT NULL,
category VARCHAR(128),
status ENUM('AVAILABLE', 'BORROWED', 'LISTED', 'SOLD') NOT NULL,
locationId INT NOT NULL,
organizationId INT NOT NULL,
PRIMARY KEY (itemId),
CONSTRAINT fk_location_item FOREIGN KEY (locationId) REFERENCES LOCATION (locationId),
CONSTRAINT fk_organiztion_item FOREIGN KEY (organizationId) REFERENCES ORGANIZATION (organizationId)
);
CREATE TABLE IF NOT EXISTS LISTING (
listingId INT AUTO_INCREMENT,
itemId INT NOT NULL,
price DECIMAL(6,2) NOT NULL,
status ENUM('AVAILABLE', 'SOLD') NOT NULL,
dateListed TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (listingId),
CONSTRAINT fk_item_listing FOREIGN KEY (itemId) REFERENCES ITEM (itemId)
);
CREATE TABLE IF NOT EXISTS FAVORITE (
userPid INT NOT NULL,
listingId INT NOT NULL,
PRIMARY KEY (userPid, listingId),
CONSTRAINT fk_user_favorite FOREIGN KEY (userPid) REFERENCES USER (pid),
CONSTRAINT fk_listing_favorite FOREIGN KEY (listingId) REFERENCES LISTING (listingId)
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment