commit 954028c0a7e74d2e4987b112f9c4ae92e62baff5
parent 3f40686cfffb9c06764b688f00b53997c3a1a24c
Author: Nikolas Mazur <nikolas@pop-os.localdomain>
Date: Wed, 8 Feb 2023 13:54:09 -0700
Add other collections and seeding for said collections
Diffstat:
M | seeds.py | | | 126 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- |
1 file changed, 122 insertions(+), 4 deletions(-)
diff --git a/seeds.py b/seeds.py
@@ -1,10 +1,22 @@
import pymongo
+import datetime
client = pymongo.MongoClient('mongodb://localhost:27017/simple_resource_management_software')
db = client.get_database('simple_resource_management_software')
-collection = db.get_collection('user_collection')
-x = collection.delete_many({})
+# Create collections
+user_collection = db.get_collection('user_collection')
+time_collection = db.get_collection('time_collection')
+fleet_collection = db.get_collection('fleet_collection')
+agreement_collection = db.get_collection('agreement_collection')
+projects_collection = db.get_collection('projects_collection')
+
+# Clean previous seeding
+x = user_collection.delete_many({})
+x = time_collection.delete_many({})
+x = fleet_collection.delete_many({})
+x = agreement_collection.delete_many({})
+x = projects_collection.delete_many({})
# Database collections/documents
# Example create user via User constructor(all fields required)
@@ -12,6 +24,7 @@ x = collection.delete_many({})
# create password
#u2.set_password('hiccupmonster')
+# User Documents
#document/json user_data, will have User.__init__() create userobj (routes.py)
#pw is 'password'
user1 = {
@@ -49,7 +62,111 @@ user2 = {
'is_active':True
}
-collection.insert_many([user1, user2])
+# Time documents
+time1 = {
+ 'clock_in': datetime.datetime.utcnow(), #System time Clock_out should be optional, but can clock_in?
+ 'modified_by': 'Nikolas', #link to _id of user
+ 'date': datetime.date.today(), # Date at document submit
+ 'project': 'Project 2', #Probably link with projects foreign key
+ 'clock_out': datetime.datetime.utcnow(), #System time
+ 'note': 'Changed due to clocking out early',
+ 'perdium': False,
+# 'total_time':
+}
+
+time2 = {
+ 'clock_in': datetime.datetime.utcnow(), #System time Clock_out should be optional, but can clock_in?
+ 'modified_by': 'Nikolas', #link to _id of user
+ 'date': datetime.date.today(), # Date at document submit
+ 'project': 'Project 2', #Probably link with projects foreign key
+ 'clock_out': datetime.datetime.utcnow(), #System time
+ 'note': 'Changed due to clocking out early',
+ 'perdium': False,
+# 'total_time':
+}
+
+# Fleet documents
+fleet1 = {
+ 'date': datetime.date.today(),
+ 'operator': 'Brennen', #forign key to userID
+# 'safety_checks': True, #array for different safety checks
+ 'additional_notes': 'Oil needs checked',
+ 'vehicle': 'The Big Truck', #vehicleID
+ 'incident_report': '',
+ 'mileage': 33,
+}
+
+fleet2 = {
+ 'date': datetime.date.today(),
+ 'operator': 'Nikolas', #forign key to userID
+# 'safety_checks': True, #array for different safety checks
+ 'additional_notes': 'Tires need replaced',
+ 'vehicle': 'The Small Truck', #vehicleID
+ 'incident_report': 'I dunno what goes in incident reports.',
+ 'mileage': 90,
+}
+
+# Agreement documents
+agreement1 = {
+ 'start_date': '2023-12-5',
+ 'end_date': '2023-8-12',
+ 'bid_document': '/asset/document/agreements/New-Agreement.pdf', #Filepath to document
+ 'budget': 1259.40,
+ 'cost': 500,
+}
+
+agreement2 = {
+ 'start_date': '2021-2-21',
+ 'end_date': '2022-12-13',
+ 'bid_document': '/asset/document/agreements/Old-Agreement.pdf', #Filepath to document
+ 'budget': 1259.40,
+ 'cost': 500,
+}
+
+# Projects documents
+projects1 = {
+ 'project_name': 'New Agreement',
+ 'project_budget': [13.20, 0, 20, 300, 50, 0
+ # labor_budget: float | Indexed 0
+ # travel_budget: float | Indexed 1
+ # supplies_budget: float | Indexed 2
+ # contact_budget: float | Indexed 3
+ # equipment_budget: float | Indexed 4
+ # other: float | Indexed 5
+ ],
+}
+
+projects2 = {
+ 'project_name': 'Old Agreement',
+ 'project_budget': [13.20, 0, 20, 300, 50, 0
+ # labor_budget: float | Indexed 0
+ # travel_budget: float | Indexed 1
+ # supplies_budget: float | Indexed 2
+ # contact_budget: float | Indexed 3
+ # equipment_budget: float | Indexed 4
+ # other: float | Indexed 5
+ ],
+}
-for x in collection.find():
+# Insert documents
+user_collection.insert_many([user1, user2])
+# time_collection.insert_many([time1, time2])
+# fleet_collection.insert_many([fleet1, fleet2])
+agreement_collection.insert_many([agreement1, agreement2])
+projects_collection.insert_many([projects1, projects2])
+
+# Print seeded data
+for x in user_collection.find():
+ print(x)
+
+for x in time_collection.find():
+ print(x)
+
+for x in fleet_collection.find():
+ print(x)
+
+for x in agreement_collection.find():
print(x)
+
+for x in projects_collection.find():
+ print(x)
+\ No newline at end of file