Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadMe and Database Setup #70

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 39 additions & 103 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,110 +5,47 @@
* [Peewee](http://docs.peewee-orm.com/en/latest/index.html) - A small, expressive ORM used for database communications
* [SQLite](https://sqlite.org/) - SQL database engine

# Setting Up a Development Environment
### Getting Started On Cloud9 ###
[Cloud9](https://c9.io/?redirect=0) is the preferred tool for our software team while developing and debugging code. However, if you are new to cloud9, they did just recent start requiring a credit card to create an account. Therefore you may not want to use cloud9 as your development environment.

### Create a Workspace with Bitbucket using SSH Protocol

When you first log into your cloud9 account, select the tab that says **workspaces**. After you open this tab you should see an option to create a new workspace, it should look like the image below.

![creatework.PNG](https://bitbucket.org/repo/bEXb4L/images/4213557604-creatework.PNG)

After you click the button go ahead and input a name and description for this workspace.

![description.PNG](https://bitbucket.org/repo/bEXb4L/images/2446581179-description.PNG)
![public.PNG](https://bitbucket.org/repo/bEXb4L/images/69137571-public.PNG)

>***Note:***
The default for the workspace is to be public, it's important to **NOT** change this default option. The way that our system works is that it creates a virtual environment for the application to run on. The virtual environment requires the use of ports in order to access the application. If you may the workspace private, it can block these ports so that they can not be accessed. There may be a way around this; however, we just find it easier if you let the workspace be public.

Next, you will want to make sure you choose to clone your repo from bitbucket. You do this by adding your git URL using the SSH.

For Example:
```[email protected]:<username>/<name_of_Repo>.git```

If you are uncertain what your git ssh URL is you can find it at the top of the bitbucket page if you click the clone option.

![git clone.PNG](https://bitbucket.org/repo/bEXb4L/images/340042303-git%20clone.PNG)

>***Note***: If you copy and paste this line make sure to remove the ```git clone``` at the front in order to ensure you only get the URL.

After you have entered in the URL, the last portion of the page asked you to choose a template. Please select the python option in order to have the workspace to run correctly.

![PYTHON.PNG](https://bitbucket.org/repo/bEXb4L/images/3923875225-PYTHON.PNG)

All that is left is to hit the create workspace button and your workspace will be configured correctly.

### Getting Your Development Environment Running

After you have created your workspace, there are three additional steps that you will have to complete before your virtual environment will be completely operational.

**Step One: Activate Your Virtual Environment**

In order to do this, all you have to do is type: ```source setup.sh``` into the Linux terminal. You might have to wait a minute or two as the tools you need for our application are downloaded into your virtual environment. However, after the setup is completed you should see the words ```(venv)``` at the front of your terminal.

![venv.PNG](https://bitbucket.org/repo/bEXb4L/images/2846617267-venv.PNG)

>***Note:***
In order for the application to work, you must activate the virtual environment. If you are not inside of the virtual environment you will see this error:
![venvError.PNG](https://bitbucket.org/repo/bEXb4L/images/1415469357-venvError.PNG)Whenever you get this error just activate the virtual environment again by entering the command ```source setup.sh```

>Also, If you ever want to deactivate the virtual environment for any reason just type ```deactivate``` into the terminal.
![deactivate.PNG](https://bitbucket.org/repo/bEXb4L/images/2248015321-deactivate.PNG)

**Step Two: Setup Your Database**

A couple of elements are necessary in order to get your database established. The first step is creating the SQLite file, we can create the file in the desired location through the use of one of our scripts.

**Create Database**

By typing the command ```python reset-db.py``` a database file containing the correct schemas will be created in the data directory with the name ```advancement.sqlite```.

**Populate Database**

The ```reset-db.py``` will only create empty tables for you, in order to populate the database you will need to execute the command: ```python add_dummy.py```. This file will add dummy data to the system so that you can gauge how the system is supposed to run.

**How to View the Database**

Now that you have the database created and populated with data, you are probably asking yourself how do I see that? Our system development team likes to use a tool called [DB Browser](http://sqlitebrowser.org/). This tool is a visual way of viewing and editing SQLite database files.

![dbBrowser.PNG](https://bitbucket.org/repo/bEXb4L/images/3023751797-dbBrowser.PNG)

**Step Three: Running the Application**

The only remaining step to getting your development environment deployed is running the actual application. This can be achieved through the command ```python run.py```, when you run this command you should see a URL created for you.

![run.PNG](https://bitbucket.org/repo/bEXb4L/images/1543001500-run.PNG)

The URL will take you to the application and allow you to see any changes you make to the system. That's all that has to be done in order to get the development environment created and ready for editing.

[TOC]
#Installation#
# BCSR Application Installation

##Requirements##
* python 2.7
* linux, unix, mac, windows(with attachments)
* git

## Creating Development Environment

1. ** Fork ** the repository from BitBucket and rename the project

2. If working on a **local machine**, then clone the repo from your terminal.

3. If you are working from cloud 9 follow [these steps](https://codymyers93.wordpress.com/2016/03/07/octoprint-working-in-cloud-9/) for directions on how to setup cloud 9 with git.

4. After you have successfully clone the repo. Run:
``` bash
source setup.sh
python app.py
```

If you are successful you will see something like:
``` bash
* linux, unix, mac, windows(with attachments), Ubuntu

## Creating Development Environment
1. Clone the BCSR repository (from Github) in your home directory: ```git clone <URL>```
2. If working on a **local machine**, then clone the repo from your terminal.
3. Edit your ```secret_config.yaml``` file by referencing the example_secret_config.yaml file.
4. Run ```source setup.sh```

## Creating the database
### PHPMYADMIN
1. Go to http://0.0.0.0/phpmyadmin/ replacing the 0.0.0.0 with your server
2. Log in with the credentials used in secret_config.yaml
3. Click on "New" on top of the sidebar at the left of the screen
4. If there is already a database named "bcsr", drop it
5. Create a new database with the name "bcsr"
6. Run ```python create_db.py```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get this error when trying to create databases

(venv) ramsayb2@Berea-C02ZC049LVDN:~/dev/bcsr %>python create_db.py                                 0 - ttys004
Traceback (most recent call last):
  File "/Users/ramsayb2/dev/bcsr/create_db.py", line 14, in <module>
    sqlite_dbs  = [ conf['databases']['dev']
KeyError: 'databases'

Copy link
Author

@sreynit02 sreynit02 Feb 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are codes that we edited that we would like to merge into development and this line was changed to sqlite_dbs = [ conf['databases'][0] . Is it maybe you haven't merged those codes in ur branch yet?


### MYSQL WORKBENCH
1. Log into mysql from the command line using: ```mysql -u root -p```. It will prompt you to enter password
2. Create the database using the command: ```create database bcsr```
3. Run ```python create_db.py```
4. If you are successful you will see something like this:
Creating empty SQLite file: data/bcsr.sql.
Creating model for 'Semesters'
Creating model for 'Divisions'
Creating model for 'Programs'
Creating model for 'Users'
Creating model for 'Courses'
Creating model for 'UsersCourses'
Creating model for 'Deadline'

## Run the Application
1. Run ```python app.py```
If successful you will see something like this:
Starting application
Running server at http://0.0.0.0:8080/
Running server at http://0.0.0.0:8080/

```
Click the link in your terminal to check if it deployed correctly.

Expand All @@ -120,12 +57,11 @@ Click the link in your terminal to check if it deployed correctly.
- css
- img
-templates
- snips # A directory for partial html files
- snips # A directory for partial html files
- start.html #This is an example of where your html files will go
-logic
-logic
- files that manipulate the database
- __init__.py
- allImports.py
- config.yaml
- models.py
- starty.py #This an example of where your controllers will go
2 changes: 2 additions & 0 deletions app/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ log:
filename: "bcsr.log"

# All the databases used by the system
databases:
- data/bcsr.sql

databaseAdmin:
user: 'heggens'
Expand Down
8 changes: 7 additions & 1 deletion app/secret_config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
DEBUG: True
secret_key: "I accidentally put our last key in public"
secret_key: key # FIXME: Add the secret key

db:
db_name: bcsr
host: localhost
password: password # FIXME: add your password
username: username # FIXME: add your username
37 changes: 19 additions & 18 deletions create_db.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# WARNING: NOT FOR USE IN PRODUCTION AFTER REAL DATA EXISTS!!!!!!!!!!!!!!!!!!!!!!
'''
This script creates the database tables in the SQLite file.
This script creates the database tables in the SQLite file.
Update this file as you update your database.
'''
import os, sys
import importlib
here = os.path.dirname(__file__)

# Don't forget to import your own models!
from app.models import *

conf = load_config('app/config.yaml')
conf = load_config(os.path.join(here,'app/config.yaml'))

sqlite_dbs = [ conf['databases']['dev']
sqlite_dbs = [ conf['databases'][0]
# add more here if multiple DBs
]

Expand All @@ -29,15 +30,15 @@
print ("Database {0} should not exist at this point!".format(fname))
print ("Creating empty SQLite file: {0}.".format(fname))
open(fname, 'a').close()


def class_from_name (module_name, class_name):
# load the module, will raise ImportError if module cannot be loaded
# m = __import__(module_name, globals(), locals(), class_name)
# get the class, will raise AttributeError if class cannot be found
c = getattr(module_name, class_name)
return c

"""This file creates the database and fills it with some dummy run it after you have made changes to the models pages."""
def get_classes (db):
classes = []
Expand All @@ -47,7 +48,7 @@ def get_classes (db):
classes.append(c)
return classes


mainDB.create_tables(get_classes('mainDB'))

# When adding dummy data the varialbes should be in Mixed case and should be the name of the class
Expand All @@ -60,7 +61,7 @@ def get_classes (db):
).save(force_insert = True)
###########
#DIVISIONS#
###########
###########
divisions = Divisions( name = "Division 1"
).save()

Expand All @@ -72,7 +73,7 @@ def get_classes (db):
programs = Programs( name = "Computer Science",
DID = 2
).save()

programs = Programs( name = "Biology",
DID = 1
).save()
Expand All @@ -85,36 +86,36 @@ def get_classes (db):
email = "[email protected]",
isAdmin = True
).save(force_insert=True)

users = Users( firstName = "Jan",
lastName = "Pearce",
username = "pearcej",
email = "[email protected]",
DID = 2
).save(force_insert=True)

users = Users( firstName = "Mario",
lastName = "Nakazawa",
username = "nakazawam",
PID = 1,
email = "[email protected]"
).save(force_insert=True)

users = Users( firstName = "Matt",
lastName = "Jadud",
username = "jadudm",
email = "[email protected]",
).save(force_insert=True)
#########
#COURSES#
#########
).save(force_insert=True)
#########
#COURSES#
#########
courses = Courses( prefix = "BIO",
number = "101",
section = "A1",
PID = 2,
SEID = 201612
).save()

courses = Courses( prefix = "CSC",
number = "415",
section = "SH",
Expand All @@ -127,7 +128,7 @@ def get_classes (db):
userscourses = UsersCourses ( username = 'heggens',
CID = 1
).save()

userscourses = UsersCourses ( username = 'heggens',
CID = 2
).save()
).save()