Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Database Design Practice
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SOFT Core
SOFT 161 and 162
Database Design Practice
Commits
80b96fd4
Commit
80b96fd4
authored
Mar 31, 2022
by
Shruti Bolman
Browse files
Options
Downloads
Patches
Plain Diff
Diet installer file
parents
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
diet_installer.py
+35
-0
35 additions, 0 deletions
diet_installer.py
with
35 additions
and
0 deletions
diet_installer.py
0 → 100644
+
35
−
0
View file @
80b96fd4
from
sys
import
stderr
from
sqlalchemy.exc
import
SQLAlchemyError
from
datetime
import
datetime
from
diet
import
DietDatabase
,
User
,
FoodType
,
Meal
,
MealFoodType
def
add_starter_data
(
session
):
ada
=
User
(
name
=
'
Ada
'
)
pancakes
=
FoodType
(
name
=
'
Pancakes
'
)
meal
=
Meal
(
user
=
ada
,
meal_food_types
=
[
MealFoodType
(
food_type
=
pancakes
,
amount
=
3
)],
timestamp
=
datetime
.
now
())
session
.
add
(
meal
)
def
main
():
try
:
url
=
DietDatabase
.
construct_mysql_url
(
'
localhost
'
,
3306
,
'
diet
'
,
'
root
'
,
'
cse1208
'
)
diner_database
=
DietDatabase
(
url
)
diner_database
.
ensure_tables_exist
()
print
(
'
Tables created.
'
)
session
=
diner_database
.
create_session
()
add_starter_data
(
session
)
session
.
commit
()
print
(
'
Records created.
'
)
except
SQLAlchemyError
as
exception
:
print
(
'
Database setup failed!
'
,
file
=
stderr
)
print
(
f
'
Cause:
{
exception
}
'
,
file
=
stderr
)
exit
(
1
)
if
__name__
==
'
__main__
'
:
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment