Skip to content

Commit bd55d28

Browse files
add migrations folder to .gitignore / add shortcut command to downgrade migrations / add new CLI to flask to help students persisting example data in their database / update documentation with information for new functionalities
1 parent 63ea242 commit bd55d28

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ dist/*
7575
.now
7676

7777
# backend stuff
78+
migrations/
7879
.venv
7980
database.database
8081
database.db

Pipfile

+2
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ init="flask db init"
2828
migrate="flask db migrate"
2929
local="heroku local"
3030
upgrade="flask db upgrade"
31+
downgrade="flask db downgrade"
32+
insert-test-data="flask insert-test-data"
3133
reset_db="bash ./docs/assets/reset_migrations.bash"
3234
deploy="echo 'Please follow this 3 steps to deploy: https://github.com/4GeeksAcademy/flask-rest-hello/blob/master/README.md#deploy-your-website-to-heroku' "

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ It is recomended to install the backend first, make sure you have Python 3.8, Pi
3131

3232
> Note: Codespaces users can connect to psql by typing: `psql -h localhost -U gitpod example`
3333
34+
### Undo a migration
35+
36+
You are also able to undo a migration by running
37+
38+
```sh
39+
$ pipenv run downgrade
40+
```
41+
3442
### Backend Populate Table Users
3543

3644
To insert test users in the database execute the following command:
@@ -51,7 +59,9 @@ And you will see the following message:
5159
Users created successfully!
5260
```
5361

54-
To update with all yours tables you can edit the file app.py and go to the line 80 to insert the code to populate others tables
62+
### **Important note for the database and the data inside it**
63+
64+
Every Github codespace environment will have **its own database**, so if you're working with more people eveyone will have a different database and different records inside it. This data **will be lost**, so don't spend too much time manually creating records for testing, instead, you can automate adding records to your database by editing ```commands.py``` file inside ```/src/api``` folder. Edit line 32 function ```insert_test_data``` to insert the data according to your model (use the function ```insert_test_users``` above as an example). Then, all you need to do is run ```pipenv run insert-test-data```.
5565

5666
### Front-End Manual Installation:
5767

src/api/commands.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def setup_commands(app):
1616
"""
1717
@app.cli.command("insert-test-users") # name of our command
1818
@click.argument("count") # argument of out command
19-
def insert_test_data(count):
19+
def insert_test_users(count):
2020
print("Creating test users")
2121
for x in range(1, int(count) + 1):
2222
user = User()
@@ -29,4 +29,6 @@ def insert_test_data(count):
2929

3030
print("All test users created")
3131

32-
### Insert the code to populate others tables if needed
32+
@app.cli.command("insert-test-data")
33+
def insert_test_data():
34+
pass

0 commit comments

Comments
 (0)